How do i find the coordinates of a boundary

4 visualizzazioni (ultimi 30 giorni)
Sidney Todd
Sidney Todd il 26 Lug 2021
Modificato: Matt J il 26 Lug 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
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 Commento
Matt J
Matt J il 26 Lug 2021
Modificato: Matt J il 26 Lug 2021
You need to attach ss3.png for us to run the code.

Accedi per commentare.

Risposte (1)

Matt J
Matt J il 26 Lug 2021
Modificato: Matt J il 26 Lug 2021
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];

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by