Distance image to objects in matlab

image, image-processing, matlab, object

Solution

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('https://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);

Problem

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?

Original source