comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: connected component labeling problem in a graylevel image without background
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: connected component labeling problem in a graylevel image without background [message #32494] Fri, 11 October 2002 10:15 Go to next message
Julia is currently offline  Julia
Messages: 11
Registered: July 2002
Junior Member
Yes, David, I think you've got the point.

> How many marbles do I have
> with a gray-scale level of X?
Variable. A graylevel at most times corresponds to a marble. But
at some graylevels, maybe it has two, three or more marbles each graylevel.

> but if you have N gray-levels and you have a tool that works with
> bi-level images only, don't you pretty much have to use
> your tool N times to get what you want?
Right, if we use label_region function which works only on binay image.
But I think if we know how they do label_region and extend the algorithm on
the graylevel image,
maybe we only needs to trace the image less than twice.
I am not sure if this is practical.

Cheers,

Julia


"David Fanning" <david@dfanning.com> wrote in message
news:MPG.1810ac85dd5a4b049899de@news.frii.com...
> Julia (julia65201@yahoo.com) writes:
>
>> But I think you kind of misunderstood my problem, maybe due to my not
very
>> clear expression. :)
>>
>>>> " The problem is like a grayscale photograph of a jar of
>>>> marbles. Each marble is uniformly gray. All the marbles are touching
each
>>>> other, so there is no
>>>> background. Two marbles of the same color may not belong to the same
>>>> region.
>>>> I want to give a unique label to each marble/region."
>>
>> In my problem, all the marbles are touching each other, so there is no
>> background there. I do not think I can use
>> label_region on the original image. So I do like this:
>> First, use HISTOGRAM to get a mask of regions at each gray level, and
then
>> use LABEL_REGION on each mask.
>>
>> If there are n gray levels in the image, I need do label_region n times.
I
>> think this is not very efficient. I am not sure if I can solve this kind
of
>> problem more efficiently in IDL, I call it "connected component labeling
>> problem in a graylevel image without background".
>>
>> Any suggestion there?
>
> I'd never be confused with a mathematician, but if you
> have N gray-levels and you have a tool that works with
> bi-level images only, don't you pretty much have to use
> your tool N times to get what you want? At least if I
> understand the question to be: How many marbles do I have
> with a gray-scale level of X?
>
> Cheers,
>
> David
>
> P.S. Let's just say I'd bet some good money even the
> HISTOGRAM function can't get us out of this one. :-)
>
> --
> David W. Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Phone: 970-221-0438, E-mail: david@dfanning.com
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Toll-Free IDL Book Orders: 1-888-461-0155
Re: connected component labeling problem in a graylevel image without background [message #32495 is a reply to message #32494] Fri, 11 October 2002 09:38 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Julia (julia65201@yahoo.com) writes:

> But I think you kind of misunderstood my problem, maybe due to my not very
> clear expression. :)
>
>>> " The problem is like a grayscale photograph of a jar of
>>> marbles. Each marble is uniformly gray. All the marbles are touching each
>>> other, so there is no
>>> background. Two marbles of the same color may not belong to the same
>>> region.
>>> I want to give a unique label to each marble/region."
>
> In my problem, all the marbles are touching each other, so there is no
> background there. I do not think I can use
> label_region on the original image. So I do like this:
> First, use HISTOGRAM to get a mask of regions at each gray level, and then
> use LABEL_REGION on each mask.
>
> If there are n gray levels in the image, I need do label_region n times. I
> think this is not very efficient. I am not sure if I can solve this kind of
> problem more efficiently in IDL, I call it "connected component labeling
> problem in a graylevel image without background".
>
> Any suggestion there?

I'd never be confused with a mathematician, but if you
have N gray-levels and you have a tool that works with
bi-level images only, don't you pretty much have to use
your tool N times to get what you want? At least if I
understand the question to be: How many marbles do I have
with a gray-scale level of X?

Cheers,

David

P.S. Let's just say I'd bet some good money even the
HISTOGRAM function can't get us out of this one. :-)

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: connected component labeling problem in a graylevel image without background [message #32496 is a reply to message #32495] Fri, 11 October 2002 09:13 Go to previous messageGo to next message
Julia is currently offline  Julia
Messages: 11
Registered: July 2002
Junior Member
Thanks for your reply, Ben.

But I think you kind of misunderstood my problem, maybe due to my not very
clear expression. :)

