Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello all,

I would like to start off with stating that i'm not a professional programmer, and often work from examples I find on sites like Code Project. It might be that i'm approaching this from the wrong angle, so please comment as you see fit.

Background
For some analysis purpose I need to calculate the ratio of black vs white pixels of a processed bitmap image. However, not the entire bitmap is of interest. The region of interest varies, therefore I need a photoshop kind of way of selecting (and excluding) different portions of the image.

Approach
The processed bitmap is loaded in a PictureBox derived object and selections are catched through mouse events. The selections are stored in o.a. a rectangle list, which is used to assemble a Graphics.Region object through union and exclude. The region and shapes are visualised by drawing directly into the overrided OnPaint event of the PictureBox object.

So far, so good.
I'm able to access separate pixels in a bitmap by entering unsafe code or through the GetPixel() method and I have a region that represents my pixels of interest. However, I cannot find a way to filter out the pixels that correspond to the selected region.

Is there any way of iterating only through the pixels in my bitmap that correspond with the region?

Any help is greatly appreciated.

Thanks.
Posted
Comments
Trak4Net 23-Aug-13 14:47pm    
You may want to check this out.
http://bobpowell.net/region_from_bitmap.aspx

1 solution

For anyone interested..

I solved this by creating a "Mask" bitmap and filling it white and the region with black. I could then iterate the mask bitmap pixels to get pixels of interest. Without filling it completely white pixels are somehow not read correctly.

The solution was actually quite simple. This proves that stepping back when you are in it for many straight hours really does help :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900