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

Monday, September 1, 2014

The Oil Painting Filter

 ⇒ 
radius = 2 & intensity levels = 20

In this new tutorial, I will explain you how to apply the famous oil painting effect on an image. The function we will see is based on 2 important parameters : the radius and the number of levels of intensity. The radius simply defines how many pixels in each direction around the current one to look for, during the browsing of your image. For example, I used a radius of 2 to get the illustration above on the right. Concerning the number of levels of intensity, just note that the higher the value is, the more colorful the resulting image will be. I used the value 20 which is a good reference number.

The procedure :
Basically, each pixel will be put into an intensity "bin". The true intensity of a (Red,Green,Blue) pixel is defined as (Red+Green+Blue) / 3, and can range anywhere from 0 to 255. However, the oil paintings have a much more restricted effect, so each pixel will have its intensity binned.
❝ Data binning is a data pre-processing technique used to reduce [...]. The original data values which fall in a given small interval, a bin, are replaced by a value representative of that interval, often the central value. It is a form of quantization. ❞ (Wikipedia)
For each pixel, all pixels within the radius will have to be examined. Pixels within the radius of the current one are sub-pixels. For each sub-pixel, you must calculate the intensity, and determine which intensity bin that intensity number falls into. Maintain a counter for each intensity bin, which will count the number of sub-pixels which fall into each intensity bin. Also maintain the total RedGreen, and Blue values for each bin because these will be used to determine the final value of the pixel. After that, for each pixel, determine which intensity bin has the most number of pixels in it.

After we determine which intensity the pixel represents, as determined by the intensity bin with the most pixels, we can then determine the final color of the pixel by taking the total RedGreen, and Blue values in that specific bin, and dividing that by the total number of pixels in that specific intensity bin. As always, here is an understandable example of source code :


Let's finish this post with another example of the use of the oil painting filter :

This is not a random image.
It was scheduled for a tutorial on the human skin detection so I'll use it again when needed
radius = 2 & intensity levels = 20


до свидания!