how to find connected component in an image

i'm doing a project to recognize kannada text,the first step says find connected components from a binarynimage.i tried doing it using bwconncomp but i'm not able to display the image.soo can u please help me with dis.

Respuestas (2)

Walter Roberson
Walter Roberson el 22 de Sept. de 2016

0 votos

bwconncomp should work, or you could use bwlabel, or you could use regionprops
bwconncomp has an example where it reconstructs the binary image with one of the components missing.
For the moment I suggest you use bwlabel() and imshow() the result, as then the different components should come out in different colors.
Image Analyst
Image Analyst el 22 de Sept. de 2016
In short
% Do connected components labeling:
labeledImage = bwlabel(binaryImage);
% Let's assign each blob a different color to visually show the user the distinct blobs.
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
% coloredLabels is an RGB image. We could have applied a colormap instead (but only with R2014b and later)
imshow(coloredLabels);

4 comentarios

deeksha h r
deeksha h r el 23 de Sept. de 2016
Error using bwlabel Expected input number 1, BW, to be two-dimensional.
Error in bwlabel (line 65) validateattributes(BW, {'logical' 'numeric'}, {'real', '2d', 'nonsparse'}, ...
Error in analysterer (line 3) labeledImage = bwlabel(binaryImage); this is the error i'm getting for using the above code,nd this error appears for many of the syntaxes i used.
What does this say
whos binaryImage
It must be logical. How did you generate your binary image?
Walter Roberson
Walter Roberson el 23 de Sept. de 2016
your binaryImage needs to be 2 dimensional. Watch out that your original image might be RGB when you are expecting it to be grayscale . In particular, if it is a JPEG image then even if it looks gray, it is much much more likely that it is RGB in which all of the colors happen to be shades of gray.
try this possible fix
if ndims(binaryImage) > 2
% It's color
binaryImage = binaryImage(:,:,2) > 128;
else
% It's gray scale, but maybe not 0 and 1.
% Make sure it's logical, not 0 and 255 or something.
binaryImage = binaryImage > 0;
end

Iniciar sesión para comentar.

Categorías

Más información sobre Display Image en Centro de ayuda y File Exchange.

Preguntada:

el 22 de Sept. de 2016

Comentada:

el 23 de Sept. de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by