1

Why can I not see the inscribed circle properly in the code attached? And how can I also find the circumscribed circle radius?

% read grayscale image from URL
url='https://i.pcmag.com/imagery/reviews/00uaCVfzQ4Gsuhmh85WvT3x-4.fit_scale.size_1028x578.v_1569481686.jpg';
Image = rgb2gray(imread(url)); % 
Image = imcomplement(Image);
[rows,columns] = size(Image);

% determine contours
BW = imbinarize(Image);
[B,L] = bwboundaries(BW,'noholes');
k = 1;
b = B{k};
yBoundary = b(:,2);
xBoundary = b(:,1);

% plot image
imshow(Image);
hold on
% plot contours (in green)
plot(yBoundary, xBoundary, 'g', 'linewidth', 2);


stat = regionprops(Image,'Centroid');
centroidObject = stat(k).Centroid;
xCentre = centroidObject(:,2);
yCentre = centroidObject(:,1);
centers = [xCentre yCentre];

pgon1 = polyshape(yBoundary, xBoundary);  
mask = poly2mask(yBoundary, xBoundary, rows, columns);
edtImage = bwdist(mask);
inscribedmaxRadius = max(edtImage(:));

% plot cirvle (in blue)
viscircles(centers, inscribedmaxRadius, 'Color','b');

resulting figure

max
  • 3,915
  • 2
  • 9
  • 25
alirazi
  • 159
  • 8

0 Answers0