Welcome Guest.   Make a donation to an author on the site October 22, 2014, 08:40:15 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2010! Download 24 custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: color area  (Read 2940 times)
kalos
Member
**
Posts: 1,069

View Profile Give some DonationCredits to this forum member
« on: February 08, 2012, 08:38:47 AM »

hello!

in a photo, I want to calculate the area that a specific color occupies

how can I do that?

thanks!
Logged
Renegade
Charter Member
***
Posts: 11,627



Tell me something you don't know...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #1 on: February 08, 2012, 08:44:55 AM »

I don't know any software that can do that. The only way I know how to do it is in code. Basically, you just get the bitmap, iterate over each pixel and count if it is the colour you want. Probably not very useful for you... Hopefully someone knows some software that can do it easier.
Logged

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker
kalos
Member
**
Posts: 1,069

View Profile Give some DonationCredits to this forum member
« Reply #2 on: February 08, 2012, 09:13:32 AM »

percentage of pixels would be nice too
Logged
flamerz
Supporting Member
**
Posts: 112



View Profile Give some DonationCredits to this forum member
« Reply #3 on: February 08, 2012, 09:56:53 AM »

the pixels are in a shape or placed randomly?
Logged
tomos
Charter Member
***
Posts: 8,607



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #4 on: February 08, 2012, 11:57:08 AM »

With my ancient version of photoshop, I can select pixels of similar, or the same colour.
If I set it to same colour (Tolerance=0) it mostly only selects a handful of pixels.

I presume that's not what you want - but I'm not sure.
Maybe you could explain a bit more?
Logged

Tom
kalos
Member
**
Posts: 1,069

View Profile Give some DonationCredits to this forum member
« Reply #5 on: February 08, 2012, 12:24:52 PM »

the pixels are in a shape or placed randomly?

concentrated in few big areas in the photo

With my ancient version of photoshop, I can select pixels of similar, or the same colour.
If I set it to same colour (Tolerance=0) it mostly only selects a handful of pixels.

I presume that's not what you want - but I'm not sure.
Maybe you could explain a bit more?

this is what I want exactly, but I need to quantify this selection as a percentage of the whole photo or as an absolute square inches etc

or maybe I can create another photo with only this selection of pixels and then count the pixels?

« Last Edit: February 08, 2012, 01:08:20 PM by kalos » Logged
tomos
Charter Member
***
Posts: 8,607



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #6 on: February 08, 2012, 03:18:40 PM »

With my ancient version of photoshop, I can select pixels of similar, or the same colour.
If I set it to same colour (Tolerance=0) it mostly only selects a handful of pixels.

I presume that's not what you want - but I'm not sure.
Maybe you could explain a bit more?

this is what I want exactly, but I need to quantify this selection as a percentage of the whole photo or as an absolute square inches etc

or maybe I can create another photo with only this selection of pixels and then count the pixels?

I'm not really sure where to go from there... undecided (my version of photoshop is no help in getting the percentage)

anyone else got any ideas?
Logged

Tom
Renegade
Charter Member
***
Posts: 11,627



Tell me something you don't know...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #7 on: February 09, 2012, 07:44:09 PM »

Well, looks like no answers so far...

Here's a quick hack that does the job. It is NOT release quality, but it does what is asked - i.e. Counts the number of pixels in a picture that are a specific colour and outputs that number along with a %.

* PixelCounter.zip (76.64 KB - downloaded 43 times.)

You can run the "PixelCounter.exe" in the debug or release folder.



The complete project is there. (Consider it as WTFPL. Grin I just can't resist that!)



Logged

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker
Renegade
Charter Member
***
Posts: 11,627



Tell me something you don't know...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #8 on: February 09, 2012, 07:54:31 PM »

this is what I want exactly, but I need to quantify this selection as a percentage of the whole photo or as an absolute square inches etc

The program above that I posted uses % of total pixels, so, if you want to determine the area of the picture, then you can figure out the area that is the colour by using the %. Onscreen, area is largely irrelevant if it isn't expressed in pixels. i.e. Square cm or square inches are basically meaningless. (Yeah, yeah... I know... but it's close enough to true and is still more true than some sort of morphing universe.)

So, I think that covers it.



Logged

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker
kalos
Member
**
Posts: 1,069

View Profile Give some DonationCredits to this forum member
« Reply #9 on: February 10, 2012, 07:16:11 AM »

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)
Logged
Renegade
Charter Member
***
Posts: 11,627



Tell me something you don't know...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #10 on: February 11, 2012, 03:17:44 AM »

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)


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. cheesy

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:



