LLIPS  rev33
Light Library for Image ProcesS
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
llips_general.c
Go to the documentation of this file.
1 /********************************************/
7 /* http://www.commentcamarche.net/contents/1200-bmp-format-bmp
8 0x0000 Entête du fichier
9 0x0000 La signature (sur 2 octets), indiquant qu'il s'agit d'un fichier BMP à l'aide des deux caractères.
10  BM, 424D en hexadécimal, indique qu'il s'agit d'un Bitmap Windows.
11 0x0002 La taille totale du fichier en octets (codée sur 4 octets)
12 0x0006 Un champ réservé (sur 4 octets)
13 0x000A L'offset de l'image (sur 4 octets), en français décalage,
14 
15 0x000E Entête de l'image
16 0x000E La taille de l'entête de l'image en octets (codée sur 4 octets).
17  28 pour Windows 3.1x, 95, NT, ...
18  0C pour OS/2 1.x
19  F0 pour OS/2 2.x
20 0x0012 La largeur de l'image (sur 4 octets), c'est-à-dire le nombre de pixels horizontalement (en anglais width)
21 0x0016 La hauteur de l'image (sur 4 octets), c'est-à-dire le nombre de pixels verticalement (en anglais height)
22 0x001A Le nombre de plans (sur 2 octets). Cette valeur vaut toujours 1
23 0x001C La profondeur de codage de la couleur(sur 2 octets), c'est-à-dire le nombre de bits utilisés pour coder
24  la couleur. Cette valeur peut-être égale à 1, 4, 8, 16, 24 ou 32
25 0x001E La méthode de compression (sur 4 octets). Cette valeur vaut 0 lorsque l'image n'est pas compressée, ou
26  bien 1, 2 ou 3 suivant le type de compression utilisé :
27  1 pour un codage RLE de 8 bits par pixel
28  2 pour un codage RLE de 4 bits par pixel
29  3 pour un codage bitfields, signifiant que la couleur est codé par un triple masque représenté par la palette
30 0x0022 La taille totale de l'image en octets (sur 4 octets).
31 0x0026 La résolution horizontale (sur 4 octets), c'est-à-dire le nombre de pixels par mètre horizontalement
32 0x002A La résolution verticale (sur 4 octets), c'est-à-dire le nombre de pixels par mètre verticalement
33 0x002E Le nombre de couleurs de la palette (sur 4 octets)
34 0x0032 Le nombre de couleurs importantes de la palette (sur 4 octets). Ce champ peut être égal à 0 lorsque chaque couleur a son importance.
35 
36 0x0036 Palette de l'image
37  La palette est optionnelle. Lorsqu'une palette est définie, elle contient successivement 4 octets pour chacune de ses entrées représentant :
38  http://fr.wikipedia.org/wiki/Windows_bitmap
39  La composante bleue (sur un octet)
40  La composante verte (sur un octet)
41  La composante rouge (sur un octet)
42  Un champ réservé (sur un octet)
43 
44 0x0xxx Codage de l'image (dépend de la palette)
45 0x0036 avec bmp 24bit windows
46  Les images en couleurs réelles utilisent 24 bits par pixel,
47  ce qui signifie qu'il faut 3 octets pour coder chaque pixel,
48  en prenant soin de respecter l'ordre de l'alternance
49  bleu,
50  vert
51  et rouge.
52 */
53 
54 /* ***************************************************************/
55 /* * Includes */
56 /* ***************************************************************/
57 #include "llips_includes.h"
58 
59 /* ***************************************************************/
60 /* * Global variables */
61 /* ***************************************************************/
62 //Predefined laplacian filter
63 const CPU_FP64 lapl_filter_1[3][3] = {{ 0,-1, 0},
64  {-1, 4,-1},
65  { 0,-1, 0}};
66 
67 const CPU_FP64 lapl_filter_2[3][3] ={{0, 1, 0},
68  {1,-4, 1},
69  {0, 1, 0}};
70 
71 const CPU_FP64 lapl_filter_3[3][3] = {{-1,-1,-1},
72  {-1, 8,-1},
73  {-1,-1,-1}};
74 
75 const CPU_FP64 lapl_filter_4[3][3] = {{ 1,-2, 1},
76  {-2, 4,-2},
77  { 1,-2, 1}};
78 
79 const CPU_FP64 lapl_filter_5[5][5] = { { 0, 0,-1, 0, 0},
80  { 0,-1,-2,-1, 0},
81  {-1,-2,16,-2,-1},
82  { 0,-1,-2,-1, 0},
83  { 0, 0,-1, 0, 0}};
84 /* ***************************************************************/
85 /* * Functions */
86 /* ***************************************************************/
87 
88 /********************************************/
97 {
98  CPU_INT16S i,j;
99 
100  if((colors & HEADER) != 0)
101  {
102  printf("Header size : %d\n",img->FileHeader_size);
103  printf("Header\n");
104  for(i=0;i<img->FileHeader_size;i++)
105  {
106  printf("%2x",img->FileHeader[i]);
107  if(((i+1)%16)==0)
108  {
109  printf("\n");
110  }
111  }
112  }
113  printf("\n\n");
114 
115  if((colors & BLUE) != 0)
116  {
117  printf("Blue Pixel\n");
118  for(i=img->he-1;i>=0;i--)
119  {
120  for(j=0;j<img->wi;j++)
121  {
122  printf("%2x",img->Blue[i][j]);
123  }
124  printf("\n");
125 
126  }
127  printf("\n");
128  }
129 
130  if((colors & GREEN) != 0)
131  {
132  printf("Green Pixel\n");
133  for(i=img->he-1;i>=0;i--)
134  {
135  for(j=0;j<img->wi;j++)
136  {
137  printf("%2x",img->Green[i][j]);
138  }
139  printf("\n");
140  }
141  printf("\n");
142  }
143 
144  if((colors & RED) != 0)
145  {
146  printf("Red Pixel\n");
147  for(i=img->he-1;i>=0;i--)
148  {
149  for(j=0;j<img->wi;j++)
150  {
151  printf("%2x",img->Red[i][j]);
152  }
153  printf("\n");
154  }
155  printf("\n");
156  }
157 }
158 
159 
160 /********************************************/
173 {
174  t_vect move;
175 
176  move.x = pix2.x - pix1.x ;
177  move.y = pix2.y - pix1.y ;
178  //draw the line... I don't know how...
179  return move;
180 }
181 
182 
183 
184 /********************************************/
193 {
194  t_vect move;
195 
196  move.x = pix2.x - pix1.x ;
197  move.y = pix2.y - pix1.y ;
198 
199  return move;
200 }
201 
202 
203 /********************************************/
211 {
212  CPU_INT16U module;
213 
214  module = (CPU_INT16U)sqrt(vect.x * vect.x + vect.y * vect.y);
215 
216 
217  return module;
218 }
219 
220 
221 /********************************************/
230 {
231  t_area ret;
232  ret.TopLeft.x = pix.x;
233  ret.TopLeft.y = pix.y;
234  ret.TopRight.x = pix.x;
235  ret.TopRight.y = pix.y;
236  ret.BotLeft.x = pix.x;
237  ret.BotLeft.y = pix.y;
238  ret.BotRight.x = pix.x;
239  ret.BotRight.y = pix.y;
240 
241  return ret;
242 }
243 
244 
245 
246 /********************************************/
255 CPU_VOID init_area(t_area * area,CPU_INT16U maxwidth,CPU_INT16U maxheight)
256 {
257  area->BotLeft.x = maxwidth;
258  area->BotLeft.y = maxheight;
259  area->BotRight.x = 0;
260  area->BotRight.y = maxheight;
261  area->TopLeft.x = maxwidth;
262  area->TopLeft.y = 0;
263  area->TopRight.x = 0;
264  area->TopRight.y = 0;
265 }
266 
267 
268 /********************************************/
279 {
280  CPU_INT16S i,j;
281 
282  for(i=0;i< img->he ;i++)
283  {
284  for(j=0 ; j< img->wi ;j++)
285  {
286  if (
287  (((j >= area->BotLeft.x) && (j <= area->BotRight.x)) && ((i == area->BotLeft.y) || (i == area->BotRight.y)))
288  || (((j >= area->TopLeft.x) && (j <= area->TopRight.x)) && ((i == area->TopLeft.y) || (i == area->TopRight.y)))
289  || (((i >= area->BotLeft.y) && (i <= area->TopLeft.y) ) && ((j == area->BotLeft.x) || (j == area->TopLeft.x)) )
290  || (((i >= area->BotRight.y) && (i <= area->TopRight.y)) && ((j == area->BotRight.x) || (j == area->TopRight.x)))
291  )
292  {
293  img->Green[i][j]= GetGreen(RGB);
294  img->Blue[i][j] = GetBlue(RGB);
295  img->Red[i][j] = GetRed(RGB);
296  }
297  }
298  }
299 }
300 
301 
302 /********************************************/
310 {
311  printf("\n%d,%d\t- \t-\t-\t - %d,%d\n| \t- \t-\t-\t - |\n| \t- \t-\t-\t - |\n%d,%d\t- \t-\t-\t - %d,%d\n\n",
312  area->TopLeft.x,
313  area->TopLeft.y,
314  area->TopRight.x,
315  area->TopRight.y,
316  area->BotLeft.x,
317  area->BotLeft.y,
318  area->BotRight.x,
319  area->BotRight.y);
320 }
321 
322 
323 /********************************************/
333 CPU_CHAR color_filter(t_img * img_in,t_img * img_out, CPU_INT32U color)
334 {
335  CPU_CHAR ret = ERR_NONE;
336  CPU_INT16S i,j;
337 
338  //Write Header
339  for(i=0;i<img_in->FileHeader_size;i++)
340  {
341  img_out->FileHeader[i] = img_in->FileHeader[i];
342  }
343  img_out->signature = img_in->signature;
344  img_out->depth = img_in->depth;
345  img_out->wi = img_in->wi;
346  img_out->he = img_in->he;
347  img_out->FileHeader_size = img_in->FileHeader_size;
348 
349  //
350  for(i=0;i< (img_in->he ) ;i++)
351  {
352  for(j=0 ; (j< img_in->wi );j++)
353  {
354  if ((color & RED)!=0)
355  {
356  img_out->Red[i][j] = img_in->Red[i][j];
357  }else
358  {
359  img_out->Red[i][j] = 0;
360  }
361  if ((color & GREEN)!=0)
362  {
363  img_out->Green[i][j] = img_in->Green[i][j];
364  }else
365  {
366  img_out->Green[i][j] = 0;
367  }
368  if ((color & BLUE)!=0)
369  {
370  img_out->Blue[i][j] = img_in->Blue[i][j];
371  }else
372  {
373  img_out->Blue[i][j] = 0;
374  }
375  }
376  }
377 
378 
379  return ret;
380 }
381 
382 
383 /********************************************/
392 CPU_CHAR histogram(t_img * img_in,t_img * img_out)
393 {
394  CPU_CHAR ret = ERR_NONE;
395  CPU_INT16U i,j;
396 
397  CPU_INT32U histowidth ;
398  CPU_INT32U histoheigh ;
399  CPU_INT32U histo_x = 1 ;
400  CPU_INT32U histo_y_red = 1,histo_y_green,histo_y_blue,histo_y_lum ;
401 
402  CPU_INT32U * redpixel = calloc((PIXEL_8bit_RANGE+1),sizeof(CPU_INT32U));
403  CPU_INT32U * greenpixel = calloc((PIXEL_8bit_RANGE+1),sizeof(CPU_INT32U));
404  CPU_INT32U * bluepixel = calloc((PIXEL_8bit_RANGE+1),sizeof(CPU_INT32U));
405  CPU_INT32U * luminancepixel = calloc((PIXEL_8bit_RANGE+1),sizeof(CPU_INT32U));
406  CPU_CHAR Luminance = 0;
407 
408  CPU_INT32U index,histomaxred=0,histomaxgreen=0,histomaxblue=0,histomaxlum =0;
409 
410  // configure historgam
411  histowidth = (img_in->wi)/4.5;
412 
413  if(histowidth>PIXEL_8bit_RANGE)
414  {
415  histowidth = PIXEL_8bit_RANGE;
416  }
417  histoheigh = histowidth / 2 ;
418 
419  histo_y_green = histo_y_red + histowidth + 2;
420  histo_y_blue = histo_y_green + histowidth + 2;
421  histo_y_lum = histo_y_blue + histowidth + 2;
422 
423  //Write Header
424  for(i=0;i<img_in->FileHeader_size;i++)
425  {
426  img_out->FileHeader[i] = img_in->FileHeader[i];
427  }
428  img_out->signature = img_in->signature;
429  img_out->depth = img_in->depth;
430  img_out->wi = img_in->wi;
431  img_out->he = img_in->he;
432  img_out->FileHeader_size = img_in->FileHeader_size;
433 
434  //count distribution of red pixel
435  for(i=0;i< (img_in->he ) ;i++)
436  {
437  for(j=0 ; (j< img_in->wi );j++)
438  {
439  //getting red pixel
440  index = img_in->Red[i][j] / (PIXEL_8bit_RANGE/(histowidth-1));
441  redpixel[index]++;
442  histomaxred = maxi(histomaxred,redpixel[index]);
443 
444  //getting green pixel
445  index = img_in->Green[i][j] / (PIXEL_8bit_RANGE/(histowidth-1));
446  greenpixel[index]++;
447  histomaxgreen = maxi(histomaxgreen,greenpixel[index]);
448  //getting red pixel
449  index = img_in->Blue[i][j] / (PIXEL_8bit_RANGE/(histowidth-1));
450  bluepixel[index]++;
451  histomaxblue = maxi(histomaxblue,bluepixel[index]);
452 
453  //calcultate luminance Y = 0,299 R + 0,587 G + 0,114 B
454  Luminance = (CPU_CHAR)( (CPU_FP32)img_in->Red[i][j] * 0.299
455  + (CPU_FP32)img_in->Green[i][j] * 0.587
456  + (CPU_FP32)img_in->Blue[i][j] * 0.114 );
457 
458  //getting lumi pixel
459  index = Luminance / (PIXEL_8bit_RANGE/(histowidth-1));
460  luminancepixel[index]++;
461  histomaxlum = maxi(histomaxlum,luminancepixel[index]);
462  }
463  }
464 
465  // normalize histogramm according to highest pixel distribution
466  // and height of histogram, and to histogram width
467  for(i=0;i<histowidth;i++)
468  {
469  redpixel[i] = redpixel[i] * histoheigh / histomaxred ;
470  greenpixel[i] = greenpixel[i] * histoheigh / histomaxgreen ;
471  bluepixel[i] = bluepixel[i] * histoheigh / histomaxblue ;
472 
473  luminancepixel[i] = luminancepixel[i] * histoheigh / histomaxblue ;
474 
475  }
476 
477  //copy input img to output including histogram
478  for(i=0;i< (img_in->he ) ;i++)
479  {
480  for(j=0 ; (j< img_in->wi );j++)
481  {
482  // Looking for red drawing area
483  if( ((j>=histo_y_red) && (j<=(histo_y_red+histowidth)))
484  && ((i>=histo_x) && (i<(histo_x+histoheigh)))
485  )
486  {
487  if(redpixel[j-histo_y_red] >= (i-histo_x))
488  {
489  img_out->Red[i][j] = 255;
490  img_out->Green[i][j] = 0;
491  img_out->Blue[i][j] = 0;
492  }else
493  {
494  img_out->Red[i][j] = (img_in->Red[i][j])/2;
495  img_out->Green[i][j] = (img_in->Green[i][j])/2;
496  img_out->Blue[i][j] = (img_in->Blue[i][j])/2;
497  }
498  }// Looking for green drawing area
499  else if( ((j>=histo_y_green) && (j<=(histo_y_green+histowidth)))
500  && ((i>=histo_x) && (i<(histo_x+histoheigh)))
501  )
502  {
503  if(greenpixel[j-histo_y_green] >= (i-histo_x))
504  {
505  img_out->Red[i][j] = 0;
506  img_out->Green[i][j] = 255;
507  img_out->Blue[i][j] = 0;
508  }else
509  {
510  img_out->Red[i][j] = (img_in->Red[i][j])/2;
511  img_out->Green[i][j] = (img_in->Green[i][j])/2;
512  img_out->Blue[i][j] = (img_in->Blue[i][j])/2;
513  }
514  }// Looking for blue drawing area
515  else if( ((j>=histo_y_blue) && (j<=(histo_y_blue+histowidth)))
516  && ((i>=histo_x) && (i<(histo_x+histoheigh)))
517  )
518  {
519  if(bluepixel[j-histo_y_blue] >= (i-histo_x))
520  {
521  img_out->Red[i][j] = 0;
522  img_out->Green[i][j] = 0;
523  img_out->Blue[i][j] = 255;
524  }else
525  {
526  img_out->Red[i][j] = (img_in->Red[i][j])/2;
527  img_out->Green[i][j] = (img_in->Green[i][j])/2;
528  img_out->Blue[i][j] = (img_in->Blue[i][j])/2;
529  }
530  }// looking for lum drawing area
531  else if( ((j>=histo_y_lum) && (j<=(histo_y_lum+histowidth)))
532  && ((i>=histo_x) && (i<(histo_x+histoheigh)))
533  )
534  {
535  if(luminancepixel[j-histo_y_lum] >= (i-histo_x))
536  {
537  img_out->Red[i][j] = 180;
538  img_out->Green[i][j] = 180;
539  img_out->Blue[i][j] = 180;
540  }else
541  {
542  img_out->Red[i][j] = (img_in->Red[i][j])/2;
543  img_out->Green[i][j] = (img_in->Green[i][j])/2;
544  img_out->Blue[i][j] = (img_in->Blue[i][j])/2;
545  }
546  }
547  else
548  {
549  img_out->Red[i][j] = img_in->Red[i][j];
550  img_out->Green[i][j] = img_in->Green[i][j];
551  img_out->Blue[i][j] = img_in->Blue[i][j];
552  }
553  }
554  }
555 
556 
557 
558 
559  return ret;
560 }
561 
562 
563 /********************************************/
571 CPU_CHAR luminance(t_img * img_in,t_img * img_out)
572 {
573  CPU_CHAR ret = ERR_NONE;
574  CPU_INT16S i,j;
575 
576  CPU_CHAR Luminance = 0;
577 
578  //Write Header
579  for(i=0;i<img_in->FileHeader_size;i++)
580  {
581  img_out->FileHeader[i] = img_in->FileHeader[i];
582  }
583  img_out->signature = img_in->signature;
584  img_out->depth = img_in->depth;
585  img_out->wi = img_in->wi;
586  img_out->he = img_in->he;
587  img_out->FileHeader_size = img_in->FileHeader_size;
588 
589  for(i=0;i< (img_in->he ) ;i++)
590  {
591  for(j=0 ; (j< img_in->wi );j++)
592  {
593  //calcultate luminance Y = 0,299 R + 0,587 G + 0,114 B
594  Luminance = (CPU_CHAR)( (CPU_FP32)img_in->Red[i][j] * 0.299
595  + (CPU_FP32)img_in->Green[i][j] * 0.587
596  + (CPU_FP32)img_in->Blue[i][j] * 0.114 );
597 
598  img_out->Red[i][j] = Luminance;
599  img_out->Green[i][j] = Luminance;
600  img_out->Blue[i][j] = Luminance;
601  }
602  }
603  return ret;
604 }
605 
606 
607 
608 /********************************************/
619 CPU_CHAR apply_linfilter(t_img * img_in,CPU_FP64 ** tab_filtre,CPU_INT16S filtersize,CPU_INT32U color,t_img * img_out)
620 {
621 
622  CPU_CHAR ret = ERR_NONE;
623  CPU_INT16S i,j,i_img,j_img;
624  CPU_FP64 one_pixel[c_color_size];
625  CPU_INT16S filter_range =(filtersize -1)/2;
626 
627  //Write Header
628  for(i=0;i<img_in->FileHeader_size;i++)
629  {
630  img_out->FileHeader[i] = img_in->FileHeader[i];
631  }
632  img_out->signature = img_in->signature;
633  img_out->depth = img_in->depth;
634  img_out->wi = img_in->wi;
635  img_out->he = img_in->he;
636  img_out->FileHeader_size = img_in->FileHeader_size;
637 
638 
639  for(i_img=0;i_img< (img_in->he ) ;i_img++)
640  {
641 
642  for(j_img=0 ; (j_img< img_in->wi );j_img++)
643  {
644 
645  one_pixel[c_Red] = 0;
646  one_pixel[c_Green] = 0;
647  one_pixel[c_Blue] = 0;
648  for (i=0;i<filtersize;i++)
649  {
650  for (j=0;j<filtersize;j++)
651  {
652  if( ((i_img-filter_range+i )>=0)
653  && ((j_img-filter_range+j )>=0)
654  && ((i_img-filter_range+i )<img_in->he)
655  && ((j_img-filter_range+j )<img_in->wi )
656  )
657  {
658  if ((color & BLUE)!=0)
659  {
660  one_pixel[c_Blue] = one_pixel[c_Blue]
661  + (CPU_FP64)(img_in->Blue[i_img-filter_range+i][j_img-filter_range+j]) * tab_filtre[i][j] ;
662  }else
663  {
664  one_pixel[c_Blue]= 0;
665  }
666  if ((color & RED)!=0)
667  {
668  one_pixel[c_Red] = one_pixel[c_Red]
669  + (CPU_FP64)(img_in->Red[i_img-filter_range+i][j_img-filter_range+j]) * tab_filtre[i][j] ;
670  }else
671  {
672  one_pixel[c_Red] = 0;
673  }
674  if ((color & GREEN)!=0)
675  {
676  one_pixel[c_Green]= one_pixel[c_Green]
677  + (CPU_FP64)(img_in->Green[i_img-filter_range+i][j_img-filter_range+j]) * tab_filtre[i][j] ;
678  }else
679  {
680  one_pixel[c_Green] = 0;
681  }
682  }
683  }
684  }
685  img_out->Red[i_img][j_img] = one_pixel[c_Red] ;
686  img_out->Green[i_img][j_img] = one_pixel[c_Green] ;
687  img_out->Blue[i_img][j_img] = one_pixel[c_Blue] ;
688  }
689  }
690  return ret;
691 }
692 
693 
694 /********************************************/
706 {
707  CPU_FP64 value = 0,value1 = 0,value2 = 0;
708 
709  value1 = 1.0/(2.0*PI*sig*sig);
710  value2 = (0.0 -(x*x+y*y))/(2*sig*sig);
711 
712  value = value1 * exp(value2);
713  return value;
714 
715 }
716 
717 
718 /********************************************/
727 CPU_VOID create_gauss_filter(CPU_FP64 ** tab_filtre,CPU_INT16S filtersize,CPU_FP64 sigma)
728 {
729  CPU_INT16U filter_range =(filtersize -1)/2;
730  CPU_INT16S i,j;
731 
732  CPU_FP64 value,sum=0,sum2=0;
733  for (i=0;i<filtersize;i++)
734  {
735  for (j=0;j<filtersize;j++)
736  {
737  value = conv_gauss(i-filter_range,j-filter_range,sigma);
738  sum = sum + value;
739  tab_filtre[i][j] = value;
740  }
741  }
742 
743  for (i=0;i<filtersize;i++)
744  {
745  for (j=0;j<filtersize;j++)
746  {
747  tab_filtre[i][j] = tab_filtre[i][j] / sum;
748  sum2 = sum2 + tab_filtre[i][j];
749  }
750  }
751 }
752 
753 
754 /********************************************/
763 {
764  CPU_INT16S i,j;
765  for (i=0;i<filtersize;i++)
766  {
767  for (j=0;j<filtersize;j++)
768  {
769  tab_filtre[i][j] = 1.0/filtersize;
770  }
771  }
772 }
773 
774 
775 /********************************************/
798 {
799  CPU_INT16S filtersize;
800  CPU_INT16S i,j;
801  switch(filtertype)
802  {
803  case 1:
804  filtersize = 3;
805  for(i=0;i<filtersize;i++)
806  {
807  for(j=0;j<filtersize;j++)
808  {
809  tab_filtre[i][j] = lapl_filter_1[i][j];
810 
811  }
812 
813  }
814  break;
815  case 2:
816  filtersize = 3;
817  for(i=0;i<filtersize;i++)
818  {
819  for(j=0;j<filtersize;j++)
820  {
821  tab_filtre[i][j] = lapl_filter_2[i][j];
822 
823  }
824 
825  }
826  break;
827  case 3:
828  filtersize = 3;
829  for(i=0;i<filtersize;i++)
830  {
831  for(j=0;j<filtersize;j++)
832  {
833  tab_filtre[i][j] = lapl_filter_3[i][j];
834 
835  }
836 
837  }
838  break;
839  case 4:
840  filtersize = 3;
841  for(i=0;i<filtersize;i++)
842  {
843  for(j=0;j<filtersize;j++)
844  {
845  tab_filtre[i][j] = lapl_filter_4[i][j];
846 
847  }
848 
849  }
850  break;
851  case 5:
852  filtersize = 5;
853  for(i=0;i<filtersize;i++)
854  {
855  for(j=0;j<filtersize;j++)
856  {
857  tab_filtre[i][j] = lapl_filter_5[i][j];
858 
859  }
860 
861  }
862  break;
863  default:
864  tab_filtre = 0;
865  break;
866  }
867 
868  return filtersize;
869 }
870 
871 
872 /********************************************/
882 CPU_CHAR apply_median_filter(t_img * img_in,CPU_INT16S filtersize,t_img * img_out)
883 {
884 
885  CPU_CHAR ret = ERR_NONE;
886  CPU_INT16S i,i_img,j_img;
887  CPU_INT16S filter_range =0;
888 
889  if(filtersize%2 != 1)
890  {
891  filtersize ++;
892  }
893  filter_range = (filtersize -1)/2;
894 
895  //Write Header
896  for(i=0;i<img_in->FileHeader_size;i++)
897  {
898  img_out->FileHeader[i] = img_in->FileHeader[i];
899  }
900  img_out->signature = img_in->signature;
901  img_out->depth = img_in->depth;
902  img_out->wi = img_in->wi;
903  img_out->he = img_in->he;
904  img_out->FileHeader_size = img_in->FileHeader_size;
905 
906 
907  for(i_img=0;i_img< (img_in->he ) ;i_img++)
908  {
909 
910  for(j_img=0 ; (j_img< img_in->wi );j_img++)
911  {
912  if( ((i_img-filter_range )>=0)
913  && ((j_img-filter_range )>=0)
914  && ((i_img-filter_range )<img_in->he)
915  && ((j_img-filter_range )<img_in->wi )
916  )
917  {
918 
919  img_out->Red[i_img][j_img] = get_median(img_in->Red,filter_range,i_img,j_img);
920  img_out->Green[i_img][j_img]= get_median(img_in->Green,filter_range,i_img,j_img);
921  img_out->Blue[i_img][j_img] = get_median(img_in->Blue,filter_range,i_img,j_img);
922 
923  }
924  }
925  }
926  return ret;
927 }
928 
929 /********************************************/
940 {
941  CPU_INT08U median;
942  CPU_INT16U ii,jj;
943  CPU_INT08U *table = (CPU_INT08U *)malloc(sizeof(CPU_INT08U)*(filter_range*2+1)*(filter_range*2+1));
944  for(ii =(0 - filter_range);ii<= filter_range;ii++)
945  {
946  for(jj =(0 - filter_range);jj<= filter_range;jj++)
947  {
948  table[ii+jj] = table2D[i+ii][j+jj];
949  }
950  }
951  qsort (table, (filter_range*2+1)*(filter_range*2+1), sizeof(CPU_INT08U), (int (*)(const void*, const void*))compare);
952  median = table[(filter_range*2+1)];
953  return median;
954 }
955 
956 
957 
966 {
967 
968  CPU_INT16S i,j;
969 
970  for(i=0;i<filtersize;i++)
971  {
972  for(j=0;j<filtersize;j++)
973  {
974  printf("%.2f ",tab_filtre[i][j]);
975  }
976  printf("\n");
977  }
978 }
CPU_VOID init_area(t_area *area, CPU_INT16U maxwidth, CPU_INT16U maxheight)
Initialize an area from 0,0 to given values.
#define BLUE
Definition: llips_general.h:32
const CPU_FP64 lapl_filter_4[3][3]
Definition: llips_general.c:75
CPU_CHAR apply_linfilter(t_img *img_in, CPU_FP64 **tab_filtre, CPU_INT16S filtersize, CPU_INT32U color, t_img *img_out)
Apply a predefined filter on the image.
#define GetGreen(c)
Definition: llips_general.h:81
CPU_INT16U y
Definition: llips_type.h:51
#define HEADER
Definition: llips_general.h:35
const CPU_FP64 lapl_filter_2[3][3]
Definition: llips_general.c:67
void CPU_VOID
Definition: llips_type.h:20
CPU_INT16U signature
Definition: llips_type.h:35
#define ERR_NONE
Definition: llips_general.h:46
float CPU_FP32
Definition: llips_type.h:29
CPU_INT08U FileHeader_size
Definition: llips_type.h:44
t_pixel BotRight
Definition: llips_type.h:63
CPU_INT32U maxi(CPU_INT32U a, CPU_INT32U b)
compare two CPU_INT32U to find the biggest
t_pixel BotLeft
Definition: llips_type.h:62
const CPU_FP64 lapl_filter_1[3][3]
Definition: llips_general.c:63
CPU_INT16S y
Definition: llips_type.h:57
CPU_INT16U vectormodule(t_vect vect)
Give module of a vector, in "pixel".
t_vect highlight_line(t_img *img, t_pixel pix1, t_pixel pix2, CPU_INT32U RGB)
Draw a line on image in a given color.
double CPU_FP64
Definition: llips_type.h:30
CPU_INT16U depth
Definition: llips_type.h:36
t_vect pixels_to_vector(t_pixel pix1, t_pixel pix2)
Convert two pixel into a vector.
CPU_INT32S compare(const CPU_VOID *a, const CPU_VOID *b)
Compare function for qsort function.
t_pixel TopLeft
Definition: llips_type.h:64
CPU_VOID display_img_value(t_img *img, CPU_INT16S colors)
Display each color of image in ascii.
Definition: llips_general.c:96
#define PI
Definition: llips_general.h:73
t_area pixel_to_area(t_pixel pix)
Convert a pixel into a area of 1 x 1.
Global include file for LLIPS.
CPU_INT32U wi
Definition: llips_type.h:37
CPU_VOID display_filter_value(CPU_FP64 **tab_filtre, CPU_INT08U filtersize)
Display values contained in a square filter.
#define RED
Definition: llips_general.h:34
unsigned char CPU_CHAR
Definition: llips_type.h:21
CPU_VOID highlight_area(t_img *img, t_area *area, CPU_INT32U RGB)
Draw a rectangular area on image in a given color.
CPU_CHAR apply_median_filter(t_img *img_in, CPU_INT16S filtersize, t_img *img_out)
Apply a median filter on an image.
CPU_VOID create_gauss_filter(CPU_FP64 **tab_filtre, CPU_INT16S filtersize, CPU_FP64 sigma)
Create a Gaussian filter used to smooth and image.
#define GREEN
Definition: llips_general.h:33
CPU_INT08U ** Red
Definition: llips_type.h:41
signed short CPU_INT16S
Definition: llips_type.h:26
CPU_FP64 conv_gauss(CPU_INT16S x, CPU_INT16S y, CPU_FP64 sig)
Gaussian convolution, used to create gaussian filter.
unsigned long CPU_INT32U
Definition: llips_type.h:27
CPU_INT08U FileHeader[MAX_HEADER_size]
Definition: llips_type.h:43
CPU_VOID printf_area(t_area *area)
Display area corner coordonate in a console.
const CPU_FP64 lapl_filter_5[5][5]
Definition: llips_general.c:79
CPU_INT16U x
Definition: llips_type.h:50
CPU_VOID create_average_filter(CPU_FP64 **tab_filtre, CPU_INT16S filtersize)
Create an average filter for smoothing.
t_pixel TopRight
Definition: llips_type.h:65
CPU_CHAR histogram(t_img *img_in, t_img *img_out)
Create an image with a view of histogram (RGBY).
CPU_INT08U ** Blue
Definition: llips_type.h:39
CPU_INT08U get_median(CPU_INT08U **table2D, CPU_INT16S filter_range, CPU_INT16S i, CPU_INT16S j)
Calcultate the median value of an area surrounding a pixel.
const CPU_FP64 lapl_filter_3[3][3]
Definition: llips_general.c:71
unsigned short CPU_INT16U
Definition: llips_type.h:25
CPU_INT08U ** Green
Definition: llips_type.h:40
#define PIXEL_8bit_RANGE
Definition: llips_general.h:29
CPU_INT16S x
Definition: llips_type.h:56
unsigned char CPU_INT08U
Definition: llips_type.h:23
CPU_CHAR luminance(t_img *img_in, t_img *img_out)
Create an image only luminance data (desaturated image)
CPU_INT16S create_laplacian_filter(CPU_FP64 **tab_filtre, CPU_INT08U filtertype)
Create a laplacian filter for edge detection (return matrix must have a size of 3 or 5) ...
#define GetRed(c)
Definition: llips_general.h:82
CPU_INT32U he
Definition: llips_type.h:38
CPU_CHAR color_filter(t_img *img_in, t_img *img_out, CPU_INT32U color)
Create an image with only the color provided.
#define GetBlue(c)
Definition: llips_general.h:80