MATLAB: How to easily calculate the average distance of a point to all other non-zero points in a binary image

binary image processingdistance transform

Hi all,
I have a binary image and I would like a distance transform that gives me the average distance of any given point in the binary image to all other non-zero points.
I there an easy way to do it that doesn't involve looping through all points of the binary image?
Thanks for your help!

Best Answer

Pierre:
You can use pdist2() if you have the Statistics and Machine Learning Toolbox
[y, x] = find(binaryImage);
distances = pdist2([x,y], [x,y])
Related Question