Thread Subject: how can I label segmented images

Subject: how can I label segmented images

From: Vicky

Date: 29 Oct, 2008 15:46:17

Message: 1 of 18

Hi there,

I'll be grateful if someone can help me out.

I have segmented bmp-images. Now I want to label (mark) each pixel of
each image, so that pixel with the same color (rgb) become the same
label. The label have to be an integer value.

Is it possible to label an segmented image?

How can I realize it?

I think the marker-based watershed segmentation is such a thing that I
need. But I have already segmented images.

Best regards
Vicky

Subject: how can I label segmented images

From: ImageAnalyst

Date: 29 Oct, 2008 16:55:51

Message: 2 of 18

On Oct 29, 11:46=A0am, Vicky <bonsa...@gmx.de> wrote:
> Hi there,
>
> I'll be grateful if someone can help me out.
>
> I have segmented bmp-images. Now I want to label (mark) each pixel of
> each image, so that pixel with the same color (rgb) become the same
> label. The label have to be an integer value.
>
> Is it possible to label an segmented image?
>
> How can I realize it?
>
> I think the marker-based watershed segmentation is such a thing that I
> need. But I have already segmented images.
>
> Best regards
> Vicky

----------------------------------------------------------------------
Vicky:
You need the image processing toolkit. In there, there is a function
called bwlabel() that does what you want.
Regards,
ImageAnalyst

Subject: how can I label segmented images

From: Vicky

Date: 31 Oct, 2008 11:18:04

Message: 3 of 18

Hallo ImageAnalyst,

thank you very much for your help.
Now I have still a question.
My segmented images are so created that different colors are directly
next to each other. So for example between two colors is not a black
area. So if I use bwlabel() it makes one object of these two colors. But
this is not what I want. Each color should become a different integer value.

bwlabel()returns a matrix, where each pixel get an integer value. The
pixels labeled 0 are the background, the pixels labeled 1 is an object
and so on.

Is it possible to label the pixels with an integer value that I define?
Or can't I persuade the labels?

Best regards,
Vicky




ImageAnalyst schrieb:
> On Oct 29, 11:46 am, Vicky <bonsa...@gmx.de> wrote:
>> Hi there,
>>
>> I'll be grateful if someone can help me out.
>>
>> I have segmented bmp-images. Now I want to label (mark) each pixel of
>> each image, so that pixel with the same color (rgb) become the same
>> label. The label have to be an integer value.
>>
>> Is it possible to label an segmented image?
>>
>> How can I realize it?
>>
>> I think the marker-based watershed segmentation is such a thing that I
>> need. But I have already segmented images.
>>
>> Best regards
>> Vicky
>
> ----------------------------------------------------------------------
> Vicky:
> You need the image processing toolkit. In there, there is a function
> called bwlabel() that does what you want.
> Regards,
> ImageAnalyst

Subject: how can I label segmented images

From: ImageAnalyst

Date: 31 Oct, 2008 12:35:44

Message: 4 of 18

On Oct 31, 7:18=A0am, Vicky <bonsa...@gmx.de> wrote:
> Hallo ImageAnalyst,
>
> thank you very much for your help.
> Now I have still a question.
> My segmented images are so created that different colors are directly
> next to each other. So for example between two colors is not a black
> area. So if I use bwlabel() it makes one object of these two colors. But
> this is not what I want. Each color should become a different integer val=
ue.
>
> bwlabel()returns a matrix, where each pixel get an integer value. The
> pixels labeled 0 are the background, the pixels labeled 1 is an object
> and so on.
>
> Is it possible to label the pixels with an integer value that I define?
> Or can't I persuade the labels?
>
> Best regards,
> Vicky
>
> ImageAnalyst schrieb:
>
>
>
> > On Oct 29, 11:46 am, Vicky <bonsa...@gmx.de> wrote:
> >> Hi there,
>
> >> I'll be grateful if someone can help me out.
>
> >> I have segmented bmp-images. Now I want to label (mark) each pixel of
> >> each image, so that pixel with the same color (rgb) become the same
> >> label. The label have to be an integer value.
>
> >> Is it possible to label an segmented image?
>
> >> How can I realize it?
>
> >> I think the marker-based watershed segmentation is such a thing that I
> >> need. But I have already segmented images.
>
> >> Best regards
> >> Vicky
>
> > ----------------------------------------------------------------------
> > Vicky:
> > You need the image processing toolkit. =A0In there, there is a function
> > called bwlabel() that does what you want.
> > Regards,
> > ImageAnalyst- Hide quoted text -
>
> - Show quoted text -

