
Image Analysis - Inside Bounding Circle
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Conor O'Keeffe
am 29 Mai 2021
Kommentiert: Conor O'Keeffe
am 30 Mai 2021
Hi
I have this binary image and am wondering is there a function to calculate the maximum circle fully on the inside of a shape similar to below

0 Kommentare
Akzeptierte Antwort
Image Analyst
am 30 Mai 2021
Compute the distance transform with bwdist(). The max value is the largest radius that a circle could fit inside the blob. Use bwdist(~mask) instead of bwdist(mask).
Full demo below:
clc; % Clear command window.
fprintf('Running %s.m ...\n', mfilename);
clear; % Delete all variables.
close all; % Close all figure windows except those created by imtool.
workspace; % Make sure the workspace panel is showing.
peaksImage = peaks(300);
subplot(2, 2, 1);
imshow(peaksImage, []);
title('Peaks Image', 'FontSize', 16)
impixelinfo
mask = peaksImage > 3;
subplot(2, 2, 2);
imshow(mask)
title('Mask Image', 'FontSize', 16)
edtImage = bwdist(~mask);
subplot(2, 2, 3);
imshow(edtImage, []);
title('EDT Image', 'FontSize', 16)
labeledImage = bwlabel(mask);
% Find radii of each blob
props = regionprops(mask, edtImage, 'MaxIntensity')
allRadii = [props.MaxIntensity]
subplot(2, 2, 2);
for k = 1 : length(props)
% Find the max of the edt Image. It may not be at the centroid!
thisBlob = ismember(labeledImage, k);
thisPeaks = peaksImage .* thisBlob;
[r, c] = find(thisPeaks == max(thisPeaks(:)));
x = c(1);
y = r(1);
xy(k, 1) = x;
xy(k, 2) = y;
str = sprintf('Radius = %.2f', allRadii(k));
text(x, y, str, 'FontSize', 12, 'Color', 'y');
end
viscircles(xy, allRadii);
fprintf('Done running %s.m\n', mfilename);

Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!