ftlLabel

Fast, toolbox free connected component labeling

You are now following this Submission

FTLLABEL Fast, toolbox free connected component labeling

I = FTLLABEL(I) finds 8-connected components in logical matrix I
I = FTLLABEL(I,CONN) finds components with CONN connectivity
[I,num] = FTLLABEL(I) returns the number of objects [num]

FTLLABEL('compile') - Compile the mex file for faster labeling

[Example 1 - General Usage]
I = imread('text.png') % load a demo image
L = ftlLabel(I); % label the connected components
figure, imagesc(L); % visualize the output

[Example 2 - Use the Mex Version]
% Compile the mex file, then use it
ftlLabel('compile'); % compile mex, must be in ftlLabel.m directory
I = imread('text.png') % load a demo image
L = ftlLabel(I); % label the connected components
figure, imagesc(L); % visualize the output

[Inputs]
I - A 2-dimensional matrix, must be logical type
CONN - Connectivity, must be 1 (4-connected) or 2 (8-connected)

[Outputs]
I - A matrix of labeled objects
num - Number of objects

[Toolbox Requirements]
None

[Additional Information]
This function was developed to replace bwlabel for big images. It
maintains a small memory footprint, and the labeled image it returns uses
the smallest integer type required to store all object labels. In
comparison to bwlabel, the m-file function performs slightly worse on
small images (<1 megapixel), but performs significantly better on large
images.

The mex version runs 4-20x faster than bwlabel for any image.
NOTE: The mex file should be compiled using mingw64. This file uses the
interleaved complex API, meaning it will not compile in Matlab versions
prior to 2018a.

Parts of this algorithm mirror the "Light Speed Labeling" algorithm:
http://www-soc.lip6.fr/~lacas/Publications/ICIP09_LSL.pdf

[TODO]
1. Expand support for n-dimensional images
2. Additional mex optimization using different AVX instructions

See also BWLABEL

Author: nicholas.j.schaub@gmail.com
Created: 2-17-2018
Updated: 3-1-2019 - Added first mex version, added num as an output

Cite As

Nick Schaub (2026). ftlLabel (https://www.mathworks.com/matlabcentral/fileexchange/70323-ftllabel), MATLAB Central File Exchange. Retrieved .

General Information

MATLAB Release Compatibility

  • Compatible with any release

Platform Compatibility

  • Windows
  • macOS
  • Linux
Version Published Release Notes Action
0.9.1

Minor bug fixes. Made code more modular.

0.9

Added mex, added number of objects as an output

0.8.1

Minor bug fixes.

0.8.0