PIPS
gaussian_noise_reduce.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 
4 #include "tools.h"
5 
6 /*
7  GAUSSIAN_NOISE_ REDUCE
8  apply 5x5 Gaussian convolution filter, shrinks the image by 4 pixels in each direction, using Gaussian filter found here:
9  http://en.wikipedia.org/wiki/Canny_edge_detector
10  code dl from http://code.google.com/p/fast-edge
11 */
12 void gaussian_noise_reduce(int w, int h, float img_in[w*h], float img_out[w*h])
13 {
14  int x, y, max_x, max_y;
15  max_x = w - 2;
16  max_y = w * (h - 2);
17  for (y = w * 2; y < max_y; y += w) {
18  for (x = 2; x < max_x; x++) {
19  img_out[x + y] = (2 * img_in[x + y - 2 - w - w] +
20  4 * img_in[x + y - 1 - w - w] +
21  5 * img_in[x + y - w - w] +
22  4 * img_in[x + y + 1 - w - w] +
23  2 * img_in[x + y + 2 - w - w] +
24  4 * img_in[x + y - 2 - w] +
25  9 * img_in[x + y - 1 - w] +
26  12 * img_in[x + y - w] +
27  9 * img_in[x + y + 1 - w] +
28  4 * img_in[x + y + 2 - w] +
29  5 * img_in[x + y - 2] +
30  12 * img_in[x + y - 1] +
31  15 * img_in[x + y] +
32  12 * img_in[x + y + 1] +
33  5 * img_in[x + y + 2] +
34  4 * img_in[x + y - 2 + w] +
35  9 * img_in[x + y - 1 + w] +
36  12 * img_in[x + y + w] +
37  9 * img_in[x + y + 1 + w] +
38  4 * img_in[x + y + 2 + w] +
39  2 * img_in[x + y - 2 + w + w] +
40  4 * img_in[x + y - 1 + w + w] +
41  5 * img_in[x + y + w + w] +
42  4 * img_in[x + y + 1 + w + w] +
43  2 * img_in[x + y + 2 + w + w]) / 159;
44  }
45  }
46 }
47 
48 int main(int argc, char **argv) {
49  int n;
50  float (*in)[n*n], (*out)[n*n];
51  int i;
52  if (argc < 3)
53  {
54  fprintf(stderr, "Usage: %s size data_file\n", argv[0]);
55  return 1;
56  }
57  n = atoi(argv[1]);
58  in=malloc(n*n);
59  out=malloc(n*n);
60  init_data_file(argv[2]);
61  init_data_float(in, n*n);
63  for(i=0;i<n*n;i++) {
64  (*out)[i]=0;
65  }
66  gaussian_noise_reduce(n,n,*in,*out);
67  print_array_float(out, n*n);
68  free(in);free(out);
69  return 0;
70 }
71 
72 
73 
static FILE * out
Definition: alias_check.c:128
void gaussian_noise_reduce(int w, int h, float img_in[w *h], float img_out[w *h])
int main(int argc, char **argv)
void * malloc(YYSIZE_T)
void free(void *)
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
static char * x
Definition: split_file.c:159
void close_data_file()
Definition: tools.c:48
void print_array_float(const char *name, const float *arr, const unsigned int n)
Definition: tools.c:54
int init_data_float(float *ptr, const unsigned int n)
Definition: tools.c:125
void init_data_file(const char *data_file)
Definition: tools.c:36