Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


comparing colors


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 freeworld   Members   -  Reputation: 329

Like
0Likes
Like

Posted 30 January 2012 - 04:16 PM

Ok I got this idea for a little shader but one hurdle... i want to compare colors (rgb no alpha), and if they are close enough alter them as I see fit. Now I could do this with say a threshold and check every channel to see if it's close enough to the other channel they are the same. Though I also what to confine the resulting colors to either red, green or blue.... I'm mostly curious if there is an easier/ more elegant way to do this then checking every chennel for every pixel in a 5x5 radius for every pixel on the screen?

This is my idea so far.. psuedo...
float threshold = 0.25f;

if ( absolute(r1 - r2) <= threshold )
    red channel close enough...

// do this for each channel, if all pass then they colors are close enough.

// then check each channel to see which is the predominat one, and output that color only.

Now this is going to be doing an area comparison, so it isn't just going to check 4 pixels per pixel, but probably ~8-16 pixels to compare all surrounding pixels. Hopefully that made sense, I can try to explain more if needed... and thanks.
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.

Sponsor:

#2 Krypt0n   Crossbones+   -  Reputation: 2683

Like
0Likes
Like

Posted 30 January 2012 - 08:48 PM

a common way to compare colors is by taking the MSE (mean squared error http://en.wikipedia.org/wiki/Mean_squared_error )
float3 delta = r1.rgb-r2.rgb;
delta*=weight.rgb;//if you want to weight individual channels
if(dot(delta,delta)<treshold)
...
if you want to find particular areas, you might want to take a look at summed area tables ( http://en.wikipedia.org/wiki/Summed_area_table ).
Another way ist to create a variance map in lower resolution, you basically scale the image down to lets say 1/4th the resolution, saving per pixel the average of 4x4 pixel and the biggest delta, this way you can easily figure out if some 4x4 area falls into the space of the color you seek.

#3 Digitalfragment   Members   -  Reputation: 874

Like
0Likes
Like

Posted 30 January 2012 - 09:14 PM

You might find it makes more sense to base your tolerances in HSV instead of RGB too.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS