MATLAB: How to crop circular area and measure the ratio of black and white from the binarized image

image processing

Hello, I have to do a image processing and analysis of X-ray Diffraction Image of metal sample.
As you may see, I made it to binarizing the Image with command from 'image processing toolbox' provided by Matlab.
However, I have to find out the percentage of black area inside the circle for 20 photos that has same frames.
Therefore, I think I have to crop the circlular center of the image and calculate the pixel using bwarea function. But having trouble cropping the center part.
Is there any way to crop the same circular area automatically and calculate the ratio of black and white area?

Best Answer

Measure the ratio of black and white from the binarized image?
Here bw_image is a input binary image.
[rows colm]=size(bw_image);
white_pixels=sum(bw_image(:));
black_pixels=~bw_image;
black_pixels=sum(black_pixels(:));
result=bwareafilt(~bw_image,1,'Largest');
outer_black=sum(result(:));
% Area with respect to circle only
black_pixels_area=(black_pixels-outer_black)/((rows*colm)-outer_black);
fprintf('The Percentage of black pixels covered area is %.2f ',black_pixels_area);
fprintf('\n The ratio black/white is %.2f',black_pixels/white_pixels);