# Determine the percentage of black pixels within a circle

6 views (last 30 days)
Vance Blake on 18 May 2020
Edited: Vance Blake on 18 May 2020
Hello, I am trying to determine the total number of pixels within the blue circle (radius = 80 dimensionless units) and the percentage of them that are black. I have multiple files that I would like to analyze, and I wanted to code a way to read in each picture in the folder one by one and then store each image name with its coresponding percentage of black pixels in a matrix. The image sizes are not standardized since they were created using the snipping tool
I have tried to implement the methods in shown in the solution links but each one is more piece of what I need and Im struggling to put them all together. Any help would be greatly appreciated.
pathname = uigetdir;
allfiles = dir(fullfile(pathname,'*.png'));
image_percent = [];
for i=1:size(allfiles,1)
image_percent=[image_percent; x]; % storage
end
Vance Blake on 18 May 2020
Edited: Vance Blake on 18 May 2020
Hi darova the center of the blue circle is the coordinates [0,0] on the plot. I don't know how that translates to the pixels of the png file itself though

Image Analyst on 18 May 2020
Please post the original image, not a screenshot. Is the actual image a real gray scale image, or is it that RGB computer graphics diagram? Then, how are you getting the black and white (binary, logical) image from the original image?
Anyway, once you have the image segmented so that you have a mask with only black pixels and white pixels, then you can use sum() and nnz() to do the count. Assume circleMask is the mask of the overall, outer circle, and mask is your segmented, binary image of stuff inside you're interested in, then
blackAreaFraction = 1 - whiteAreaFraction
##### 2 CommentsShowHide 1 older comment
John Chuck on 18 May 2020
Hi this is VB I made a new account to post the original image files.

### Categories

Find more on Images in Help Center and File Exchange

R2019a

### Community Treasure Hunt

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

Start Hunting!