Measure width of rectangular object

조회 수: 3 (최근 30일)
Jon Mestal
Jon Mestal 2020년 5월 13일
답변: Image Analyst 2020년 5월 13일
I am trying to automatically measure the width of a rectangular object in an image. This is an MR image of a true rectangular object, but the image can show some imperfections; the example image has some bowing. Ideally, I would measure the width near the center of the object, parallel to the object edges rather than along the image axes. The object should be rougly in the same position and orientaton every time, but may move slightly (a few cm) based on the actual positioning when the object is imaged.
I was able to successfuly measure width using BoundingBox from regionprops, but that does not work well when the image is rotated slightly, and it is measuring form the longest width instead of near the center.
I think I need to fill in the binary image, then rotate and count the pixels, but not sure how to do so or if that is the best approach.

답변 (2개)

darova
darova 2020년 5월 13일
Here is an idea:
  • binarize image
  • imclose image to get solid region
  • use for loop and imline to create several lines. Use createMask property to create mask of the line
  • calculate length of each line
I = I1 & mask;
[ii,jj] = find(I);
d(i) = hypot(ii(end)-ii(1),jj(end)-jj(1));
  • choose shortest line

Image Analyst
Image Analyst 2020년 5월 13일
I'd probably threshold, then scan the top and bottom to get the top line and bottom line, which may be slightly tilted. Then call fitPolynomialRansac() or polyfit() to get the angle. Then rotate with imrotate to level/straighten the image and then take a profile right through the center. Then look for full width, half max of the profile. Let us know if you can't figure it out.

카테고리

Help CenterFile Exchange에서 White에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by