How to evaluate the height and width of an object in BW image

Antworten (1)

Alfonso
Alfonso am 2 Mai 2018
Bearbeitet: Alfonso am 2 Mai 2018
Try this
% Get boundary
bw = bwboundaries(binary_img);
bw = bw{1};
bw_x = bw(:, 2); %columns
bw_y = bw(:, 1); %rows
% height and width
leftCol = min(bw_x);
rightCol = max(bw_x);
top = max(bw_y);
bottom = min(bw_y);
width = rightCol - leftCol + 1;
height = top - bottom + 1;
% Crop the img
img_cropped = imcrop(binary_img, [leftCol, bottom, width, height]);
imshow(img_cropped)
Just change binary_img by the name of the one you posted.

3 Kommentare

sana3 sal
sana3 sal am 2 Mai 2018
Bearbeitet: Walter Roberson am 13 Jun. 2020
Thank you for your kind effort :) but i have found what i need here: https://www.mathworks.com/matlabcentral/answers/351818-how-do-i-use-image-processing-to-determine-the-length-of-an-object-in-an-image Thank you again and again ♥
Okay, glad you were finally able to solve it.
can i get ur solution please?

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 2 Mai 2018

Kommentiert:

am 13 Jun. 2020

Community Treasure Hunt

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

Start Hunting!

Translated by