Discussion:
mahotas - dilate with large structuring elements
Gil Gonçalves
2014-04-09 13:58:17 UTC
Permalink
Hi,

I'm trying to dilate a binary image with a large structuring element using
dilate.

se=ones((200,200),uint8)

If I use cv2.dilate no problem at all, but with mahotas.dilate the computer
sucks.

Another question is how to find the largest connected component in a
labeled image.
Using matlab I use the property PixelIdxList to get the pixel list of the
connected components. But with mahotas I don't know I to get these list.

Thanks for the possible help.

gil
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Luis Pedro Coelho
2014-04-09 15:59:50 UTC
Permalink
Post by Gil Gonçalves
I'm trying to dilate a binary image with a large structuring element
using dilate.
se=ones((200,200),uint8)
If I use cv2.dilate no problem at all, but with mahotas.dilate the
computer sucks.
Yeah, this is a known issue. The mahotas code is optimized for small
structuring elements, but does not scale very well for large one.

Btw, why are you dilating with such a large element?

I've considered adding a second implementation for large files and
choosing on the fly, but never really figured out a use case for very
large s.e.
Post by Gil Gonçalves
Another question is how to find the largest connected component in a
labeled image.
labeled,_ = mh.label(binary_image)
sizes = mh.labeled.labeled_size(labeled)

# Ignore the background object, probably:
sizes[0] = 0

print "Largest object is", sizes.argmax()

# isolate it
largest = (labeled == sizes.argmax())

HTH,
Luis
--
Luis Pedro Coelho | EMBL | http://luispedro.org

Recent stuff:
http://doi.org/10.1002/bies.201300143
http://dx.doi.org/10.1038/nm.3424
http://dx.doi.org/10.1038/nmeth.2693
Post by Gil Gonçalves
Using matlab I use the property PixelIdxList to get the pixel list of
the connected components. But with mahotas I don't know I to get these
list.
Thanks for the possible help.
gil
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Gil Gonçalves
2014-04-09 16:31:39 UTC
Permalink
Hi Luis

Thanks for the quicker answer. In fact I'm dilating the binary image to get
a buffer along an object (a line) to speed up my analysis. But of-course
maybe this can be done in a more efficient way.

gil

Em quarta-feira, 9 de abril de 2014 16h59min50s UTC+1, Luis Pedro Coelho
Post by Luis Pedro Coelho
Post by Gil Gonçalves
I'm trying to dilate a binary image with a large structuring element
using dilate.
se=ones((200,200),uint8)
If I use cv2.dilate no problem at all, but with mahotas.dilate the
computer sucks.
Yeah, this is a known issue. The mahotas code is optimized for small
structuring elements, but does not scale very well for large one.
Btw, why are you dilating with such a large element?
I've considered adding a second implementation for large files and
choosing on the fly, but never really figured out a use case for very
large s.e.
Post by Gil Gonçalves
Another question is how to find the largest connected component in a
labeled image.
labeled,_ = mh.label(binary_image)
sizes = mh.labeled.labeled_size(labeled)
sizes[0] = 0
print "Largest object is", sizes.argmax()
# isolate it
largest = (labeled == sizes.argmax())
HTH,
Luis
--
Luis Pedro Coelho | EMBL | http://luispedro.org
http://doi.org/10.1002/bies.201300143
http://dx.doi.org/10.1038/nm.3424
http://dx.doi.org/10.1038/nmeth.2693
Post by Gil Gonçalves
Using matlab I use the property PixelIdxList to get the pixel list of
the connected components. But with mahotas I don't know I to get these
list.
Thanks for the possible help.
gil
-
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Sprindzuk Matvey
2014-04-09 16:47:41 UTC
Permalink
Sorry, I have no experience like that. You can try various versions of
Mahotas on several OS platforms or try PIL, SimpleCV or Mamba CV libraries

Best

