Image Analysis - Inside Bounding Circle

12 visualizaciones (últimos 30 días)
Conor O'Keeffe
Conor O'Keeffe el 29 de Mayo de 2021
Comentada: Conor O'Keeffe el 30 de Mayo de 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

Respuesta aceptada

Image Analyst
Image Analyst el 30 de Mayo de 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);

Más respuestas (1)

Matt J
Matt J el 29 de Mayo de 2021
Editada: Matt J el 29 de Mayo de 2021
Use bwboundaries() to get the boundary coordinates and use incircle() from here:

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by