How to find out the points collection which has the same minimum distance to the boundary of a closed image

1 view (last 30 days)
Dear all,
I get stuck by a simple mathmatic problem:
I have a closed and irregular image. To make it simple, I put their coordinate here (10,30) (20,40) (50,30) (50,20) (40,20) (30,10) (20,10) (10,20)
Now I want to find out the points which have the same minimum distance (here 5 pixel) to the boundary of this image. But I have no idea how to do it. Is there any simple way to do it? Thank you.

Accepted Answer

Image Analyst
Image Analyst on 4 Aug 2019
Try imdilate() to expand it out 5 pixels.
xy = [10,30; 20,40; 50,30; 50,20; 40,20; 30,10; 20,10; 10,20]
x = xy(:, 1);
y = xy(:, 2);
plot(x, y, 'b.', 'MarkerSize', 50);
grid on;
rows = 100
columns = 100
mask = poly2mask(x, y, rows, columns);
subplot(2, 2, 1);
imshow(mask, 'InitialMagnification', 1800);
axis('on', 'image');
% Dilate by 5 pixels.
se = strel('disk', 5, 0);
mask5 = imdilate(mask, se);
subplot(2, 2, 2);
imshow(mask5, 'InitialMagnification', 1800);
axis('on', 'image');
perim=bwperim(mask5);
subplot(2, 2, 3);
imshow(perim, 'InitialMagnification', 1800);
axis('on', 'image');
impixelinfo;
0000 Screenshot.png

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!