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

Friday, May 2, 2014

Let's Go!

Dear reader from somewhere, as you have probably seen, this blog will talk about the image processing mechanisms. Firstly, you must understand that we obviously won't see all things that exist in this field because it's just impossible but what you will see will help you to understand better how famous image editing software work (like GIMP or Adobe Photoshop). I mean how  the hell  can they transform an image into another one just by playing with pixels. So here we are, what is a pixel?
I'm talking about this little, very little element that comprises your digital image. This pixel is itself composed of data. These data are the colors of the famous (Alpha,Red,Green,Blue) or ARGB color model. Now if we see these 3 last colors as spotlights, we easily understand that we can generate new colors by turning them on and off. Here is an illustration where we see that Blue+Red=Magenta, Green+Red=Yellow, Green+Blue=Cyan, ... It's what we call additive color.
In computer science, these same data are represented with just 1 unsigned integer of 32bits.
Each ARGcomponent is consequently coded on 32bits / 4 colors = 8bits.
Even if Alpha isn't really a color. It's just an information which determines the opacity of your image.
If we "ignore" the Alpha information and consider only RGB, the lower value of these 3 colors will be
3 * 00000000 (= (0,0,0) = Black) and the higher value will be 3 * 11111111 (= (255,255,255) = White). In the  ARG RGcolor model, the representation of the pure Green color, for example, on 3*8bits, is 00000000 11111111 00000000 (= (0,255,0)) where the first 8bits indicate that the Red channel is totally disabled, like the last 8bits representing the state of the Blue channel and the second 8bits indicate that the Green channel is enabled and in addition to that, it's at its maximum value. Now you can imagine what is the binary representation of an image with a width w and a height h,
it's w * h pixels composed of 3*8bits (or even more as we "ignore" the Alpha information here).
All of this lead us to the matrices which are two dimensional arrays where we can find at each location (x,y) (= (column,row)) our 3 RGB colors. And each time, we will have to fully or partially read these matrices in order to update every colors according to what we want to do on our image. Apart from that, I hope you will enjoy what you will learn in my future posts and maybe it will encourage you to develop your own image editing software, I will be glad to use it if you link it to me. Here is an interesting image editing software that I recently found : PhotoDemon.



Note that certain of my future posts will be accompanied of source code examples.
And I've decided to use the OCaml programming language, and not Camel (ʘ‿ʘ)
Look at its very understandable syntax :

You can easily do lots of things with OCaml... Moreover, in my add function, I didn't had to specify the type of the variables x and y, the language automatically detects that in this case, the parameters are integers, like the resulting value, because of the presence of the operator "+". Let's test this function :

×
-
+
terminal

Objective Caml version 4.12.0

# add(21, 21);;
- : int = 42

Now, here are some others functions that will be useful to get the value of one pixel component or to make sure that a pixel component value is strictly between 0 and 255 as we just saw it.

Finally, here is an example on how to browse a matrix where matrix.(i).(j) is the location of the current (Red,Green,Blue) pixel and the symbol "<-" means receive. Plus, the location of the first pixel in a matrix is (0,0) (at the top-left corner) and not (1,1) as we could imagine. So if the dimensions of an image are widthxheight, the last pixel (at the bottom-right corner because we browse the matrix left to right and top to bottom) is at location (width-1,height-1) (and not at (width,height)).

But you can use the programming language of your choice...
Next time, I will present some classic image processing filters.