-------------------------------------------------------------------------
Vicky:
First you have to get a binary image that bwlabel can label. bwlabel
requires that the objects it labels NOT BE TOUCHING. If you can't
draw a thin line between the objects (e.g. by erosion) because it
might affect your areas, then I think your only recourse is to copy
each color out to a separate image and then label those. It looks
like you might have to do that (it's not hard - just one line of code
per color) since you have colored objects that are in contact with
each other.
Regards,
ImageAnalyst

Subject: how can I label segmented images

From: Vicky

Date: 31 Oct, 2008 13:03:37

Message: 5 of 18

Hallo ImageAnalyst,

it's a good idea to copy each color out. Then every color get an label.
The background is 0 and the colored object get the label 1. The object
get the label 1 in each seperated image. If I bring the sepearted images
together again (with an image addition) all the objects have the label
1. And so I can't distinguish the different colors.

Or do I understand it wrong?

Best regards,
Vicky


ImageAnalyst schrieb:
> On Oct 31, 7:18 am, Vicky <bonsa...@gmx.de> wrote:
>> Hallo ImageAnalyst,
>>
>> thank you very much for your help.
>> Now I have still a question.
>> My segmented images are so created that different colors are directly
>> next to each other. So for example between two colors is not a black
>> area. So if I use bwlabel() it makes one object of these two colors. But
>> this is not what I want. Each color should become a different integer value.
>>
>> bwlabel()returns a matrix, where each pixel get an integer value. The
>> pixels labeled 0 are the background, the pixels labeled 1 is an object
>> and so on.
>>
>> Is it possible to label the pixels with an integer value that I define?
>> Or can't I persuade the labels?
>>
>> Best regards,
>> Vicky
>>
>> ImageAnalyst schrieb:
>>
>>
>>
>>> On Oct 29, 11:46 am, Vicky <bonsa...@gmx.de> wrote:
>>>> Hi there,
>>>> I'll be grateful if someone can help me out.
>>>> I have segmented bmp-images. Now I want to label (mark) each pixel of
>>>> each image, so that pixel with the same color (rgb) become the same
>>>> label. The label have to be an integer value.
>>>> Is it possible to label an segmented image?
>>>> How can I realize it?
>>>> I think the marker-based watershed segmentation is such a thing that I
>>>> need. But I have already segmented images.
>>>> Best regards
>>>> Vicky
>>> ----------------------------------------------------------------------
>>> Vicky:
>>> You need the image processing toolkit. In there, there is a function
>>> called bwlabel() that does what you want.
>>> Regards,
>>> ImageAnalyst- Hide quoted text -
>> - Show quoted text -
>
> -------------------------------------------------------------------------
> Vicky:
> First you have to get a binary image that bwlabel can label. bwlabel
> requires that the objects it labels NOT BE TOUCHING. If you can't
> draw a thin line between the objects (e.g. by erosion) because it
> might affect your areas, then I think your only recourse is to copy
> each color out to a separate image and then label those. It looks
> like you might have to do that (it's not hard - just one line of code
> per color) since you have colored objects that are in contact with
> each other.
> Regards,
> ImageAnalyst

Subject: how can I label segmented images

From: Adam

Date: 31 Oct, 2008 14:15:04

Message: 6 of 18

Vicky <bonsai19@gmx.de> wrote in message <geevn9$s8t$1@aioe.org>...
> Hallo ImageAnalyst,
>
> it's a good idea to copy each color out. Then every color get an label.
> The background is 0 and the colored object get the label 1. The object
> get the label 1 in each seperated image. If I bring the sepearted images
> together again (with an image addition) all the objects have the label
> 1. And so I can't distinguish the different colors.
>
> Or do I understand it wrong?
>
> Best regards,
> Vicky

Just weight the layers as you add them together.

iOut = iRed + 2*iblue + 3*iGreen;

~Adam

Subject: how can I label segmented images

From: Vicky

Date: 31 Oct, 2008 14:39:13

Message: 7 of 18

Adam schrieb:
> Vicky <bonsai19@gmx.de> wrote in message <geevn9$s8t$1@aioe.org>...
>> Hallo ImageAnalyst,
>>
>> it's a good idea to copy each color out. Then every color get an label.
>> The background is 0 and the colored object get the label 1. The object
>> get the label 1 in each seperated image. If I bring the sepearted images
>> together again (with an image addition) all the objects have the label
>> 1. And so I can't distinguish the different colors.
>>
>> Or do I understand it wrong?
>>
>> Best regards,
>> Vicky
>
> Just weight the layers as you add them together.
>
> iOut = iRed + 2*iblue + 3*iGreen;
>
> ~Adam


Hallo Adam,

thank you very much for your answer.
But I don't know what you mean. Can you axplain something more?

Vicky

Subject: how can I label segmented images

From: Adam

Date: 31 Oct, 2008 16:20:02

Message: 8 of 18

Vicky <bonsai19@gmx.de> wrote in message

> it's a good idea to copy each color out.
Then every color get an label.
.
> The background is 0 and the colored object get the label 1.
.
It sounds like at this step you are capable of making an "image" which is the binary representation of a color. In my example I'm going to assume there are 4 colors, {red, green, blue, black}. You get 3 "images" that I'll call {iRed, iGreen, iBlue}
.
> The object get the label 1 in each seperated image.
.
So each of these "images" is a matrix full of 1's and 0's
.
> If I bring the sepearted images together again
>(with an image addition) all the objects have the label 1.
>And so I can't distinguish the different colors.
.
So change the ones to something else. The easy way is multiplying each "image".
iRed = iRed; % leave as 1
iBlue = iBlue * 2; % change to label 2
iGreen = iGreen * 3; % change to label 3
.
Now if you add them together they won't all be 1.
.
~Adam

Subject: how can I label segmented images

From: ImageAnalyst

Date: 31 Oct, 2008 20:21:38

Message: 9 of 18

On Oct 31, 12:20=A0pm, "Adam" <not.r...@email.com> wrote:
> Vicky <bonsa...@gmx.de> wrote in message
> > it's a good idea to copy each color out.
>
> Then every color get an label.
> .> The background is 0 and the colored object get the label 1.
>
> .
> It sounds like at this step you are capable of making an "image" which is=
 the binary representation of a color. =A0In my example I'm going to assume=
 there are 4 colors, {red, green, blue, black}. =A0You get 3 "images" that =
I'll call {iRed, iGreen, iBlue}
> .> The object get the label 1 in each seperated image.
>
> .
> So each of these "images" is a matrix full of 1's and 0's
> .> If I bring the sepearted images together again
> >(with an image addition) all the objects have the label 1.
> >And so I can't distinguish the different colors.
>
> .
> So change the ones to something else. =A0The easy way is multiplying each=
 "image".
> iRed =3D iRed; =A0% leave as 1
> iBlue =3D iBlue * 2; =A0% change to label 2
> iGreen =3D iGreen * 3; % change to label 3
> .
> Now if you add them together they won't all be 1.
> .
> ~Adam

---------------------------------------------------------------------
That won't work. At least not for labeling. If you separate them,
then just figure out what you want (areas, intensities, perimeters,
centroids, whatever) and you're done. No need to recombine into a
single image and try to (possibly) relabel and remeasure them in some
kind of combined image. It's just not necessary. Anyway the method
you and Adam thought up won't give blobs with unique label numbers.
It doesn't matter whether you just have binary maps of each color
plane or even if each color plane is labeled independently - you won't
have unique labels if you combine them in that way. Think about it
and you'll understand why. Just measure each image separately.
Regards,
ImageAnalyst

Subject: how to draw thin line between different color regions?

From: Basela Hasan

Date: 27 Jan, 2009 14:16:01

Message: 10 of 18

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <45e80e7d-08ae-4b57-b846-e656ae560989@s9g2000prm.googlegroups.com>...
> On Oct 31, 7:18=A0am, Vicky <bonsa...@gmx.de> wrote:
> > Hallo ImageAnalyst,
> >
> > thank you very much for your help.
> > Now I have still a question.
> > My segmented images are so created that different colors are directly
> > next to each other. So for example between two colors is not a black
> > area. So if I use bwlabel() it makes one object of these two colors. But
> > this is not what I want. Each color should become a different integer val=
> ue.
> >
> > bwlabel()returns a matrix, where each pixel get an integer value. The
> > pixels labeled 0 are the background, the pixels labeled 1 is an object
> > and so on.
> >
> > Is it possible to label the pixels with an integer value that I define?
> > Or can't I persuade the labels?
> >
> > Best regards,
> > Vicky
> >
> > ImageAnalyst schrieb:
> >
> >
> >
> > > On Oct 29, 11:46 am, Vicky <bonsa...@gmx.de> wrote:
> > >> Hi there,
> >
> > >> I'll be grateful if someone can help me out.
> >
> > >> I have segmented bmp-images. Now I want to label (mark) each pixel of
> > >> each image, so that pixel with the same color (rgb) become the same
> > >> label. The label have to be an integer value.
> >
> > >> Is it possible to label an segmented image?
> >
> > >> How can I realize it?
> >
> > >> I think the marker-based watershed segmentation is such a thing that I
> > >> need. But I have already segmented images.
> >
> > >> Best regards
> > >> Vicky
> >
> > > ----------------------------------------------------------------------
> > > Vicky:
> > > You need the image processing toolkit. =A0In there, there is a function
> > > called bwlabel() that does what you want.
> > > Regards,
> > > ImageAnalyst- Hide quoted text -
> >
> > - Show quoted text -
>
> -------------------------------------------------------------------------
> Vicky:
> First you have to get a binary image that bwlabel can label. bwlabel
> requires that the objects it labels NOT BE TOUCHING. If you can't
> draw a thin line between the objects (e.g. by erosion) because it
> might affect your areas, then I think your only recourse is to copy
> each color out to a separate image and then label those. It looks
> like you might have to do that (it's not hard - just one line of code
> per color) since you have colored objects that are in contact with
> each other.
> Regards,
> ImageAnalyst
I have a colored image and I want to lables the pixels of each color region. Actually I met similar problem as mentioned above, but I don't know how to use imerode to draw this thin line between different color regions? I've tried it but I couldn't get those regions separated.

