How do i find the coordinates of a boundary

조회 수: 7 (최근 30일)
Sidney Todd
Sidney Todd 2021년 7월 26일
편집: Matt J 2021년 7월 26일
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
J=rgb2gray(I);
BW1=edge(J,'sobel',.009);
% 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)
end
% numPixels(k) = size(boundary, 1)
  댓글 수: 1
Matt J
Matt J 2021년 7월 26일
편집: Matt J 2021년 7월 26일
You need to attach ss3.png for us to run the code.

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2021년 7월 26일
편집: Matt J 2021년 7월 26일
How about simply,
[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];

제품

Community Treasure Hunt

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

Start Hunting!

Translated by