This project has moved. For the latest updates, please go here.

Adjust image intensity & apply blue tint to an image

Jun 10, 2015 at 1:27 PM
Hello,

I have to adjust image intensity and then apply blue tint to an image using below mentioned algorithm written in “Interactive Data Language” (IDL).

Most commonly, photographs are three channel images with a red, a green and a blue image (RGB). Usually the data is stored as “sRGB”, which means there is a non-linear encoding of the amount of light a pixel represents to a pixel value that maps to the display device.

Blue Channel
The simplest form of “blue light simulation” is simply using the blue channel by itself. It has the strongest contrast between spots and background skin. However, the image is much darker and needs lighting up. In the real world, we would increase the number of photons on each pixel, by increasing the strength of the lighting, opening up the aperture of the camera or using a longer shutter time. To simulate this with an existing RGB image, first the sRGB encoding needs to be removed. The simplest way of approximating this is by using this:
Bg = (B/255)γ, where we use γ = 2.2
B is the original pixel value, Bg is “gamma corrected” or linearized pixel value. These latter values can now be multiplied, gamma-transformed and put back into the image.
Enhanced-B = 255 * (factor * Bg)1/γ   
Where factor can be set to the increase in light intensity. Note that values need to be clipped at a value of 255 (pixels greater than 255 are set to 255). The figure below illustrates factor =2 and factor = 4:

It can be seen that simulating 4x as much light looks much like doubling the pixel values without linearizing the blue channel. However, doubling the pixel values increases the perceived lightness of the lighter areas more than that of the darker area, and hence enhances the contrast more than could be achieved with just photography.

The final step in the simulation is to present an image with a blue tint. This is simply accomplished by creating a three-channel image with the Bg values in each channel, adjusting each of the channels with a constant representing a blue tint, and transforming that back to an sRGB image:
Enhanced-Red = 255 * (factor * ( RedC + Bg) )1/γ   
And analogously for Green and Blue. A good tint vector is [RedC, GreenC, BlueC] = [-0.03,-0.03,0.03].

Please suggest how we can achieve same using Magick.Net API.

Thanks in advance!!
Coordinator
Jun 10, 2015 at 3:03 PM
I think you should take a look at the Fx method of MagickImage. You can use that to do mathematical operations on channels. You can find the documentation here: http://www.imagemagick.org/script/fx.php.
Jun 10, 2015 at 4:01 PM
Edited Jun 10, 2015 at 4:10 PM
Thanks dlemstra for instant reply, can't we achieve above mentioned need through some methods in MagickImage class? I am badly stuck with this need and already spent a week but with no success. I am not able to paste image snapshots here, let me know how i can provide you for better understanding of output.
Coordinator
Jun 10, 2015 at 4:17 PM
You could put your images on dropbox/onedrive. It would really help to get som visual examples. Or write your calculations in c# so they are easier to understand.
Jun 10, 2015 at 4:20 PM
Edited Jun 10, 2015 at 4:22 PM
I don't have access to any dropbox/onedrive. Please share if you have any. I need to write code in C# but i got calculation in IDL as a reference. Please share your mail id, will send visual examples.
Coordinator
Jun 11, 2015 at 6:53 AM
Dropbox is free and it is easy to create an account. I would recommend you to create one. You can contact me through CodePlex if you prefer to use e-mail.
Jun 12, 2015 at 4:15 AM
I have uploaded the visual on dropbox @ https://www.dropbox.com/s/vaa345b4zev3ozr/CodePlex_Discussion_639776_AdjustIntensity%26BlueTint.png?dl=0. Here you find the sample image and two step process to achieve the required output.
Coordinator
Jun 12, 2015 at 5:04 AM
Can you make the first image available as a separate download?
Jun 12, 2015 at 5:26 AM
Edited Jun 12, 2015 at 5:40 AM
I have uploaded 3 seperate images on dropbox folder @ https://www.dropbox.com/sh/5ibv54wywa0128p/AADjBrd7yWe52bPu_CkfAOgLa?dl=0. Please let me know in case more information require.

Thanks in advance.
Jun 16, 2015 at 5:15 AM
Hello dlemstra,

Have you got the chance to look into my problem? Please share your findings. I am relying on your help now.

Thanks in advance.
Coordinator
Jun 16, 2015 at 7:34 AM
I haven't had time to look at this yet. I don't have a math background so I am not sure how to read this:
Bg = (B/255)γ, where we use γ = 2.2 
What happens when the value is 128?
128 / 255 ???? 2.2
Jun 16, 2015 at 9:32 AM
Hello dlemstra,

Can't we achieve on looking into output image shared with you. I agree we can't do mathematical calculations but if you look into summary then first we need to extract Blue channel image and then increase the intensity to 4x and at the end apply Blue tint.
Coordinator
Jun 16, 2015 at 9:39 AM
We can do mathematical calculations but I don't understand what Bg = (B/255)γ means. How would you write that in C#?
Jun 16, 2015 at 3:58 PM
Hello dlemstra,
We can ignore this mathematical calculations and refer images shared and try to replicate through Magick methods.
Coordinator
Jun 16, 2015 at 7:02 PM
Edited Jun 16, 2015 at 8:42 PM
The problem is that I don't know how to translate it because I don't understand what you are trying to do.
Bg = (B/255)γ, where we use γ = 2.2 
What is the value of Bg when B is 128?

If you are just trying to extract individual channels from an image you should use the Separate method of MagickImage.