Thanks,
 

Subject: how to draw thin line between different color regions?

From: Pete

Date: 27 Jan, 2009 16:01:04

Message: 11 of 18

I'm neither sure that I've understood you all nor that I have coded this correctly, but you could try this function:

function im_labeled = image_labeller(im)
% IM is a 3 channel colour image, in which each colour corresponds to an
% object that should be labeled

% Get a num_pixels x 3 array - each row is a colour in the original image
x = reshape(im, size(im,1)*size(im,2), 3);

% Identify unique colours
[b, m, n] = unique(x, 'rows');

% Create the labels - a separate label for each colour
% (You might want to use 0:size(b,1)-1 instead)
labels = 1:size(b,1);

% Put the labels into a vector -
% check out the help for UNIQUE to get a better idea what's happening
im_labeled = labels(n);

% Reshape the vector to have the same dimensions as IM
im_labeled = reshape(im_labeled, size(im, 1), size(im, 2));

Subject: how to draw thin line between different color regions?

From: ImageAnalyst

Date: 27 Jan, 2009 16:14:38

Message: 12 of 18

Basela:
I can't understand what you said and can't really visualize what you
want to do. Maybe you could mock something up in Photoshop and post
it somewhere (such as at drop.io, posterous.com, or flickr.com). Once
you've labeled the image, you can display them in colors if you want
using the label2rgb() function. If they're in different colors, I
don't see why you'd need a line "between different color regions."
And can you explain "between"? Do you mean like a black line
separating the colors (right on the boundary), or do you mean going,
say, from the centroid of one to the centroid of the other region.
Actually I can't think of a reason for wanting/needing to do either
one. One thing you could do is use bwboundaries() if you want the
coordinates of the outlines of the regions. Then you could use them
(the boundary coordinates) to draw them in a color of your choice
(such as black).
Regards,
ImageAnalyst

Subject: how to draw thin line between different color regions?

From: Walter Roberson

Date: 27 Jan, 2009 17:34:37

Message: 13 of 18

ImageAnalyst wrote:
> Basela:
> I can't understand what you said and can't really visualize what you
> want to do.

> If they're in different colors, I
> don't see why you'd need a line "between different color regions."
> And can you explain "between"? Do you mean like a black line
> separating the colors (right on the boundary), or do you mean going,
> say, from the centroid of one to the centroid of the other region.

I believe the current request was in response to your reply to the original
poster in a slightly earlier thread in which you indicated that bwlabel needs
the objects to be separated by at least a thin line -- that is, that the
original poster has an image with multiple objects distinguished by
colour but sometimes adjacent, and wishes to label the objects.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: how can I label segmented images

From: Walter Roberson

Date: 27 Jan, 2009 17:40:41

Message: 14 of 18

Vicky wrote:

> I have segmented bmp-images. Now I want to label (mark) each pixel of
> each image, so that pixel with the same color (rgb) become the same
> label.

Are the images artificially generated? If not, if they are camera
images, then even if the objects are extremely uniform in colour
in manufacture, when you take pictures of them, due to differences
in illumination and shadows, and differences in sensitivity of
the individual CCD cells, and due to thermal noise, it is unlikely
that all pixels of the same object will have *exactly* the same RGB
triples. In order to identify areas of "the same color" you may wish
to use John d'Errico's FEX (Matlab File Exchange) contribution for
fuzzy color matching.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: how to draw thin line between different color regions?

