ndimage zero-ignorant filters, or other ways to fill holes
![](https://secure.gravatar.com/avatar/ebfeaf378875b178c108e9a45285114a.jpg?s=120&d=mm&r=g)
Guys, I feel a bit hesistant to ask this because I know: as a fairly intensive user of scipy i should try to give something back to the community and code it up myself. However, I don't feel confident enough with ndimage's c code, and feel I'd spend much too much time and energy on it. That being said, I'm dying (well, almost) for a zero-ignorant version of ndimage.uniform_filter. In other words: a nd (2-d would be enough for me) windowing average filter that gives me back the mean of the non-zero pixels in the window. All current ndimage filters just incorporate the zero's, NaN's propagate through, and ndimage doesn't work with masks or masked arrays. I often find myself looking for a simple way to fill gaps (patches of zeros) in an image with values resembling the average surroundings of the gap, or smoothing an image that has zero-filled gaps of data that should not be taken into account while smoothing. I could solve such a thing very easily by iterating a version of uniform_filter that would not incorporate the zero-cells in its calculation. Hmm, I feel it's hard to explain. I hope someone understands what I mean... If someone would be willing to contribute such a feature to ndimage, please know that you'd at least make me very happy :) If someone comes up with another brillant idea to fill the zero-gaps in my images with values that are in reasonable range of the gap's surroundings, I'd also be very grateful. Keep in mind that the images typically are pretty large, though. 7000x7000 pixels is no exception. Regards, Vincent Schut.
![](https://secure.gravatar.com/avatar/0712dc182847d310baab088228011f47.jpg?s=120&d=mm&r=g)
On Mon, Nov 24, 2008 at 1:03 PM, Vincent Schut <schut@sarvision.nl> wrote:
If someone comes up with another brillant idea to fill the zero-gaps in my images with values that are in reasonable range of the gap's surroundings, I'd also be very grateful. Keep in mind that the images typically are pretty large, though. 7000x7000 pixels is no exception.
Maybe you could use ndimage.morphology.grey_closing, I cant find a code example using it, but the idea is similar to the examples featured in this page: http://www.mmorph.com/pymorph/morph/morph/mmclose.html The "close hole" operator is probably closer to what you intended: http://www.mmorph.com/pymorph/morph/morph/mmclohole.html I am not sure whether this operator is implemented in the free version of pymorph, maybe you should give it a try: http://luispedro.org/pymorph Hope this helps. []s Carlos
Regards, Vincent Schut.
_______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
![](https://secure.gravatar.com/avatar/6194b135cba546afa82516de1537de49.jpg?s=120&d=mm&r=g)
On Mon, Nov 24, 2008 at 10:48 PM, Carlos da Silva Santos <carlos.s.santos@gmail.com> wrote:
On Mon, Nov 24, 2008 at 1:03 PM, Vincent Schut <schut@sarvision.nl> wrote:
If someone comes up with another brillant idea to fill the zero-gaps in my images with values that are in reasonable range of the gap's surroundings, I'd also be very grateful. Keep in mind that the images typically are pretty large, though. 7000x7000 pixels is no exception.
Maybe you could use ndimage.morphology.grey_closing, I cant find a code example using it, but the idea is similar to the examples featured in this page: http://www.mmorph.com/pymorph/morph/morph/mmclose.html
The "close hole" operator is probably closer to what you intended: http://www.mmorph.com/pymorph/morph/morph/mmclohole.html
I am not sure whether this operator is implemented in the free version of pymorph, maybe you should give it a try: http://luispedro.org/pymorph
Hope this helps.
Hi Carlos, the links you provided look very interesting ! Would you be able to answer some further questions ? e.g. the original pymorph (http://www.mmorph.com/pymorph) appears to have a BSD license, did this change for the luispedro.org pymorph ? Is pymorph all 2D (only) ? What data data-types does pymorph support ? float32 ? Thanks, Sebastian Haase
![](https://secure.gravatar.com/avatar/0712dc182847d310baab088228011f47.jpg?s=120&d=mm&r=g)
On Tue, Nov 25, 2008 at 7:13 AM, Sebastian Haase <haase@msg.ucsf.edu> wrote:
On Mon, Nov 24, 2008 at 10:48 PM, Carlos da Silva Santos <carlos.s.santos@gmail.com> wrote:
On Mon, Nov 24, 2008 at 1:03 PM, Vincent Schut <schut@sarvision.nl> wrote:
If someone comes up with another brillant idea to fill the zero-gaps in my images with values that are in reasonable range of the gap's surroundings, I'd also be very grateful. Keep in mind that the images typically are pretty large, though. 7000x7000 pixels is no exception.
Maybe you could use ndimage.morphology.grey_closing, I cant find a code example using it, but the idea is similar to the examples featured in this page: http://www.mmorph.com/pymorph/morph/morph/mmclose.html
The "close hole" operator is probably closer to what you intended: http://www.mmorph.com/pymorph/morph/morph/mmclohole.html
I am not sure whether this operator is implemented in the free version of pymorph, maybe you should give it a try: http://luispedro.org/pymorph
Hope this helps.
Hi Sebastian,
Hi Carlos, the links you provided look very interesting !
Morphology is a quite nice tool, indeed.
Would you be able to answer some further questions ? e.g. the original pymorph (http://www.mmorph.com/pymorph) appears to have a BSD license, did this change for the luispedro.org pymorph ?
According to Luis Pedro, the license is the same: "The license stays BSD..." http://luispedro.org/pymorph
Is pymorph all 2D (only) ? What data data-types does pymorph support ? float32 ?
Actually, I never used pymorph. But quoting from the docs: "The Morphology Toolbox mainly supports four types of images according to their pixel datatypes : binary, unsigned gray scale uint8 and uint16, and signed gray scale int32. Most functions work for 1D, 2D and 3D images." http://www.mmorph.com/pymorph/morph/mmtypes/mmImage.html I believe the morphological operators available in ndimage.morphology work with floating point, can anyone confirm this? But pymorph has much more operators than ndimage.morphology. In my experience, it is not that common to use floating point images in applications involving morphology. Do you have anything specific in mind? Hope this helps, Carlos
Thanks, Sebastian Haase _______________________________________________ SciPy-user mailing list SciPy-user@scipy.org http://projects.scipy.org/mailman/listinfo/scipy-user
participants (3)
-
Carlos da Silva Santos
-
Sebastian Haase
-
Vincent Schut