Finding the width of a blob perpendicular to the major axis
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Muhammad Syahmeer
il 8 Dic 2022
Commentato: Image Analyst
il 10 Dic 2022
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
0 Commenti
Risposta accettata
DGM
il 9 Dic 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 Commenti
Image Analyst
il 10 Dic 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.
Più risposte (1)
Image Analyst
il 8 Dic 2022
Use bwferet
3 Commenti
Image Analyst
il 9 Dic 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.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
