# How do i find the coordinates of a boundary

1 view (last 30 days)
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.
% imshow(I)
hold on
J=rgb2gray(I);
BW1=edge(J,'sobel',.009);
% imshow(imfill(BW1,'holes'))
%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)
end
% numPixels(k) = size(boundary, 1)
Matt J on 26 Jul 2021
You need to attach ss3.png for us to run the code.

Matt J on 26 Jul 2021
Edited: Matt J on 26 Jul 2021
[m,n]=size(Image);
I=boundary(:,1); J=boundary(:,2);
corner1 = [1, max(J(I==1))]; %row/column coordinates
corner2 = [m, max(J(I==m))];
corner3=[m,1];
corner4=[1,1];