Skip to content

Instantly share code, notes, and snippets.

@Saafke
Last active March 29, 2020 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Saafke/c88852cc9bbb8efb8f77ae89ce457a30 to your computer and use it in GitHub Desktop.
Save Saafke/c88852cc9bbb8efb8f77ae89ce457a30 to your computer and use it in GitHub Desktop.
Matlab script for the Connected Component Labelling blog.
% Code created by Xavier Weber
% Create an image -- like the one in the GIF.
im = zeros(5,5);
im(1:1,5:5) = 255;
im(2:2,2:2) = 255;
im(3:3,1:1) = 255;
im(3:3,4:5) = 255;
im(4:4,4:4) = 255;
im(5:5,4:4) = 255;
im(5:5,2:4) = 255;
% Count the blobs
[nBlobs, im] = countBlobs(im);
% Give each blob a unique color
im = label2rgb(im);
%Show it
imshow(im, 'InitialMagnification', 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment