question

ChrisSpect-2258 avatar image
0 Votes"
ChrisSpect-2258 asked cheong00 edited

C# Calculating area of circles in black-white image

I have a question about image processing. I get an output similar to the picture in the example. I want to calculate the area of the white areas here. I want to sort the flats by size. How can I calculate areas? ( No libiary)

I have questions about image processing. Given an area with multiple non-intersecting circles (see image link), how can I obtains a list of circles sorted by size?

Specifically:

How can I identify circle locations?
How can I identify circle sizes?
How can I sort the list of circles identified?
I need a programmatic solution in C#, without the use of 3rd-party libraries.

EXAMPLE IMAGE
DhjJD.jpg

Thank YOU.


dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cheong00 avatar image
0 Votes"
cheong00 answered cheong00 edited

The following is how I would attack this problem. Not optimized approach.

From top to bottom, scan for pixels with white color and "pixel above in black".

If the pixel is surrounded by black pixels, then these are "1 pixel circles", and you can put it into array.

If the pixel do not have consecutive white pixel at the side, this is the "north-most pixel".

If the multiple pixels on the row are white, the middle one is "north-most pixel".

Once "north-most pixel" is found, scan directly below it for the first pixel that is white and "pixel below is black", that would be "south-most pixel".

The middle point of "north-most pixel" and "south-most pixel" is the center of the circle. The distance between center and either point is the radius. Now put it into array.

Once you found all the "circles" you can proceed to sort it and calculate area, etc.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
0 Votes"
Castorix31 answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered

I'm a little curious why you don't want to use other packages.

When I used the code of Wolfgang Radl in this link for testing, it basically worked, but each circle was recognized as two, which may be caused by severe jagged edges.

I added a line to his code to output the area:

             for (int i = 0; i < contours.Size; i++)
             {
                 Ellipse ellipse = new Ellipse(CvInvoke.FitEllipse(contours[i]));
                 result.Draw(ellipse, new Bgr(Color.Red), 1);
    
                 Console.WriteLine(ellipse.RotatedRect.Center.X * ellipse.RotatedRect.Center.Y *Math.PI);
             }

Of course, if it is for learning purposes, it makes sense not to use other packages but to do it ourselves.


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.