What you are looking for is called a *distance transform*. We have one function (skimage.morphology.medial_axis) which can be coerced into returning a distance transform with an optional argument, but I recommend you look to SciPy’s NDImage module (scipy.ndimage) for a more general set of transforms. We haven’t reimplemented these since we depend on SciPy.
Specifically, for your purposes, you will likely want to use scipy.ndimage.distance_transform_edt and then either mask or threshold the result.
import scipy.ndimage as ndi # Load your data here as `image`
dist = ndi.distance_transform_edt(image) dist[dist < T] = 0 # Could also operate on the original image with image[dist < T] = something # Optional, uncomment if you want a binary result# dist[dist >= T] = 1
Hope that helps, Josh
On Tuesday, July 15, 2014 6:28:21 AM UTC-5, Eduardo Henrique Arnold wrote:
I need to implement a filter that takes each white pixel in a binary image and look for the distance between the top and bottom closest background (black) pixels. If this distance is smaller than a threshold T all the pixels between this two background pixels should be set to 0 (background pixels).
I know I could iterate through all the image columns and pixels, but I think this would yield a poor performance. Is there any suggestion of how I could develop this filter in a more efficient way?