Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

selective bwdist()

Asked by leila on 13 Dec 2011

I have a binary 3D image that consists of a 3D object with "1"-valued pixels and background with "0"-valued pixels. I want to compute the euclidean distance of "some" background pixels to the object.

I found that the MATLAB function bwdist() can compute the distance of "all" of the background pixels to the nearest object pixel for each point.

Is there any MATLAB function or other way to compute the distance of an small subset of background pixels to the nearest non-zero pixel efficiently?

Your help is greatly appreciated.

2 Comments

Sven on 13 Dec 2011

Which version of MATLAB do you have? In 2011b, there was an update which might help you quite a bit:

http://blogs.mathworks.com/steve/2011/12/13/exploring-shortest-paths-part-5/

Sean de Wolski on 13 Dec 2011

How conveniently timed on Steve's part!

leila

3 Answers

Answer by Alex Taylor on 14 Dec 2011

You all have seen Steve's blog post, so you know the answer. But, for anyone who comes to this post with a similar question, we added two new functions to the Image Processing Toolbox for calculating constrained distance problems in R2011b.

bwdistgeodesic: http://www.mathworks.com/help/toolbox/images/ref/bwdistgeodesic.html

graydist: http://www.mathworks.com/help/toolbox/images/ref/graydist.html

These functions solve the geodesic distance and gray-weighted distance transforms.

0 Comments

Alex Taylor
Answer by Image Analyst on 14 Dec 2011

How about just using Pythagorean theorem? If you know the coordinates of all the pixels in your 3D binary object (which you can find out), then just calculate it. If you have one reference point, and say a million other points, it's just a million calculations - shouldn't take too long though I'm not sure whether it will be faster or slower than bwdist.

0 Comments

Image Analyst
Answer by leila on 14 Dec 2011

Thanks all for your help, Unfortunately I found that the aspect ratio of the image pixels is not [1:1:1],I guess that the bwdist() and bwdistgeodesic() do not support this case. Is there any way to solve this problem?

0 Comments

leila

Contact us