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

조회 수: 2 (최근 30일)
sana3 sal
sana3 sal 2018년 5월 2일
댓글: Walter Roberson 2020년 6월 13일
Hello, I need to find the height and width of the following white object in this image.

답변 (1개)

Alfonso
Alfonso 2018년 5월 2일
편집: Alfonso 2018년 5월 2일
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
Alfonso
Alfonso 2018년 5월 2일
Okay, glad you were finally able to solve it.
Walter Roberson
Walter Roberson 2020년 6월 13일
can i get ur solution please?

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

Community Treasure Hunt

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

Start Hunting!

Translated by