Jump to content
  • Advertisement
Sign in to follow this  

comparing colors

This topic is 2822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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 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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!