from scipy.ndimage.morphology import distance_transform_edt as distTransform
distMatrix = distTransform(imgBin, sampling=[0,1])
Hi Eduardo,
What you are looking for is called a distance transform. We have one function (
skimage.morphology.medial_
) which can be coerced into returning a distance transform with an optional argument, but I recommend you look to SciPy’s NDImage module (axis 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_
and then either mask or threshold the result.transform_edt 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,
JoshOn Tuesday, July 15, 2014 6:28:21 AM UTC-5, Eduardo Henrique Arnold wrote:
Hi there.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?Thanks.