Filter löschen
Filter löschen

Finding the width of a blob perpendicular to the major axis

4 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

DGM
DGM am 9 Dez. 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 Kommentare
Muhammad Syahmeer
Muhammad Syahmeer am 9 Dez. 2022
Bearbeitet: Muhammad Syahmeer am 9 Dez. 2022
Thanks for that @Image Analyst. Yup on my way to get the latest version installed.
I used the “orientation” option from regionprops like you suggested and subtracted it with 90 degrees to get the image vertical. Though wasn’t sure why 90 is the magic number but it seems to do the trick..
Image Analyst
Image Analyst am 10 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 8 Dez. 2022
  3 Kommentare
Image Analyst
Image Analyst am 9 Dez. 2022
Then use regionprops() to get the 'Image' and the 'Orientation'. Then rotate the blob so that it's vertical and then scan down line by line using find() or nnz() to count the white pixels on each line. I think you can do it. Something like
props = regionprops(mask, 'Image', 'Orientation');
for k = 1 : numel(props)
thisImage = props(k).Image;
thisImage = imrotate(thisImage, props(k).Orientation);
[rows, columns] = size(thisImage);
widths = nan(rows, 1), 1);
for row = 1 : rows
widths(row) = nnz(thisImage(row, :));
end
end
If that's not right, I'm sure you can debug it.
Muhammad Syahmeer
Muhammad Syahmeer am 9 Dez. 2022
Thanks so much for the code Image Analyst. That's really helpful!

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by