That Software Guy, Inc.'s Logo

Software Consulting Services
Need Help? Call That Software Guy!


RatePoint Site Seal

Sign up for That Software Guy, Inc.'s Zen Cart Newsletter. You'll get periodic updates on new features I'm developing.
Email:
Preferred format:
HTML   Text


So I started looking at image transformation using GD, and I thought, what would it take to turn a red shirt blue? I started with a jpg image of a red shirt, and converted it to a gif to make the number of colors more manageable.
Here's the nice red shirt I started with. Perfect for bullfighting. How hard could it be to turn this thing blue?
My first thought was, let's just find the most common color in the image and change it to blue. It never occurred to me that the most common color would be the background. No big deal - it's probably the second most common color.
Ummm... unless it's not. OK, let's try a more sophisticated approach. Let's use the W3C's color difference formula, and appy the new color to any pixel within a specific difference of the old color. The formula is:

color difference = (maximum (Red value 1, Red value 2) - minimum (Red value 1, Red value 2)) + (maximum (Green value 1, Green value 2) - minimum (Green value 1, Green value 2)) + (maximum (Blue value 1, Blue value 2) - minimum (Blue value 1, Blue value 2))
Better. This image shows the effect of changing any color whose difference is less than 20 from our target color to the target color. Let's try just going from 20 to 100.
Hmm.... this looks flat. But if I go down from 100, I still see red pixels. So rather than just applying the new color to pixels within a certain color difference, why don't we apply the difference between the new color and original color to those pixels?
This is applying the difference when the difference is less than 60. Now we still see red pixels, but look at how the texture is preserved. Let's try bumping it back up to 100.
This is the image using a color difference threshold of 100. Almost all the red is gone. You just see a little bit around the collar and under the arms.
I raised the color difference threshold to 200. Here's the great blue shirt I finally ended up with.

But enough of polo shirts. Let's look at what we really want to see.
Want to do this yourself? The ColorShifter is now available to the public.

   Terms | Privacy | SiteMap | Newsletter | Contact Me | ©2003-2008 That Software Guy, Inc.