Hi Josh, 

I appreciate your reply, it was very helpful. Looking at the Scipy docs, I've realized I could use the sampling argument to get only vertical distances. However this does not seem to work, it shows me an empty matrix no matter what. If I invert the order of the sampling list, [1,0], it shows me some line strips, but not the result I was expecting. I cannot figure out what is wrong or if this method is not supposed be used like this.

from scipy.ndimage.morphology import distance_transform_edt as distTransform
distMatrix = distTransform(imgBin, sampling=[0,1])

BTW, did you format your code in the last post manually? I could not find a way of doing it here. 

Thanks again!

On Tuesday, July 15, 2014 1:03:04 PM UTC+1, Josh Warner wrote:

Hi Eduardo,

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:

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.