コード例 #1
0
void  
process(int x0, int y0, int width, int height, char* ims_name, char* imd_name){

  pnm imd = pnm_new(width, height, PnmRawPpm);
  pnm ims = pnm_load(ims_name);

  unsigned short r,g,b;

  for(int y=0; y<height; y++){
    for(int x=0; x<width; x++){
      for(int z=0; z<3; z++){	
	r = pnm_get_component(ims, y+y0, x+x0,PnmRed);
	g = pnm_get_component(ims, y+y0, x+x0,PnmGreen);
	b = pnm_get_component(ims, y+y0, x+x0,PnmBlue);
	pnm_set_component(imd,y,x,PnmRed, r);
	pnm_set_component(imd,y,x,PnmGreen, g);
       	pnm_set_component(imd,y,x,PnmBlue, b);
	
      }
    }
  }
  
  
  pnm_save(imd, PnmRawPpm, imd_name);
  pnm_free(imd);
  pnm_free(ims);
  
}
コード例 #2
0
void  
process(int num, char* ims_name, char* imd_name){

  pnm ims = pnm_load(ims_name);
  int height = pnm_get_height(ims);
  int width = pnm_get_width(ims);
  pnm imd = pnm_new(width, height, PnmRawPpm);

  unsigned short r,g,b;

  for(int y=0; y<height; y++){
    for(int x=0; x<width; x++){
      for(int z=0; z<3; z++){
	switch (num){
	case 1:
	  r = pnm_get_component(ims, y, x,PnmRed);
	  pnm_set_component(imd,y,x,PnmRed, r);
	  pnm_set_component(imd,y,x,PnmGreen, 0);
	  pnm_set_component(imd,y,x,PnmBlue, 0);
	  break;
	
	case 2:
	  g = pnm_get_component(ims, y, x,PnmGreen);
	  pnm_set_component(imd,y,x,PnmRed, 0);
	  pnm_set_component(imd,y,x,PnmGreen, g);
	  pnm_set_component(imd,y,x,PnmBlue, 0);
	  break;
	
	case 3:
	  b = pnm_get_component(ims, y, x,PnmBlue);
	  pnm_set_component(imd,y,x,PnmRed, 0);
	  pnm_set_component(imd,y,x,PnmGreen, 0);
	  pnm_set_component(imd,y,x,PnmBlue, b);
	  break;
	}
	
      }
    }
  }
  
  pnm_save(imd, PnmRawPpm, imd_name);
  pnm_free(imd);
  pnm_free(ims);
  
}
コード例 #3
0
ファイル: filter.c プロジェクト: Alkinn/traitement-images
void
process(int factor, char* filter_name,char* ims_name, char* imd_name) {

    pnm ims = pnm_load(ims_name);
    int cols = pnm_get_width(ims);
    int rows = pnm_get_height(ims);

    int new_cols = factor*cols;
    int new_rows = factor*rows;

    pnm imw = pnm_new(new_cols, rows, PnmRawPpm);
    pnm imd = pnm_new(new_cols, new_rows, PnmRawPpm);


    // ===== Columns interpolation =====
    for(int i=0; i<rows; i++) {
        for(int j=0; j<new_cols; j++) {
            float new_j = (float)j / factor;

            float WF = 0;
            if (strcmp(filter_name, "box")== 0)
                WF = 0.5;
            else if (strcmp(filter_name, "tent")== 0)
                WF = 1.0;
            else if (strcmp(filter_name, "bell")== 0)
                WF = 1.5;
            else if (strcmp(filter_name, "mitch")== 0)
                WF = 2.0;

            float left = new_j - WF;
            float right = new_j + WF;

            int l_int = floor(left);
            int r_int = floor(right);

            float S = 0.0;

            for (int k=l_int; k <= r_int; k++) {

                float h = 0.0;
                if (strcmp(filter_name, "box")== 0)
                    h = box((float)k-new_j);
                else if (strcmp(filter_name, "tent")== 0)
                    h = tent((float)k-new_j);
                else if (strcmp(filter_name, "bell")== 0)
                    h = bell((float)k-new_j);
                else if (strcmp(filter_name, "mitch")== 0)
                    h = mitch((float)k-new_j);

                if (k<0) {
                    S += pnm_get_component(ims, i, 0, 0)*h;
                }
                else if (k>=cols) {
                    S += pnm_get_component(ims, i, cols-1, 0)*h;
                }
                else {
                    S += pnm_get_component(ims, i, k, 0)*h;
                }
            }


            for (int c=0; c<3; c++) {
                pnm_set_component(imw, i, j, c, (unsigned short) S);
            }
        }
    }


    // ===== Rows interpolation =====
    for(int i=0; i<new_rows; i++) {
        for(int j=0; j<new_cols; j++) {
            float new_i = (float) i / factor;

            float WF = 0;
            if (strcmp(filter_name, "box")== 0)
                WF = 0.5;
            else if (strcmp(filter_name, "tent")== 0)
                WF = 1.0;
            else if (strcmp(filter_name, "bell")== 0)
                WF = 1.5;
            else if (strcmp(filter_name, "mitch")== 0)
                WF = 2.0;

            float above = new_i - WF;
            float below = new_i + WF;

            int a_int = floor(above);
            int b_int = floor(below);

            float S = 0.0;

            for (int k=a_int; k <= b_int; k++) {

                float h = 0.0;
                if (strcmp(filter_name, "box")== 0)
                    h = box((float)k-new_i);
                else if (strcmp(filter_name, "tent")== 0)
                    h = tent((float)k-new_i);
                else if (strcmp(filter_name, "bell")== 0)
                    h = bell((float)k-new_i);
                else if (strcmp(filter_name, "mitch")== 0)
                    h = mitch((float)k-new_i);

                if (k<0) {
                    S += pnm_get_component(imw, 0, j, 0)*h;
                }
                else if (k>=rows) {
                    S += pnm_get_component(imw, rows-1, j, 0)*h;
                }
                else {
                    S += pnm_get_component(imw, k, j, 0)*h;
                }
            }

            for (int c=0; c<3; c++) {
                pnm_set_component(imd, i, j, c, (unsigned short) S);
            }
        }
    }



    pnm_save(imd, PnmRawPpm, imd_name);
    pnm_free(ims);
    pnm_free(imw);
    pnm_free(imd);

}
コード例 #4
0
void  
process(int min, int max, char* ims_name, char* imd_name){

  pnm ims = pnm_load(ims_name);
  int height = pnm_get_height(ims);
  int width = pnm_get_width(ims);
  pnm imd = pnm_new(width, height, PnmRawPpm);

  unsigned short r,g,b,min_r,min_g,min_b,max_r,max_g,max_b;

  min_r = 255;
  min_g = 255;
  min_b = 255;
  max_r = 0;
  max_g = 0;
  max_b = 0;

  for(int y=0; y<height; y++){
    for(int x=0; x<width; x++){
      for(int z=0; z<3; z++){
	r = pnm_get_component(ims, y, x, PnmRed);
	g = pnm_get_component(ims, y, x, PnmGreen);
	b = pnm_get_component(ims, y, x, PnmBlue);
	
	if(r < min_r){
	  min_r = r;
	}
	
	if(g < min_g){
	  min_g = g;
	}

	if(b < min_b){
	  min_b = b;
	}

	if(r > max_r){
	  max_r = r;
	}
	
	if(g > max_g){
	  max_g = g;
	}

	if(b > max_b){
	  max_b = b;
	}
      }
    }
  }

  unsigned short normalize_r, normalize_g, normalize_b;

  for(int y=0; y<height; y++){
    for(int x=0; x<width; x++){
      for(int z=0; z<3; z++){

	normalize_r = (max - min) / (max_r - min_r) * pnm_get_component(ims, y, x, PnmRed) + (min * max_r - max * min_r) / (max_r - min_r);

	normalize_g = (max - min) / (max_g - min_g) * pnm_get_component(ims, y, x, PnmGreen) + (min * max_g - max * min_g) / (max_g - min_g);
	
	normalize_b = (max - min) / (max_b - min_b) * pnm_get_component(ims, y, x, PnmBlue) + (min * max_b - max * min_b) / (max_b - min_b);
	
	pnm_set_component(imd, y, x, PnmRed, normalize_r);
	pnm_set_component(imd, y, x, PnmGreen, normalize_g);
       	pnm_set_component(imd, y, x,PnmBlue, normalize_b);
	
      }
    }
  }
  
  printf("****** valeurs min r g b ****** \n");
  printf("%u \n", min_r);
  printf("%u \n", min_g);
  printf("%u \n", min_b);
  printf("****** valeurs max r g b ****** \n");
  printf("%u \n", max_r);
  printf("%u \n", max_g);
  printf("%u \n", max_b);
  printf("****** valeurs normalize r g b ****** \n");
  printf("%u \n", normalize_r);
  printf("%u \n", normalize_g);
  printf("%u \n", normalize_b);

  pnm_save(imd, PnmRawPpm, imd_name);
  pnm_free(imd);
  pnm_free(ims);
  
}
コード例 #5
0
void process(char* ims_name, char* imd_name, char* filter, int d0, int n, int w, int u0, int v0) {

  
  /* Selection du filtre */
  /*float (*function_pointer) (double, double, double, double, int, int, int);
  if(strcmp(filter,"lp") == 0){
    printf("low pass filter\n");
    function_pointer = lp;
  }
  else if(strcmp(filter,"hp") == 0){
    printf("high pass filter\n");
    function_pointer = hp;
  }
  else if(strcmp(filter,"br") == 0){
    printf("band reject filter\n");
    function_pointer = br;
  }
  else if(strcmp(filter,"bp") == 0){
    printf("band pass filter\n");
    function_pointer = br;
  }
  else if(strcmp(filter,"no") == 0){
    printf("rejet d'encoche \n");
    function_pointer = no;
  }
  else {
    printf("unknown filter,\n filters avalaible: lp, hp, br, bp, no");
    assert(false);
    }*/


  pnm ims = pnm_load(ims_name);
  int width  = pnm_get_width(ims);
  int height = pnm_get_height(ims);
  pnm imd = pnm_new(width, height, PnmRawPpm);
  
  unsigned short * image = (unsigned short *) malloc(height * width * sizeof(unsigned short));
  fftw_complex * freq_repr = (fftw_complex *) fftw_malloc(height* width * sizeof(fftw_complex));

  image = pnm_get_channel(ims, image, PnmRed);
  freq_repr = fft_forward(height, width, image);

  float * as = (float *) malloc(sizeof(float) * height * width);
  float * ps = (float *) malloc(sizeof(float) * height * width);
  fft_fr_to_spectra(width, height, freq_repr, as, ps);

  
  pnm imd2 = pnm_new(width, height, PnmRawPpm);
  for(int y = 0; y < height; y++)
    for(int x = 0; x < width; x++)
      for(int z = 0; z < 3; z++)
	pnm_set_component(imd2,y,x,z,as[x+y*height]);  
  pnm_save(imd2, PnmRawPpm, "toto.ppm");

  //float d_u_v;

  for(int j=0; j<height; j++){
    for(int i=0; i<width; i++){
      //d_u_v  = sqrt((float)(j-height/2)*(j-height/2)+(float)(i-width/2)*(i-width/2));       
      //as[i+j*width] = function_pointer(i, j, u0, v0, n, w, d0) * as[i+j*width];
      as[i+j*width] = low_pass(d0, n, d((float) i-width/2,(float) j-height/2)) * as[i+j*width];
      //printf("%f \n", hp(i, j, u0, v0, n, w, d0));
      //printf("%d \n", function_pointer(i, j, u0, v0, n, w, d0));
    }
  }
  
  pnm imd3 = pnm_new(width, height, PnmRawPpm);
  for(int y = 0; y < height; y++)
    for(int x = 0; x < width; x++)
      for(int z = 0; z < 3; z++)
	pnm_set_component(imd3,y,x,z,as[x+y*height]); 
  pnm_save(imd3, PnmRawPpm, "toto2.ppm");
  

  fft_spectra_to_fr(height,width,as,ps, freq_repr);
  
  image = fft_backward(height, width, freq_repr);
  
  for(int y = 0; y < height; y++)
    for(int x = 0; x < width; x++)
      for(int z = 0; z < 3; z++)
	pnm_set_component(imd,y,x,z,image[x+y*height]);
  
  pnm_save(imd, PnmRawPpm, imd_name);
  
  free(image);

}
コード例 #6
0
void LAB2RGB(pnm pimd, float* LAB, int cols, int rows) {

	float* LMS = malloc(cols * rows * 3 * sizeof(float));
	float tmp;

	// Conversion du format LAB au format LMS
	for (int i = 0; i < rows; ++i)
 	{
 		for (int j = 0; j < cols; ++j)
 		{
 			for (int k = 0; k < 3; ++k)
 			{
 				tmp = 0.0;

 				for (int m = 0; m < 3; ++m)
 				{
 					tmp += LAB2LMS[k][m] * *LAB;
 					LAB++;	
 				}
 				LAB -= 3;

 				// Conversion de log(LMS) en LMS
 				tmp = pow(10,tmp);
 				
 				*LMS = tmp;

 				LMS++;
 			}
 			LAB += 3;
 		}
 	}

 	LMS -= cols * rows * 3;
 	LAB -= cols * rows * 3;

 	// Conversion de LMS en RGB
 	for (int i = 0; i < rows; ++i)
 	{
 		for (int j = 0; j < cols; ++j)
 		{
 			for (int k = 0; k < 3; ++k)
 			{
 				tmp = 0.0;
 				for (int m = 0; m < 3; ++m)
 				{
 					tmp += LMS2RGB[k][m] * *LMS;
 					LMS++;	
 				}
 				LMS -= 3;
 				tmp = tmp;
 				if (tmp >= 255.0)
 				{
 					tmp = 255.0;
 				}
 				if (tmp <= 0.0)
 				{
 					tmp = 0.0;
 				}

 				pnm_set_component(pimd, i, j, k, (short) tmp);
 			}
 			LMS += 3;
 		}
 	}

 	LMS -= cols * rows * 3;

 	free(LMS);
}