Sign in to follow this  

How could I do with Green filter?

This topic is 4710 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

What you could do is to scan through each pixel one by one and:

- add up the red, green and blue components
- divide by 3 (to get average) then by 256 (to get number in range 0 to 1)
- take that number and multiply the red, green and blue components of the destination colour with it, combine them again into a single colour and set the pixel.

Share this post


Link to post
Share on other sites
Calculate the luminance of the scene (0.299 * R + 0.587 * G + 0.114 * G)
Then use the result as the amount of green to render (i.e. multiply color (0, 1, 0) by the number calculated above).

Please post a screen shot when you get it working. I would love to see your results.

Share this post


Link to post
Share on other sites
Perhaps I'm misinterpreting the OP, but "Green filter glass" sounds like he wants a material that filters all but the green channel out of an image (like the POV-Ray filter color property). In this case, you would just allow the green component of each color to pass through and set the red and blue components to zero.

Share this post


Link to post
Share on other sites
(edit: update; what I wrote is not completely true. I added the bold text in point 2.)

I guess the OP really want how to implement a "green filter glass"-like filter - ie, as BitMaster stated, a filter that filters out everything which is not green - or only a percentage of it. SCHOTT sells some of them. This kind of filter is (widely?) used in photography.

And they are not really easy...

If you want to implement a real green filter glass then you'd have to do the following:


  1. transform your RGB color to a wavelength. This is not the easy part, but there are good hints on the net (take care: most code deals with wavelength-to-RGB conversion since most computer program uses RGB colors to represent datas).
  2. apply a lut on the data (wavelength to wavelength LUT). The Schott curves (VG6, VG9 and VG14 are good enough - use the transmittance curve, not the internal transmittance one). The LUT should have 2048 indices and should output a value in the range 0..2048 - so 16 bits should be OK. You can add more precision by multiplying by 16 if you want. (wrong) The Schott curves don't allow you to use a wavelength-to-wavelength LUT; the wavelength do not change, but the amount of energy that goes through the filter changes. Thefore, the transmittance should be applied to the RGB color:

    int wl;
    float tr;
    wl = rgbToWavelength(my_rgb_color);
    tr = SchottFilter[wl]; // tr is in [0.0 .. 1.0f]
    my_rgb_color = tr * my_rgb_color;

    The LUT is therefore a wavelength-to-transmittance LUT, and stores float values which are in the range 0..1..
  3. transform back your wavelength to RGB. You don't have to do that.

This will not be as fast as you'd like - because of the number of per-pixel operation. Moreover, Schott's filters are real filters, not perfect filters.

This is an interesting subject. I'll try to write some code in the next days (I'd like to see the effect with a green filter, a yellow filter, a red filter and so on :D)

Regards,

[Edited by - Emmanuel Deloget on January 17, 2005 9:34:18 AM]

Share this post


Link to post
Share on other sites
Thanks for all . I will post the result soon.
1.In each pixel I reduce G to zero and take no change with R and B ? For example the origin pixel is (25,48,123) and after do Green Filter this will be (25,0,123)
Or
2. In each pixel, I caculate the min value of R, G, B and then reduce G to the min value while R and B is not change.
For example: RGB = 142,147,12 then after filter these are RGB = 142,12,12
?
Any idea?
Thanks for help

Share this post


Link to post
Share on other sites

This topic is 4710 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this