The effect of some photo filters can be summarized in transmission curves such as this one:


I want to simulate the effect of such filters on digital images. For example, the Warming Filter 81A whose curve is pictured above.

I have to convert the color of each pixel of the source image, to the color it would be seem to have if seen through the filter.
Digital image colors are usually stored in the RGB format, but can be converted to other color spaces: HSV, YCbCr, etc.

How can I relate the transmittance function to the source and converted image colors?
Which color space should I use to simulate the effect of a photo filter, without losing any of the light information (chromaticity or luminosity)?

Note: I posted a related question on physics.stackexchange.com

  • 1
    Are you trying to write the algorithm yourself, or are you just interested in the outcome? Adobe Photoshop has a Photo Filters effect, which allows you to apply any one of the standard warming and cooling filter effects to your images. – jrista Dec 9 '13 at 6:40
  • @jrista Yes, I am trying to write the algorithm myself. Actually, I would like to do quite the same thing as what Photoshop does with its Photo Filter effect. – wip Dec 9 '13 at 13:15
  • 1
    @wil, please see this about cross-posting on Stack Exchange sites. meta.stackexchange.com/questions/64068/… – Please Read My Profile Dec 10 '13 at 1:17
  • @mattdm Ok, I am deleting and editing the questions. – wip Dec 10 '13 at 1:20
  • 1
    Do you have the actual equation for the curve, or do just have a picture of the curve as above? – Please Read My Profile Dec 10 '13 at 1:21

Disclaimer: this is off the top of my head --- I hope I am getting this right.

Probably you should make some assumption because I suppose that there is a loss of information when going from the "real" image to the RGB composition which is not reversible.

I mean, supposing a "real" RGB pixel (forget about demosaicing and so on), the light that hit that pixel has a spectrum of potentially infinite wavelengths. This spectrum is sampled by three photosites, which are really weighting the spectrum in three zones, trying to mimic the human color receptors sensitivity (I suppose...). This is utterly destructive; you can't reconstruct the spectrum of the single pixel after that. There is some information in the links of https://stackoverflow.com/questions/12239986/convert-rgb-to-light-frequency.

To do approximate filtering, I see two ways:

  • doing it on the HUE channel. This is how for example the "color zones" of Darktable works. Maybe you can peek at the source code of this.

  • you can try to apply the same "weight function" the sensor apply to the image to your filtering function, with a white light in. Supposing linearity, you should then be able to obtain a transformation matrix (R, G, B) to apply to your image.

You can also have a peek at http://registry.gimp.org/node/24473, if you can grasp some of LISP programming ;-)

And for a bit of intelligent fun, don't forget to look at Roger Cicala's blog...

| improve this answer | |
  • Thank you for the valuable suggestions, I'm investigating them now. – wip Dec 10 '13 at 5:35
  • About your second idea, I don't see how I can obtain three transformation matrices. One pixel of my image is made of 3 values (R, G, B), the output of the transformation would be another 3-values color, so the transformation would be a single 3x3 matrix, no? How would I obtain the two other matrices? – wip Dec 10 '13 at 5:50
  • @Wil, you are correct --- will edit. – Rmano Dec 10 '13 at 15:02

The problem you are trying to solve is highly underconstrained - the colour of each pixel in your digital image depends on the frequency distribution of the light entering that pixel. Different frequency distributions can result in the same RGB value being recorded in the image, however with the filter in place these different frequency distributions will give different results.

The simplest solution would actually be to buy a bunch of filters and work out the average shift empirically. I imagine the warming filter in photoshop was probably tuned by eye and is far from accurate.

The only other way would be to run a large number of simulations of different lightsources with different distributions, shining light onto different object with different reflectance properties then calculate the attenuation using the response of your filter, then the response of the pixel colour filters, then factor in different RAW processing methods and aggregate the results.

| improve this answer | |
  • You are right in noticing that the problem is under constrained, that is the main problem I had to solve. – wip Apr 3 '14 at 9:13

I ended up converting the RGB values of my source digital image to Spectrum Power Distributions (SPD) using the algorithm Brian Smits describes in this paper: An RGB to Spectrum Conversion for Reflectances.

Once I have a SPD for a given color, I apply the transmission curve to it and obtain a new SPD.

Finally, I convert back that SPD to an RGB values, which allows me to reconstruct a new digital image.

I made a small tool illustrating the conversion process, if anyone's interested, here is the source.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.