[Numpy-discussion] position of objects?
klimek at grc.nasa.gov
Wed Jan 19 11:26:37 CST 2005
Peter Verveer wrote:
> The watershed_ift() is a somewhat uusual implementation of watershed.
> In principle it does the same as a normal watershed, except that it
> does not produce watershed lines. I implemented this one, because with
> the current implementation of binary morphology it is a bit cumbersome
> to implement more common approaches. That will hopefully change in the
Well, it might turn out to still be useful. From what I'm reading,
watershed from markers can do some interesting things. See the library
> The procedure you show below seems to be based on a normal watershed.
> I am not completely sure how the Image-J implementation works, but one
> way to do that would be to do a watershed on the distance transform of
> that image (actually you would use the negative of the distance
> transform, with the local minima of that as the seeds). You could do
> that with watershed_ift, in this case it would give you two labeled
> objects, that in contrast to your example would however touch each
> other. To do the exact same as below a watershed is needed that also
> gives watershed lines.
I'll give this procedure a try. Even if the labeled objects touch, some
code could perhaps separate the objects by changing the touching pixels
> Prompted by your earlier questions about skeletons I had a look at
> what it would take to properly implement skeletons and other
> morphology based algorithms, such as watersheds, and I found that I
> need to rethink and reimplement the basic morphology operations first. ...
Well, improving things is always good but from what I can see its not
bad right now.
if you are going to be changing things, one minor suggestion from me
would be to make indices of label() (and sum(), mean(), ...) and
find_objects() the same. For example, in an image containg two objects,
label() returns a list of three: 0, 1, and 2 where 0 is the background
and the two objects are labeled 1 and 2. But find_objects() returns a
list of two (indices in the list being 0 and 1). Its not a big deal but
in a for-loop it gets a little messy. Also forces me to do things like
the following example which requires the loop to start at 1 (to skip the
background) and run the range to n+1 to capture the second object.
labeled, n = ND.label(binImage)
objList = ND.sum(binImage, labeled, range(n+1))
for i in range(1, len(objList)):
print 'object %d pixels: %d ' % (i, objList[i])
On a different note, I came across a morphology library which looks very
I've contacted one of the authors of the package (R. Lotufo) and he
indicated that they are thinking about updating it to run under numarray
probably in about 6 months. Perhaps you and them could join forces. The
only potential problem I see is that their code is designed strictly for
2D grayscale and binary images whereas you are trying to keep it general
for any number of dimensions.
More information about the Numpy-discussion