number of pixels inside circles of different radius on a single picture

i wanted to draw circles with different radius on a picture and count number of pixels inside each circle coverage..

 Accepted Answer

A similar demo of mine is attached.

10 Comments

This is the image file. I have to find how many pixels are there in circle 1 , circle 2 ..... I have to find the image center and with increasing radius I have to draw circles say three or four circles. find number of pixels inside each circle. It is a binary image. Thank you image analyst
Well, you'd use the FAQ like I said. Is this homework - it looks a lot like it?
The FAQ says
% Create a logical image of a circle with specified
% diameter, center, and image size.
% First create the image.
imageSizeX = 640;
imageSizeY = 480;
[columnsInImage rowsInImage] = meshgrid(1:imageSizeX, 1:imageSizeY);
% Next create the circle in the image.
centerX = 320;
centerY = 240;
radius = 100;
circlePixels = (rowsInImage - centerY).^2 ...
+ (columnsInImage - centerX).^2 <= radius.^2;
% circlePixels is a 2D "logical" array.
So the radius above would be the radius of your yellow circles. Then you'd just use that as a mask against your inverted image, and sum
binaryImage = yourGrayImage < 128; % Find black scribbles.
% Mask it
binaryImage(~circlePixels) = false;
% Get area of black scribbles within the circle
numberBlackPixels = sum(binaryImage(:))
You can put that in a loop or function to do it for the various radii that you need. If that solves your problem, please mark it as Accepted. Thanks in advance.
binaryImage(~circlePixels) = false; i get error on this line Attempt to grow array along ambiguous dimension.
Attach your script and original image if you want us to look at it and try it.
First i have to find the center(x,y) of the png image. using the center(x,y) of the png image file, i have draw a several circles with increasing radius until it covers the entire png image. the center of the circle should be at center of the png image. after drawing the circles, i have to count number of pixels in each circle. please help me in this regard.thanks in advance.
Well, I did a lot more for you than I usually do for people so you lucked out. The m-file is attached below the image that it produces.
Thank you very much.... today i got hope that i will definitely complete my work. i started working on the rest of the project. will definitely tell you the result. thank you.
thank you. in the pic below,
the circle generation should stop with J and L . the circle should stop when it encounters the picture edges. also how to draw triangles instead of circle? thank you.
You won't know if there are any detached blobs unless you cover the whole image. What if there was a white spot way on the right side just before the right edge of the image? If you had stopped the first time the circle added zero pixels, then you never would get that blob, so the algorithm would not be robust.
For triangles, use poly2mask() to define the binary mask. I'm sure you can figure it out after looking at the help for poly2mask.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!