Distance image to objects in matlab
我的图像包含一些点(或对象)。我想在此图像的基础上创建另一个图像,以显示与这些对象的距离。例如,此新图像应在对象位置处具有最大值。 Matlab中有什么解决方案吗?
您可以使用
1 2 3 4 5 6 7 8 9 10 11 | %# read the image img = imread('http://i.stack.imgur.com/Hc7ay.png'); %# convert to grayscale gs = im2bw(img); %# segment the objects sig = gs~=1; %# remove the border sig = sig(5:end-4,5:end-4); %# calculate the distance distFromObjects = -bwdist(sig); |