IAM

OPENSOURCEFAN STUDYING
STUDYINGCOMPUTERSCIENCEANDMATH COMPUTERSCIENCE

Check out the latest superpixel benchmark — Superpixel Benchmark (2016) — and let me know your opinion! @david_stutz

ARTICLE

Fast, Multi-Label Connected Components in MatLab

This article presents a MatLab MEX wrapper for a fast, multi-label connected components implementation in C++ originally written by Ali Rahimi.

Connected component algorithms are basic building blocks of many computer vision algorithms. With bwconncomp, MatLab provides a simple connected components algorithm for binary images. Motivated by the need to compute connected components in (semantic) segmentations, where applying bwconncomp is painful, I wrote a MEX wrapper for Ali Rahimi's C++ implementation of a connected component algorithm.

The code is available on GitHub:

GitHub

Building

The MEX wrapper is compiled as follows:

>> mex sp_fast_connected_relabel.cpp
Building with 'g++'.
Warning: You are using gcc version '4.8.4'. The version of gcc is not supported. The version currently supported with MEX is
'4.7.x'. For a list of currently supported compilers see: http://www.mathworks.com/support/compilers/current_release. 

Warning: You are using gcc version '4.8.4-2ubuntu1~14.04.1)'. The version of gcc is not supported. The version currently
supported with MEX is '4.7.x'. For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release. 

MEX completed successfully.

Usage

The wrapper operates on matrices of type double. A usage example is given below:

>> image = imread('checkerboard.png');
>> labels = sp_fast_connected_relabel(double(image));
>> imshow(uint8(labels)*10)
>> imwrite(uint8(labels)*10, 'checkerboard_components.png');

Given an image checkerboard.png, Figure 1 shows the generated output.

connected_components

Figure 1 (click to enlarge): original checkerboard on the left, connected components on the right. The connected components are shown in different gray tones.

What is your opinion on this article? Did you find it interesting or useful? Let me know your thoughts in the comments below or using the following platforms:

@david_stutz