>> " The problem is like a grayscale photograph of a jar of
>> marbles. Each marble is uniformly gray. All the marbles are touching each
>> other, so there is no
>> background. Two marbles of the same color may not belong to the same
>> region.
>> I want to give a unique label to each marble/region."

In my problem, all the marbles are touching each other, so there is no
background there. I do not think I can use
label_region on the original image. So I do like this:
First, use HISTOGRAM to get a mask of regions at each gray level, and then
use LABEL_REGION on each mask.

If there are n gray levels in the image, I need do label_region n times. I
think this is not very efficient. I am not sure if I can solve this kind of
problem more efficiently in IDL, I call it "connected component labeling
problem in a graylevel image without background".

Any suggestion there?

Julia



----- Original Message -----
From: "Ben Tupper" <btupper@bigelow.remove.org>
Newsgroups: comp.lang.idl-pvwave
Sent: Friday, October 11, 2002 10:20 AM
Subject: Re: connected component labeling problem in a graylevel image
without background

> Hi there in the 'Show Me' state! My brother lives just south of
> Rolla - near Fort Leonard Wood. I have visited there once and I was
> just wowed by the geological landscape. Here in New England the
> landscape is just such dull (but beautiful, too) post-glacial!
>
> Happy to help if I can.
>
> Your problem is a bit different from that I have encountered. In my
> cases, we had a segmented image of phytoplankton and ever-present
> debris, too. Each feature (aka blob) has varying gray scale values.
> It sounds like your marbles have homogeneous gray scale values even
> though the gray scale value might change from marble to marble.
>
> I'm not sure of the specifics of what you want to do with each
> feature, but here's what I would pull them out of the image.
>
> Starting with your segmented image (background = 0, foreground = any
> values other than zero)... which has dimension nx,ny.
>
> Create a blank image that is one pixel wider in each direction than
> your segmented image. Be sure the extra pixels in the
> one-pixel-wide-pad are all set to the background value, 0. If you
> know the images will ALWAYS be the same size, simply make one copy of
> this and use it repeatedly rather than making this larger image over
> and over again. You could store this in a pointer, an object, or in a
> system variable.
>
> padded = bytarr(nx+2, ny+2)
>
> Copy your segmented image into the slightly larger image
>
> padded[1:nx-2, 1:ny-2] = segmented
>
> Run the padded image through LABEL_REGION
>
> labeled = LABEL_REGION(padded, keywords=keywords)
>
> Use HISTOGRAM to get the indices of the color blobs - subset the
> labeled image at the same time. Capture the reverse indices.
>
> h = HISTOGRAM(labeled[1:nx, 1:ny], reverse_indices = r)
>
> Now through the magic of reverse_indices, you can quickly pull out the
> location of each feature (marble, in this case). I can't recall the
> syntax off hand (I don't have IDL right here, either), but I do recall
> an example in the documentation for HISTOGRAM. If that doesn't help,
> check out David Fanning's web pages.
>
> I'm not sure if that helps or answers your question. I'm not even
> sure, now that I reread you note, what your question is. This does
> mean that you have scanned the image at least twice (LABEL_REGION and
> HISTOGRAM) in addition to any scanning you did to segment the image.
>
> Cheers,
> Ben
>>
Re: connected component labeling problem in a graylevel image without background [message #32502 is a reply to message #32496] Fri, 11 October 2002 09:15 Go to previous messageGo to next message
Ben Tupper is currently offline  Ben Tupper
Messages: 186
Registered: August 1999
Senior Member
On Fri, 11 Oct 2002 06:55:23 -0600, David Fanning <david@dfanning.com>
wrote:

> Ben Tupper (btupper@bigelow.remove.org) writes:
>
>> Now through the magic of reverse_indices, you can quickly pull out the
>> location of each feature (marble, in this case). I can't recall the
>> syntax off hand (I don't have IDL right here, either), but I do recall
>> an example in the documentation for HISTOGRAM. If that doesn't help,
>> check out David Fanning's web pages.
>
> Now hold on here. Have you *ever* heard me
> claim I understand REVERSE_INDICES? I don't
> think so.
>
> Cheers,
>
> David
>
> P.S. Let's just say I've been embarrassed more than a
> few times by writing about things I don't understand, but
> even I know the difference between ignorance and complete
> and utter bewilderment. :-(

Oops! I never meant to undermine your good standing in the IDLEPA.
You'll note, I hope, that I did say reverse_indices is *magic*. My
view probably is rooted in some ancient anthropoid response to
misunderstood natural phenomena.

I guess I had this in mind (snipped from JDs tutorial on REBIN found
in your web-treasures.)

> Perhaps I'll also write a histogram tutorial, revealing all my tricks. Then I could pass the torch to Pavel...
>
> JD


Cheers to you David,
Ben
Re: connected component labeling problem in a graylevel image without background [message #32503 is a reply to message #32496] Fri, 11 October 2002 05:55 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Ben Tupper (btupper@bigelow.remove.org) writes:

> Now through the magic of reverse_indices, you can quickly pull out the
> location of each feature (marble, in this case). I can't recall the
> syntax off hand (I don't have IDL right here, either), but I do recall
> an example in the documentation for HISTOGRAM. If that doesn't help,
> check out David Fanning's web pages.

Now hold on here. Have you *ever* heard me
claim I understand REVERSE_INDICES? I don't
think so.

Cheers,

David

P.S. Let's just say I've been embarrassed more than a
few times by writing about things I don't understand, but
even I know the difference between ignorance and complete
and utter bewilderment. :-(

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: connected component labeling problem in a graylevel image without background [message #32504 is a reply to message #32503] Fri, 11 October 2002 08:20 Go to previous messageGo to next message
Ben Tupper is currently offline  Ben Tupper
Messages: 186
Registered: August 1999
Senior Member
On Thu, 10 Oct 2002 23:07:31 -0500, "Julia" <julia65201@yahoo.com>
wrote:

> Hi, there,
>
> I have a problem here:
> " The problem is like a grayscale photograph of a jar of
> marbles. Each marble is uniformly gray. All the marbles are touching each
> other, so there is no
> background. Two marbles of the same color may not belong to the same
> region.
> I want to give a unique label to each marble/region."
>
> Now I am solving this problem in this way:
> First, use WHERE or HISTOGRAM to get a mask of regions
> at each gray level, and then use LABEL_REGION on each mask.
>
> However, this method is not efficient since it needs to scan the image
> for several times.
>
> Can I do it only in a raster scan of the image?
>
> Any suggestion will be appreciated,
>
> Julia

I just received a personal email from someone with a remarkably
similar question from Missouri. I thought I might put my reply here.

At 09:38 PM 10/10/2002 -0500, you wrote:
> Hello, Ben,
>
> I am doing some stuff of blob coloring now. I searched on the Internet and saw your post. If you can
> take a time to look at my problem, it will be highly appreciate.
>
> " When the label region is used to uniquely mark blobs within an image,
> the edge pixels are all assumed to be zero. I would like to preserve
> those edge pixels AND perform the region labeling."
>
> Now I am encountering the same problem.
> " The problem is like a grayscale photograph of a jar of
> marbles. Each marble is uniformly gray. All the marbles are touching each other, so there is no
> background. Two marbles of the same color may not belong to the same region.
> I want to give a unique label to each marble/region."
>
> Now I am solving this problem in this way:
> First, use WHERE or HISTOGRAM to get a mask of regions
> at each gray level, and then use LABEL_REGION on each mask.
>
> However, this method is not efficient since it needs to scan the image
> for several times.
>
> Have you solved this problem? Do you have any suggestion that can do it in a
> raster scan of the image?
>
> I look forward to your reply.
>
> Thanks,
>
> Xiaoying Jin
>


Hi there in the 'Show Me' state! My brother lives just south of
Rolla - near Fort Leonard Wood. I have visited there once and I was
just wowed by the geological landscape. Here in New England the
landscape is just such dull (but beautiful, too) post-glacial!

Happy to help if I can.

Your problem is a bit different from that I have encountered. In my
cases, we had a segmented image of phytoplankton and ever-present
debris, too. Each feature (aka blob) has varying gray scale values.
It sounds like your marbles have homogeneous gray scale values even
though the gray scale value might change from marble to marble.

I'm not sure of the specifics of what you want to do with each
feature, but here's what I would pull them out of the image.

Starting with your segmented image (background = 0, foreground = any
values other than zero)... which has dimension nx,ny.

Create a blank image that is one pixel wider in each direction than
your segmented image. Be sure the extra pixels in the
one-pixel-wide-pad are all set to the background value, 0. If you
know the images will ALWAYS be the same size, simply make one copy of
this and use it repeatedly rather than making this larger image over
and over again. You could store this in a pointer, an object, or in a
system variable.

padded = bytarr(nx+2, ny+2)

Copy your segmented image into the slightly larger image

padded[1:nx-2, 1:ny-2] = segmented

Run the padded image through LABEL_REGION

labeled = LABEL_REGION(padded, keywords=keywords)

Use HISTOGRAM to get the indices of the color blobs - subset the
labeled image at the same time. Capture the reverse indices.

h = HISTOGRAM(labeled[1:nx, 1:ny], reverse_indices = r)

Now through the magic of reverse_indices, you can quickly pull out the
location of each feature (marble, in this case). I can't recall the
syntax off hand (I don't have IDL right here, either), but I do recall
an example in the documentation for HISTOGRAM. If that doesn't help,
check out David Fanning's web pages.

I'm not sure if that helps or answers your question. I'm not even
sure, now that I reread you note, what your question is. This does
mean that you have scanned the image at least twice (LABEL_REGION and
HISTOGRAM) in addition to any scanning you did to segment the image.

Cheers,
Ben
>
Re: connected component labeling problem in a graylevel image without background [message #32567 is a reply to message #32495] Tue, 15 October 2002 09:20 Go to previous message
Ben Tupper is currently offline  Ben Tupper
Messages: 186
Registered: August 1999
Senior Member
On Fri, 11 Oct 2002 10:38:48 -0600, David Fanning <david@dfanning.com>
wrote:

> Julia (julia65201@yahoo.com) writes:
>
>> But I think you kind of misunderstood my problem, maybe due to my not very
>> clear expression. :)
>>
>>>> " The problem is like a grayscale photograph of a jar of
>>>> marbles. Each marble is uniformly gray. All the marbles are touching each
>>>> other, so there is no
>>>> background. Two marbles of the same color may not belong to the same
>>>> region.
>>>> I want to give a unique label to each marble/region."
>>
snip
>
> P.S. Let's just say I'd bet some good money even the
> HISTOGRAM function can't get us out of this one. :-)

Oh! Wait, wait! Maybe you could use histogram! At least, for the
easiest of the marbles. Consider an image (dimx, dimy) with a
couple of gray circles (gray pixels have index addresses ind).

Start with the indices of each gray level from the original histogram
(use reverse_indices to pull out these indices.) Convert the indices
to cartesian coords.

x = ind mod dimx
y = ind/dimx

Use histogram (actually, JD's hist_nd.pro ... I found it using
Google) to manufacture X and Y profiles of the marbles.

; hist=HIST_ND(V,BINSIZE,MIN=,MAX=,NBINS=,REVERSE_INDICES=)

v = transpose([[x],[y]])
binsz = [1,1]
hh = hist_nd(v, binsz, min = [0,0], max = [dimx-1, dimy-1])

Now, peak at the resulting histograms in each dimension - these will
be like profile plots or the original image for each gray level n. (I
suppose these could be called shadow plots along each dimension.)

!p.multi = [0,1,2]
Plot, hh[0,*], title = 'x profile'
Plot, indgen(dimx), hh[1,*], title = 'y profile'

If the marbles do not overlap (in a dimension), then the center of
mass of each marble along each dimension should be easy to find. If
they do overlap - well that's a new kind of problem. I suppose that
you are not limited to the X and Y axes - that is, you could develop a
profile along any arbitrarily rotated axis. That math gets a bit
fuzzy for me after this point, but it should be just a geometry game.

I don't IDL in front of me this morning - so this is cut and pasted
from my own wobbly memory (and it still a bit early in the morn'.)

Cheers,
Ben
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: gzip files
Next Topic: connected component labeling problem in a graylevel image without background

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:31:44 PDT 2025

Total time taken to generate the page: 0.00888 seconds