简体   繁体   中英

Distance image to objects in matlab

I have an image that contains some points (or objects). I want to create another image base on this image that shows the distance from these objects. For example, this new image should has the maximum value at the object locations. Is there any solution in matlab?

在此输入图像描述

You can use bwdist for this, which calculates the distance of each pixel from the signal in a binary image.

%# 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);

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM