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 (2025). ftlLabel (https://www.mathworks.com/matlabcentral/fileexchange/70323-ftllabel), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Image Processing and Computer Vision > Image Processing Toolbox > Image Segmentation and Analysis > Region and Image Properties >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.