
Image Analysis - Inside Bounding Circle
12 views (last 30 days)
Show older comments
Conor O'Keeffe
on 29 May 2021
Commented: Conor O'Keeffe
on 30 May 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 Comments
Accepted Answer
Image Analyst
on 30 May 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);

See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!