Finding the width of a blob perpendicular to the major axis

9 views (last 30 days)
Hi!
I've got a binarised blob here with a major axis plotted inside the blob. I am looking to find a series of width, perpendicular to the major axis plotted in the blob. Basically, I'm looking to find the distance of a line that has a starting coordinate from the left side of boundary, intersects with the coordinate of the major axis and ending with a coordinate from the right side of the boundary. The image below shows what I'm looking for. Apologies if my question isn't clear enough.
Basically I'm looking to measure the distance of the black arrows. Attached is the code I've used to draw the magenta coloured line (major axis) of the blob.
Really appreciate if someone can help me to solve this problem.
Cheers,
How

Accepted Answer

DGM
DGM on 9 Dec 2022
Unless you have some existing means to find the major axis, I'd still use feret properties to rotate the object. The rest of this really isn't much different than IA's answer, though.
% cropped screenshot with annotations removed
mask = imread('image.png');
mask = rgb2gray(mask)>128;
% pick the largest blob if desired
% otherwise, the script processes all blobs
mask = bwareafilt(mask,1);
% get properties
S = regionprops(mask,'minferetproperties','image');
th = vertcat(S.MinFeretAngle)-180;
% preallocate outputs
blobimgs = cell(numel(S),1);
blobwidth = cell(numel(S),1);
for k = 1:numel(S)
% rotate blob image
thisblob = imrotate(S(k).Image,th(k));
% close-crop blob image
yrange = any(thisblob,2);
thisblob = thisblob(yrange,:);
xrange = any(thisblob,1);
thisblob = thisblob(:,xrange);
% throw results into output arrays
blobimgs{k} = thisblob;
blobwidth{k} = sum(thisblob,2);
end
% view the blob and width profile
f = 1; % select a blob
subplot(2,1,1)
imshow(blobimgs{f})
subplot(2,1,2)
plot(blobwidth{f})
  4 Comments
Image Analyst
Image Analyst on 10 Dec 2022
@Muhammad Syahmeer With regionprops the Orientation value is in degrees, ranging from -90 degrees to 90 degrees. If you want a different range, you'd have to add the offset. For example to go from -90 to +90 to 0 to 180, you'd have to add 90 to the Orientation value.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 8 Dec 2022
  3 Comments
Muhammad Syahmeer
Muhammad Syahmeer on 9 Dec 2022
Thanks so much for the code Image Analyst. That's really helpful!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!