Here's the code:

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1.        private string SomeOtherMethod(string imgPath, Color compareColor)
  2.        {
  3.            // http://stackoverflow.com/questions/6020406/travel-through-pixels-in-bmp
  4.            Bitmap bmp = new Bitmap(imgPath);
  5.            int count = 0;
  6.            int total = 0;
  7.  
  8.            for (int ii = 0; ii < bmp.Width; ii++)
  9.            {
  10.                for (int jj = 0; jj < bmp.Height; jj++)
  11.                {
  12.                    Color pixelColor = bmp.GetPixel(ii, jj);
  13.  
  14.                    // do stuff with pixelColor
  15.                    if (pixelColor.R == compareColor.R && pixelColor.G == compareColor.G && pixelColor.B == compareColor.B)
  16.                    {
  17.                        count++;
  18.                    }
  19.                    total++;
  20.                }
  21.            }
  22.  
  23.            decimal percent = (Convert.ToDecimal(count) / Convert.ToDecimal(total)) * 100;
  24.  
  25.            return "Counted " + count.ToString() + " pixels of " + total.ToString() + " (" + percent.ToString() + "%)";
  26.        }


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.

Formatted for C# with the GeSHI Syntax Highlighter [copy or print]
  1. (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.



Logged

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker
Renegade
Charter Member
***
Posts: 11,627



Tell me something you don't know...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #11 on: February 11, 2012, 03:51:33 AM »

Here's a new version:



* PixelCounter2.zip (81.75 KB - downloaded 47 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.

Logged

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker
kalos
Member
**
Posts: 1,069

View Profile Give some DonationCredits to this forum member
« Reply #12 on: February 11, 2012, 05:38:02 AM »

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
Logged
IainB
Supporting Member
**
Posts: 4,790


Slartibartfarst

see users location on a map View Profile Give some DonationCredits to this forum member
« Reply #13 on: February 11, 2012, 09:10:03 AM »

@Renegade: I like that new SOPA flag...  
Logged
tomos
Charter Member
***
Posts: 8,607



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #14 on: February 11, 2012, 11:06:50 AM »

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

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...
Logged

Tom
Ath
Supporting Member
**
Posts: 2,234



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #15 on: February 11, 2012, 12:02:14 PM »

In case of the skinchart picture, a selection like using the lasso tool of lots of graphics editors would be the easiest way of handling that process. Then counting the pixels inside would give a percentage covered by it.
But what would that need to be compared to? Total no. of square mm, but how to relate that to the pixelcount? (like Renegade already said) You would need a confirmed measuring standard on the same photo to be able to compare, like the crime-scene photo's you see in TV series like CSI.
Logged

Deozaan
Charter Member
***
Posts: 6,418



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #16 on: February 12, 2012, 11:06:42 PM »

Isn't this what the Magic Wand does in just about every paint/photo program out there?
Logged

Renegade
Charter Member
***
Posts: 11,627



Tell me something you don't know...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #17 on: February 12, 2012, 11:20:35 PM »

If someone knows how to do it in Photoshop, chime in. I don't know of how the Magic Wand helps...

Here's an ASCII representation that is impractical for the Magic Wand (to count the "O"s):

---O---O---O---O---O---O---
-O---O---O---O---O---O---O-
---O---O---O---O---O---O---
-O---O---O---O---O---O---O-
---O---O---O---O---O---O---

Or with X's just to make it more painful to look at:

XXXOXXXOXXXOXXXOXXXOXXXOXXX
XOXXXOXXXOXXXOXXXOXXXOXXXOX
XXXOXXXOXXXOXXXOXXXOXXXOXXX
XOXXXOXXXOXXXOXXXOXXXOXXXOX
XXXOXXXOXXXOXXXOXXXOXXXOXXX

That's the first problem for the Magic Wand - You must manually select all similar colour patches yourself, which defeats the purpose of doing it manually.

Next, I don't know how to get a pixel count from the Magic Wand. Anyone know how to do that?


Logged

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker
Deozaan
Charter Member
***
Posts: 6,418



see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #18 on: February 13, 2012, 03:20:35 AM »

Hmm... That's right. It doesn't select all similar colors. Only connected ones.

I don't use Photoshop, but I remember in PSP several years ago you there was either an option to make the Magic Wand select all similar colors in the entire image, or you could select a color and then use a menu option to select all similar colors. Something like that. . .

Once you've got all the pixels selected there is still a bit of a problem counting them. One way to do it could be to make the selection one color and make everything not selected a different color so you've got just a two-tone image and then use coding magic to figure it out from there. That's based on the assumption that it's easier to count specific pixels in a two-tone image than a 32-bit color image.

If it sounds like I don't know what I'm talking about, that's because I don't. I'll shut up now. embarassed
Logged

tomos
Charter Member
***
Posts: 8,607



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« Reply #19 on: February 13, 2012, 09:32:31 AM »

That's the first problem for the Magic Wand - You must manually select all similar colour patches yourself, which defeats the purpose of doing it manually.

again, in my ancient version of photoshop:
Contigious selected = select adjacent pixels of same colour (or similar colour - depending on the "tolerance")
Contigious deselected= select pixels of same colour (etc.) throughout the image

No idea how to count them though...
and,
as per Ath's post above, I dont really understand the request in the context of the example given...
Logged

Tom
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.067s | Server load: 0.09 ]