M
Post by Gil Gonçalves
Hi,
I'm trying to dilate a binary image with a large structuring element using
dilate.
se=ones((200,200),uint8)
If I use cv2.dilate no problem at all, but with mahotas.dilate the
computer sucks.
Another question is how to find the largest connected component in a
labeled image.
Using matlab I use the property PixelIdxList to get the pixel list of the
connected components. But with mahotas I don't know I to get these list.
Thanks for the possible help.
gil
--
You received this message because you are subscribed to the Google Groups
"pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Gil Gonçalves
2014-04-09 17:03:59 UTC
Permalink
<https://lh3.googleusercontent.com/-2qWQYUnhUcI/U0V8pxWm5rI/AAAAAAAAAHw/LjpAEwUkd2k/s1600/Selec%C3%A7%C3%A3o_001.bmp>
Sorry, I have no experience like that. You can try various versions of
Mahotas on several OS platforms or try PIL, SimpleCV or Mamba CV libraries
Best
M
Post by Gil Gonçalves
Hi,
I'm trying to dilate a binary image with a large structuring element
using dilate.
se=ones((200,200),uint8)
If I use cv2.dilate no problem at all, but with mahotas.dilate the
computer sucks.
Another question is how to find the largest connected component in a
labeled image.
Using matlab I use the property PixelIdxList to get the pixel list of the
connected components. But with mahotas I don't know I to get these list.
Thanks for the possible help.
gil
--
You received this message because you are subscribed to the Google Groups
"pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Luis Pedro Coelho
2014-04-09 17:24:55 UTC
Permalink
The image you posted was not even 200 pixels wide, so I do wonder why
you'd want to dilate it by 200,200. Basically, if there is a single
white pixel, the whole image will turn white.

Are you sure this is what you want to do?

In any case, you can also dilate by smaller amounts repeatedly. Dilating
by 200,200 takes 40s on my computer, but I can repeatedly dilate by
10,10 to get a similar result.

HTH,
Luis
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Gil Gonçalves
2014-04-09 17:31:19 UTC
Permalink
Hi Luis

The original image as 4692x2449 pixels. I've posted a screen shot.

gil
Post by Luis Pedro Coelho
The image you posted was not even 200 pixels wide, so I do wonder why
you'd want to dilate it by 200,200. Basically, if there is a single
white pixel, the whole image will turn white.
Are you sure this is what you want to do?
In any case, you can also dilate by smaller amounts repeatedly. Dilating
by 200,200 takes 40s on my computer, but I can repeatedly dilate by
10,10 to get a similar result.
HTH,
Luis
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Luis Pedro Coelho
2014-04-09 18:45:49 UTC
Permalink
Ok, that makes much more sense :)

Have you considered using a distance transform and thresholding on it?

import mahotas as mh
pseudo_dilation = mh.distance(~ binary_image) < 100

Not exactly the same, but maybe it solves your problem.

HTH
Luis
Post by Gil Gonçalves
Hi Luis
The original image as 4692x2449 pixels. I've posted a screen shot.
gil
The image you posted was not even 200 pixels wide, so I do wonder why
you'd want to dilate it by 200,200. Basically, if there is a single
white pixel, the whole image will turn white.
Are you sure this is what you want to do?
In any case, you can also dilate by smaller amounts repeatedly. Dilating
by 200,200 takes 40s on my computer, but I can repeatedly dilate by
10,10 to get a similar result.
HTH,
Luis
--
You received this message because you are subscribed to the Google
Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
Luis Pedro Coelho | EMBL | http://luispedro.org

Recent stuff:
http://doi.org/10.1002/bies.201300143
http://dx.doi.org/10.1038/nm.3424
http://dx.doi.org/10.1038/nmeth.2693
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Gil Gonçalves
2014-04-09 18:51:52 UTC
Permalink
It is a good suggestion. Thanks.

Em quarta-feira, 9 de abril de 2014 19h45min49s UTC+1, Luis Pedro Coelho
Post by Luis Pedro Coelho
Ok, that makes much more sense :)
Have you considered using a distance transform and thresholding on it?
import mahotas as mh
pseudo_dilation = mh.distance(~ binary_image) < 100
Not exactly the same, but maybe it solves your problem.
HTH
Luis
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Loading...