MATLAB Answers

0

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

Asked by Dingcheng Zhu on 3 Aug 2019
Latest activity Commented on by Image Analyst
on 4 Aug 2019
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.

  0 Comments

Sign in to comment.

1 Answer

Answer by Image Analyst
on 4 Aug 2019
 Accepted Answer

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

  2 Comments

Thank you for your answer. What if I want to shrink the image? Which function should I use? The shirnkage is what I want.

Sign in to comment.