Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Label connected components- using their count as their label

Subject: Label connected components- using their count as their label

From: dave

Date: 10 Feb, 2014 22:40:09

Message: 1 of 2

I am trying to write a routine that will find connected pixels in a binary image.


I have found and used commands to identify the connected components and count the number of components in each of the objects.

Now I would like to label each of the objects based on the number of connected components.


i.e.
my binary image:

a=
1 0 0 0 1 1
1 0 0 0 0 0
0 0 1 1 1 0

i would like my label image to look like
2 0 0 0 2 2
2 0 0 0 0 0
0 0 3 3 3 0


any ideas ???


FYI ...

i use the following to find the connected components -->
ConComps = bwconncomp(a,4);

and this to find the number of pixels in each component-->
s = regionprops(ConComps,'area');


thanks in advance

Subject: Label connected components- using their count as their label

From: Steve Eddins

Date: 11 Feb, 2014 13:31:56

Message: 2 of 2

On 2/10/14 5:40 PM, dave wrote:
> I am trying to write a routine that will find connected pixels in a
> binary image.
>
>
> I have found and used commands to identify the connected components and
> count the number of components in each of the objects.
>
> Now I would like to label each of the objects based on the number of
> connected components.
>
>
> i.e. my binary image:
>
> a= 1 0 0 0 1 1
> 1 0 0 0 0 0
> 0 0 1 1 1 0
>
> i would like my label image to look like
> 2 0 0 0 2 2
> 2 0 0 0 0 0
> 0 0 3 3 3 0
>
>
> any ideas ???
>
>
> FYI ...
>
> i use the following to find the connected components -->
> ConComps = bwconncomp(a,4);
> and this to find the number of pixels in each component-->
> s = regionprops(ConComps,'area');
>
>
> thanks in advance

cc = bwconncomp(a,4);
s = regionprops(cc,'Area','PixelIdxList');
L = zeros(size(a));
for k = 1:length(s)
    L(s(k).PixelIdxList) = s(k).Area;
end

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us