From: Image Analyst

Date: 27 Jan, 2009 17:45:04

Message: 15 of 18

I thought the colors were in the labeled image, but maybe they're in the original image. If he doesn't yet have the labeled image, but has only the binary image, then he can try to use watershed segmentation (watershed), or the Euclidean distance map (bwdist) to separate blobs. But it seems like these are often problematic and over segment the object, sending a dividing line across the blob at every little indent in the outline. He could also try erosion down to "markers" (or even to the "utlimate eroded set") and then use the markers to morphologically "reconstruct" the objects (basically dilating out again but don't let blobs join together). Or if he has just a few images, there's always the manual way - just use freehanddraw (file exchange) to trace a curve and then blacken the binary image under the curve, then call bwlabel.

Subject: how to draw thin line between different color regions?

From: Basela Hasan

Date: 28 Jan, 2009 10:19:01

Message: 16 of 18

"Image Analyst" <imageanalyst@mailinator.com> wrote in message <glnh70$ob0$1@fred.mathworks.com>...
> I thought the colors were in the labeled image, but maybe they're in the original image. If he doesn't yet have the labeled image, but has only the binary image, then he can try to use watershed segmentation (watershed), or the Euclidean distance map (bwdist) to separate blobs. But it seems like these are often problematic and over segment the object, sending a dividing line across the blob at every little indent in the outline. He could also try erosion down to "markers" (or even to the "utlimate eroded set") and then use the markers to morphologically "reconstruct" the objects (basically dilating out again but don't let blobs join together). Or if he has just a few images, there's always the manual way - just use freehanddraw (file exchange) to trace a curve and then blacken the binary image under the curve, then call bwlabel.

Sorry but just to be clear, I'm trying to label people clothes in family album photos, I thought of the following procedure to do this task:
1- crop the clothing box (this box may have backgound and partial occlusion)
2- I want to draw a black thin line between those different color regions in the bounding box.
3. use bwlabel to label the pixels of each color region.
Actually I know that I can use a pain program, but my question was, is there someway in matlab to automate step 2?

Thank you all.

Subject: how to draw thin line between different color regions?

From: Walter Roberson

Date: 29 Jan, 2009 17:01:51

Message: 17 of 18

Basela Hasan wrote:

> Sorry but just to be clear, I'm trying to label people clothes in family album photos,

Then like I suggested the other day, the areas you want to label will not be
a consistent color in the images even if they were a consistent color in real
life. And clothes in real life have a tendency not to be all one colour and
a tendency to be patterned and possibly to have laces or other such objects
that are really part of the clothes but which dangle or are complicated shapes
and so on. With regards to solid colours, recall that with clothes it is common
for the buttons to be a different colour.

Therefore, you will not be able to segment the images just by colour with any
accuracy. You will probably need pattern (texture) mapping as well.

How do you intend to handle the case where someone's shirt/ top/ blouse is
very much the same colour (perhaps even the same material and same pattern) as
their pants / shorts / skirt? There might or might not be a fine dividing line between
the two that a human could detect. If a top and skirt were deliberately coordinated
then is that a single outfit to be grouped as a single object, or is it a
two piece outfit to be segmented into two objects? And if a woman's clothes
appear to be a jacket over a skirt, then you cannot tell without opening the
combination and attempting to take it apart whether it is really physically
one piece, or physically two pieces but with the jacket required to be worn,
or physically two pieces with the jacket optional but a normal part of the
outfit (but could be removed if, say, it got quite warm), or physically two
pieces with the jacket fully removable in a design sense (in which case it is
logically two distinct objects.) Even if a woman's jacket is open at the
front, you cannot easily determine whether the outfit is logically one piece
or two pieces without being able to examine the construction.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: how to draw thin line between different color regions?

From: ImageAnalyst

Date: 29 Jan, 2009 22:15:00

Message: 18 of 18

On Jan 29, 12:01=A0pm, Walter Roberson <rober...@hushmail.com> wrote:
[Walter's insightful response snipped]
Well said Walter. I was thinking the same thing myself. I just
wasn't as gracious as you in detailing a response (since it would take
a while). Sometimes people think something will be easy but once you
think about it, it could actually get very complicated. But when I
saw that the poster was now "Basela Hasan" when it started out as
"Vicky" (while still acting as Vicky trying to clear things up) and
the subject line for the thread also changed - well, I just lost
interest even more. I mean, how many people are we talking to here?

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
thresholding sait Billgates 31 Jan, 2009 02:43:33
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com