MATLAB Answers

How do i find the coordinates of a boundary

1 view (last 30 days)
Sidney Todd
Sidney Todd on 26 Jul 2021
Edited: Matt J on 26 Jul 2021
Hi, I am needing to find the length of only the line circled below. I am thinking if i can get the coorindates of the four corners of the boundary i would be able to subtract away the unwanted sides from the perimeter of the boundary, thus giving me the distance desired.
I = imread('ss3.png');
% imshow(I)
hold on
% imshow(imfill(BW1,'holes'))
mask = imclose(BW1, true(7));
mask = conv2(double(mask), ones(3), 'same') > 3.1; % Adjust number to control the size of the new mask.
mask = imfill(mask, 'holes'); % Remove any interior holes
% imshow(mask,'InitialMagnification', 'fit')
%Auto crop image using set points----------------------------------------
I2 = imcrop(mask,[407.51 0.51 83.98 1037.98]);
imshow(I2,'InitialMagnification', 'fit')
% 407.51 0.51 83.98 1037.98
I3 = bwareafilt(I2,[40 100000]);
% imshow(I3)
%boundary outline and trace -----------------------------------------
[B,L] = bwboundaries(I3,'noholes');
imshow(label2rgb(L, @gray, [0 0 0]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 0.5)
% numPixels(k) = size(boundary, 1)
  1 Comment
Matt J
Matt J on 26 Jul 2021
You need to attach ss3.png for us to run the code.

Sign in to comment.

Answers (1)

Matt J
Matt J on 26 Jul 2021
Edited: Matt J on 26 Jul 2021
How about simply,
I=boundary(:,1); J=boundary(:,2);
corner1 = [1, max(J(I==1))]; %row/column coordinates
corner2 = [m, max(J(I==m))];

Community Treasure Hunt

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

Start Hunting!

Translated by