,.
. :%%%. .%%%.
__%%%(\ `%%%%% .%%%%%
/a ^ '% %%%% %: ,% %%"`
'__.. ,'% .-%: %-' %
~~""%:. ` % ' . `.
%% % ` %% .%: . \.
%%:. `-' ` .%% . %: :\
%(%,%..." `%, %%' %% ) )
%)%%)%%' )%%%.....- ' "/ (
%a:f%%\ % / \`% "%%% ` / \))
%(%' % /-. \ ' \ |-. '.
`' |% `() \| `()
|| / () /
() 0 | o
\ /\ o /
o ` /-|
___________ ,-/ ` _________ ,-/ _________________ INCLUDES _ OCAML _ SOURCE _ CODE _ EXAMPLES _____________________________________________

Tuesday, July 8, 2014

Color Adjustment

After one of my posts which talked about the color correction, I am going to present new color adjustment methods which are frequently used in photography and image processing and which can change different color properties like the hue of your image, the color balance and finally, the color tint.


Hue rotation :

Firstly, what is the hue? A good definition could be the property of colors by which they can be perceived as ranging from Red through Yellow, Green, and Blue, as determined by the dominant wavelength of the light. This color variation is generally illustrated with what we call a color wheel (see above) where each color on this color wheel is accessible due to a certain angle going from 0 to 359°. Nevertheless this information didn't help me to understand how to change the hue of an image and in addition to that it was really hard to find more explanation about this color transformation.
But I think I found an appropriate answer. Look at the following intriguing image (source) :
I simply tried to apply the given formula and as you can see on my illustrations above, it worked perfectly. Each RGB pixel of your image must be replaced by R'G'B' as they are defined (you can ignore the Alpha information, I mean A' and A) and θ is an angle of your choice between 0 and 359°.
I hope you know how to manipulate matrices... Here is my  ugly  hue_rotation function :


Color balance :
  
The color balance is the global adjustment of the intensities of the colors (typically Red, Green, and Blue primary colors). An important goal of this adjustment is to render specific colors – particularly neutral colors – correctly; hence, the general method is sometimes called gray balance, neutral balance, or white balance. Color balance changes the overall mixture of colors in an image and is used for color correction; generalized versions of color balance are used to get colors other than neutrals to also appear correct or pleasing. The function that I will present is based on the values of 3 parameters which can change the appearance of your image significantly. These parameters are Red', Green' and Blue' component values of your choice. All you have to do is replacing all the (Red,Green,Blue) pixel components of your image by ((255/Red')*Red, (255/Green')*Green, (255/Blue')*Blue). I used the parameters (159,92,65), (192,157,86), (220,166,166) for the 3 illustrations above. Note that you must use floating point numbers when you are calculating (255/x') * x.


Color tint :
  
In color theory, a tint is the mixture of a color with White, which increases lightness of your image. It's the contrary of what we called a shade which is the mixture of a color with Black and which reduces lightness. Here is an example of some shades of Blue :
The function which changes the color tint of your image is very similar to the previous one. But this time, the 3 important parameters are percentages representing an increase of the Red, Green or Blue tint of your image. If your 3 percentages are Red'Green' and Blue', what you have to do is replacing all the (Red,Green,Blue) pixel components of your image by
(Red + (255Red)*Red''Green + (255 - Green)*Green'', Blue + (255 - Blue)*Blue'') where
Red'' = Red'/100, Green'' = Green'/100 and Blue'' = Blue'/100. Here is a source code example :