Image Analysis - Inside Bounding Circle

조회 수: 13 (최근 30일)
Conor O'Keeffe
Conor O'Keeffe 2021년 5월 29일
댓글: Conor O'Keeffe 2021년 5월 30일
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

채택된 답변

Image Analyst
Image Analyst 2021년 5월 30일
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);

추가 답변 (1개)

Matt J
Matt J 2021년 5월 29일
편집: Matt J 2021년 5월 29일
Use bwboundaries() to get the boundary coordinates and use incircle() from here:

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by