Reputation: 1107
What is the best c# algorithm to calculate number of not black pixels in the closed area? I have for example this image. I click the mouse in the red button position. I would like to know how much not black pixels (in this example white pixels) are in the closed area (The square and rectangle should not be calculated)?
Upvotes: 0
Views: 193
Reputation: 1151
What you need is very similar to a fill algorithm, the only difference is that instead of changing pixel colours you will count them. Search for an implementation of a fill algorithm.
Upvotes: 1
Reputation: 9407
You will need emguCV/C# to find a contour(blob) in your image. A function provided by that library that allow you to get all the contours on your image:
var contours = YourImage.FindContours(CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, RETR_TYPE.CV_RETR_EXTERNAL);
Then, you will need to build your own algorithm to check which contour does your mouse coordinates fall in. Your sample image, has only three contours (Square, Rectangle and the rest). You will need to iterate those three and test your mouse coordinates against each of their coordinates taking into consideration their area, shape.. etc.
Upvotes: 1