MATLAB: Identifying the circle that fits the outer white pixels in a binary image (or make external mask)

image analysis

Hi all,
I want to process a series of images similar to the attached one in order to measure their porosities: V_pores / V_total. For my case, in a 2D context, V_total is the surface of circle containing all pores. It is important to know that the radius and center of the circle changes, and also many circular shapes can be identified in between, however, I am only interested, at this moment, in measuring the general surface of the circle (Vt).
Alernatively, I would be interested in applying a mask to the image. But it seems to be more difficult.
Any help would be appreciated. Many thanks.

Best Answer

I = imread("SampleXRmorph.PNG");
[y,x] = find(I) ;
% Get center of cricle
C = [mean(x) mean(y)] ;
% GEt raidus
d = sqrt((C(1)-x).^2+(C(2)-y).^2) ;
R = max(d) ;
% plot circle
th = linspace(0,2*pi) ;
xc = C(1)+R*cos(th) ;
yc = C(2)+R*sin(th) ;
%
imshow(I)
hold on
plot(xc,yc,'r')