ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

color area

<< < (3/4) > >>

Renegade:
thank you very much!

but, what about photos, where similar colors form an area or multiple areas, which must be counted?

maybe we can input many color codes, but again, how can we determine similar color codes in a photo?

it works exceptionally well with vector graphics, but with raster images, it seems bothersome (like many other stuff with rasters)
-kalos (February 10, 2012, 07:16 AM)
--- End quote ---


It counts all the pixels that are a specific colour, so it doesn't matter what kind of picture it is. I just picked that picture because it's fun. :D

It actually relies on a raster image. No matter what kind of image you use, it will be rasterized. (See below.)

Here's another example screenshot:

color area

Here's the code:


--- Code: C# ---private string SomeOtherMethod(string imgPath, Color compareColor)        {            // http://stackoverflow.com/questions/6020406/travel-through-pixels-in-bmp            Bitmap bmp = new Bitmap(imgPath);            int count = 0;            int total = 0;             for (int ii = 0; ii < bmp.Width; ii++)            {                for (int jj = 0; jj < bmp.Height; jj++)                {                    Color pixelColor = bmp.GetPixel(ii, jj);                                        // do stuff with pixelColor                    if (pixelColor.R == compareColor.R && pixelColor.G == compareColor.G && pixelColor.B == compareColor.B)                    {                        count++;                    }                    total++;                }            }             decimal percent = (Convert.ToDecimal(count) / Convert.ToDecimal(total)) * 100;             return "Counted " + count.ToString() + " pixels of " + total.ToString() + " (" + percent.ToString() + "%)";        }

If you wanted to check for multiple colors, that's easily done by adding in more color pickers, etc. etc.

If you want to check for "similar" colours, this is the comparison:

pixelColor.R == compareColor.R && pixelColor.G == compareColor.G && pixelColor.B == compareColor.B

That needs to be adjusted to whatever you consider "similar".

e.g.


--- Code: C# ---(pixelColor.R <= compareColor.R + 5) && (pixelColor.R >= compareColor.R - 5) && (pixelColor.G <= compareColor.G + 5) && (pixelColor.G >= compareColor.G - 5) && (pixelColor.B <= compareColor.B + 5) && (pixelColor.B >= compareColor.B - 5)
Or whatever.

However, you really need to know some colour theory and the math behind it to come up with something that will work the way you want it to. The above example is just a very simple example.



Renegade:
Here's a new version:

color area

PixelCounter2.zip (81.75 kB - downloaded 168 times.)

It lets you look for 3 colours and define a variance as described above. Full source is there as well so anyone can tweak it if they need.

kalos:
thanks it works wonders!

is there a simple way to quantify the pixels of these skin moles?

http://www.gulfmd.com/images/skinchart.gif

also, how will I know that all the pixels are selected? a line that will mark the area would be helpful

IainB:
@Renegade: I like that new SOPA flag...  

tomos:
is there a simple way to quantify the pixels of these skin moles?

http://www.gulfmd.com/images/skinchart.gif

also, how will I know that all the pixels are selected? a line that will mark the area would be helpful
-kalos (February 11, 2012, 05:38 AM)
--- End quote ---

I suspect you need photoshop (or equivalent, Gimp, etc.) for what you want. Each of those moles has probably dozens of colours - so trying to select by colour, you will need to vary the "tolerance" of the selection - a bit like making a search "fuzzy". (As I described above.)

In fact I wonder if selecting automatically (using colour) is even fully possible, as all moles have highlit areas which will not be selected when you select by the main colour...

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version