Beispiel #1
0
/*------------------------------------------------*/
int main(int argc,char **argv)
{
    int i,j,k;
    int length,width;
    float** MatriceImgR;
    float** MatriceImgI;
    float** MatriceImgM;
    char filename[255];

    printf("Veuillez entrer le nom de l'image a charger: ");
    scanf("%s", filename);
    
    /*Allocation memoire pour la matrice image*/
    MatriceImgR=LoadImagePgm(filename,&length,&width);
    MatriceImgI=fmatrix_allocate_2d(length,width);

    // Application de la fonction logarithmique
    RecalLog(MatriceImgR, length, width);
    Recal(MatriceImgR, length, width);
  
    /*Sauvegarde de MatriceImgR sous forme d'image pgm*/
    SaveImagePgm(NAME_IMG_OUT,MatriceImgR,length,width);

    /*Liberation memoire pour les matrices*/
    free_fmatrix_2d(MatriceImgR);
    free_fmatrix_2d(MatriceImgI);

    /*retour sans probleme*/ 
    printf("\n C'est fini ... \n\n\n");
    return 0;
}
Beispiel #2
0
int main(int argc,char** argv)
{
	int i,j,k;
  	int length,width;
  	float var;
  	int size_filter; 

  	float** image; 
	float** mask;  
  	float** degrad_image;  
   	
  	printf("Input the size of filter: ");
  	scanf("%d",&size_filter);
	
	printf("Input the variance of bruit : ");
  	scanf("%f",&var);

	image = LoadImagePgm(NAME_IMG_IN,&length,&width);
	mask = fmatrix_allocate_2d(length,width);
	degrad_image = fmatrix_allocate_2d(length,width);

	/* initialize array*/
	for(i=0;i<length;i++){
		for(j=0;j<width;j++){
			mask[i][j]=0.0;
			degrad_image[i][j]=0.0;
		}
	}

  	/* add blur to original image */
	blur_mask(mask,size_filter,length,width);
	convolution(degrad_image,image,mask,length,width);
	Recal(degrad_image,length,width);

	/* add noise to blur image */
	add_gaussian_noise(degrad_image,length,width,var);
	Recal(degrad_image,length,width);

  	/* save image */
	SaveImagePgm(NAME_IMG_OUT,degrad_image,length,width);
	system("display photograph_degraded.pgm&");
        
  
  	/* free memory*/
	free_fmatrix_2d(image);  
	free_fmatrix_2d(mask);
	free_fmatrix_2d(degrad_image);
  	
  	printf("\n Ending ... \n\n\n");
  	return 0; 	 
}
Beispiel #3
0
/*------------------------------------------------*/
int main(int argc,char **argv)
 {
  int i,j;
  int length,width;
  char BufSystVisuImg[100];

  //Lecture Image
  float** MatriceImg1=LoadImagePgm(NAME_IMG_IN,&length,&width);
  float** MatriceImg2=fmatrix_allocate_2d(length*4,width*4);

  //Interpolation plus proche voisin

  //utilisation de la division entière
  for(i=0;i<length*4;i++){
    for(j=0;j<width*4;j++){
      MatriceImg2[i][j] = MatriceImg1[i/4][j/4];
    }
  }


  //Sauvegarde
  SaveImagePgm(NAME_IMG_OUT,MatriceImg2,length*4,width*4);

  //Commande systeme: VISU
  strcpy(BufSystVisuImg,NAME_VISUALISER);
  strcat(BufSystVisuImg,NAME_IMG_OUT);
  strcat(BufSystVisuImg,".pgm&");
  printf(" %s",BufSystVisuImg);
  system(BufSystVisuImg);



  //==End=========================================================

  //Liberation memoire
  free_fmatrix_2d(MatriceImg1);
  free_fmatrix_2d(MatriceImg2);

  //retour sans probleme
  printf("\n C'est fini ... \n\n");
  return 0;
}
Beispiel #4
0
/*------------------------------------------------*/
int main(int argc,char **argv)
 {
  int i,j;
  int length,width;
  char BufSystVisuImg[100];

  //Lecture Image
  float** MatriceImg1R=LoadImagePgm(NAME_IMG_IN,&length,&width);
  float** MatriceImg1I=fmatrix_allocate_2d(length,width);

  float** MatriceImg2R=fmatrix_allocate_2d(length*4,width*4);
  float** MatriceImg2I=fmatrix_allocate_2d(length*4,width*4);

  //Initialisation des matrices
  for(i=0;i<length;i++)
    for(j=0;j<width;j++){
      MatriceImg1I[i][j]=0.0;
    }
  for(i=0;i<length*4;i++)
    for(j=0;j<width*4;j++){
      MatriceImg2R[i][j]=0.0;
      MatriceImg2I[i][j]=0.0;
    }


  //Mult par matrice alternante pour centrer le spectre d'amplitutdes
  ToggleCenter(MatriceImg1R,length,width);

  /*FFT*/
  FFTDD(MatriceImg1R,MatriceImg1I,length,width);


  /*zero padding*/
  CenterSmallMatInBigMat(MatriceImg2R,MatriceImg1R,4,length,width);
  CenterSmallMatInBigMat(MatriceImg2I,MatriceImg1I,4,length,width);


  /*IFFT*/
  IFFTDD(MatriceImg2R,MatriceImg2I,length*4,width*4);

  ToggleCenter(MatriceImg2R,length*4,width*4);

  /*Pour visu*/
  Recal(MatriceImg2R,length*4,width*4);


  //Sauvegarde
  SaveImagePgm(NAME_IMG_OUT,MatriceImg2R,length*4,width*4);

  //Commande systeme: VISU
  strcpy(BufSystVisuImg,NAME_VISUALISER);
  strcat(BufSystVisuImg,NAME_IMG_OUT);
  strcat(BufSystVisuImg,".pgm&");
  printf(" %s",BufSystVisuImg);
  system(BufSystVisuImg);



  //==End=========================================================

  //Liberation memoire
  free_fmatrix_2d(MatriceImg1R);
  free_fmatrix_2d(MatriceImg1I);
  free_fmatrix_2d(MatriceImg2R);
  free_fmatrix_2d(MatriceImg2I);


  //retour sans probleme
  printf("\n C'est fini ... \n\n");
  return 0;
}
int main(int argc,char** argv)
{
	int nb_iterations;
	int nbLevels=3;
  	int i,j,k,l,flag;
  	int length,width;
  	float var,sum1,sum2;
  	int size_filter;
	float** image;
	float** g;
	float** h;
	float** f;
	float** temp;
	float** temp1;
	float** haar;
	float** haar_inverse;
  		
  	printf("Input the size of low-pass filter : ");
  	scanf("%d",&size_filter);	

  	printf("Input the variance of noise : ");
  	scanf("%f",&var);
 
  	printf("Input the number of iterations (LANDWEBER): ");
  	scanf("%d",&nb_iterations);

	image=LoadImagePgm(NAME_IMG_IN, &length, &width);
	g=fmatrix_allocate_2d(length,width);
	f=fmatrix_allocate_2d(length,width);
	h=fmatrix_allocate_2d(length,width);
	temp=fmatrix_allocate_2d(length,width);
	temp1=fmatrix_allocate_2d(length,width);
	haar=fmatrix_allocate_2d(length,width);	
	haar_inverse=fmatrix_allocate_2d(length,width);

	for(i=0;i<length;i++){
		for(j=0;j<width;j++){
			g[i][j]=0.0;
			f[i][j]=0.0;
			h[i][j]=0.0;	
			temp[i][j]=0.0;
			temp1[i][j]=0.0;
			haar[i][j]=0.0;
			haar_inverse[i][j]=0.0;
		}
	}

  	/* add_gaussian_noise */
 	flou(h,size_filter,length,width);
	G(g,image,h,length,width);
	add_gaussian_noise(g,length,width,var);
	copy(f,g,length,width);

	k=1;
   	do{
		copy(temp1,f,length,width);
		sum1=0.0;
		sum2=0.0;
		for(i=0;i<length;i++){
			for(j=0;j<width;j++){
				sum1=sum1+SQUARE(image[i][j]-g[i][j]);
				sum2=sum2+SQUARE(image[i][j]-temp1[i][j]);
			}
		}
		printf("\n %d\t %f\t",k,10*log10(sum1/sum2));
	
		/* 1er etape : deconvolution with Landweber */
		for(l=0;l<nb_iterations;l++){
			update(temp1,temp,h,g,alpha,size_filter,length,width);
		}
		
		/* 2e etape : denoise with Haar coefficients */
		haar2D_complete(temp1,haar,nbLevels,length,width);
		for(i=0;i<length;i++){
			for(j=0;j<width;j++){
				if((i>length/pow(2,nbLevels)||j>width/pow(2,nbLevels))){
					if((SQUARE(haar[i][j])-3*SQUARE(var))>0){
						haar[i][j]=(SQUARE(haar[i][j])-3*SQUARE(var))/haar[i][j];
					}
					else{
						haar[i][j]=0.0;
					}
				}
				else{
					haar[i][j]=haar[i][j];	
				}
			}
		}
		ihaar2D_complete(haar,haar_inverse,nbLevels,length,width);
		flag=diff(haar_inverse,f,length,width);
		copy(f,haar_inverse,length,width);
		k++;
    	}while(k<=5);	
    	
	Recal(f,length,width);
		
    
	SaveImagePgm(NAME_IMG_OUT1,image,length,width);
	system("display photograph_original.pgm&");
	SaveImagePgm(NAME_IMG_OUT2,g,length,width);
	system("display photograph_degraded.pgm&");
	SaveImagePgm(NAME_IMG_OUT3,f,length,width);
	system("display photograph_restaured.pgm&");


	free_fmatrix_2d(image);  
	free_fmatrix_2d(f);
	free_fmatrix_2d(g);
	free_fmatrix_2d(h);
	free_fmatrix_2d(temp);
	free_fmatrix_2d(temp1);
	free_fmatrix_2d(haar);
	free_fmatrix_2d(haar_inverse);
  	
 	printf("\n Ending ... \n\n\n");
  	return 0; 	 
}
Beispiel #6
0
/*------------------------------------------------*/
int main(int argc,char **argv)
 {
  int i,j;
  int length,width;
  char BufSystVisuImg[100];

  //Lecture Image
  float** MatriceImg1=LoadImagePgm(NAME_IMG_IN,&length,&width);
  float** MatriceImg2=fmatrix_allocate_2d(length*4,width*4);

  //Interpolation bilinéaire

  int x,y,x1,y1; // x1 : x+1, y1 : y+1

  int fxpy;   //f(x^1,y) , x prime
  int fxpy1;  //f(x^1,y+1), x prime et y + 1
  int fxpyp;  //f(x^1,y^1), x et y primes

  for(i=0;i<length*4;i++){
    for(j=0;j<width*4;j++){

      x = j/4;
      y = i/4;

      if(y==127)
        y1 = 127;
      else
    y1 = y+1;

      if(x==127)
    x1 = 127;
      else
    x1 = x+1;

      //f(x^1,y)
      fxpy = MatriceImg1[y][x] +
    (int)(((j%4)*0.25)*(MatriceImg1[y][x1] - MatriceImg1[y][x]));

      //f(x^1,y+1)
      fxpy1 = MatriceImg1[y1][x] +
    (int)(((j%4)*0.25)*(MatriceImg1[y1][x1] - MatriceImg1[y1][x]));

      //f(x^1,y^1)
      fxpyp = fxpy + (int)(((i%4)*0.25)*(fxpy1 - fxpy));

      MatriceImg2[i][j] = fxpyp;
    }
  }


  //Sauvegarde
  SaveImagePgm(NAME_IMG_OUT,MatriceImg2,length*4,width*4);

  //Commande systeme: VISU
  strcpy(BufSystVisuImg,NAME_VISUALISER);
  strcat(BufSystVisuImg,NAME_IMG_OUT);
  strcat(BufSystVisuImg,".pgm&");
  printf(" %s",BufSystVisuImg);
  system(BufSystVisuImg);



  //==End=========================================================

  //Liberation memoire
  free_fmatrix_2d(MatriceImg1);
  free_fmatrix_2d(MatriceImg2);

  //retour sans probleme
  printf("\n C'est fini ... \n\n");
  return 0;
}
Beispiel #7
0
/*------------------------------------------------*/
int main(int argc,int** argv)
{
    int i,j,k,l;
    int length,width;
    float tau_L;
    float tau_H;
    float p_H;
    float sigma;
	
    /* Entrer des valeurs */
    printf("Entrez la valeur de tau_L: ");
    scanf("%f",&tau_L);
    printf("Entrez la valeur de tau_H: ");
    scanf("%f",&tau_H);
    printf("Entrez l'ecart type du filter Gaussien: ");
    scanf("%f",&sigma);
  
    // Chargement de l'image
    float** MatriceImgR=LoadImagePgm(NAME_IMG_IN,&length,&width);
    float** MatriceImgI=fmatrix_allocate_2d(length,width);
    float** gaussMaskI=fmatrix_allocate_2d(length,width);

    // Initialisation a zero de la partie imaginaire
    for(i=0;i<length;i++) 
    {
        for(j=0;j<width;j++) 
        {
	        MatriceImgI[i][j]=0.0;
	        gaussMaskI[i][j]=0.0;
        }
    }

    /* Implementer detecteur de Canny */
    int halfMaskWidth = 16;
    int maskSize = halfMaskWidth*2 + 1;

    ////////////////////////////////////////////
    // Etape 1: application d'un filtre Gaussien
    //
    float** mask = gaussianMask(halfMaskWidth, sigma);
    float** gaussMaskR = padWithZeros(mask, maskSize, maskSize, length, width);

    // Convolution
    float** convR = fmatrix_allocate_2d(length,width);
    float** convI = fmatrix_allocate_2d(length,width);
    FFTDD(MatriceImgR,MatriceImgI,length,width);
    FFTDD(gaussMaskR,gaussMaskI,length,width);
    MultMatrix(convR,convI,MatriceImgR,MatriceImgI,gaussMaskR,gaussMaskI,length,width);
    IFFTDD(convR,convI,length,width);

    // Sauvegarde de l'image filtree
    SaveImagePgm(NAME_IMG_CANNY,convR,length,width);

    /////////////////////////////////////////////
    // Etape 2: calcul du gradient a chaque pixel
    //
    float** gradientX = fmatrix_allocate_2d(length,width);
    float** gradientY = fmatrix_allocate_2d(length,width);
    float** gradientMagn = fmatrix_allocate_2d(length,width);
    float** gradientAngles = fmatrix_allocate_2d(length,width);
    float** contourAngles = fmatrix_allocate_2d(length,width);

    gradient(convR, gradientX, gradientY, length, width);
    gradientMagnitude(gradientX, gradientY, gradientMagn, length, width);
    gradientAngle(gradientX, gradientY, gradientAngles, contourAngles, length, width);

    // Sauvegarde de l'image du gradient
    SaveImagePgm(NAME_IMG_GRADIENT,gradientMagn,length,width);

    // Suppression des non-maximums
    deleteNonMaximums(gradientMagn,contourAngles,length,width);

    // Sauvegarde de l'image des non-maximum supprimes
    SaveImagePgm(NAME_IMG_SUPPRESSION,gradientMagn,length,width);

  /* Sauvegarder les images 
     TpIFT6150-2-gradient.pgm
     TpIFT6150-2-suppression.pgm
     TpIFT6150-2-canny.pgm */

    printf("Entrez la valeur de p_H: ");
    scanf("%f",&p_H);
 
   /* Implementer detecteur de Canny semi-automatique */
  
   /* Sauvegarder l'image TpIFT6150-2-cannySemiAuto.pgm */
   
   /*retour sans probleme*/  
 
  printf("\n C'est fini ... \n\n\n");
  return 0; 	 
}
Beispiel #8
0
/*------------------------------------------------*/
int main(int argc,char **argv)
{
    int i,j,k;
    int length,width;
    float** MatriceImgR1;
    float** MatriceImgR2;

    float** MatriceImgI1;
    float** MatriceImgI2;

    float** MatriceImgM1;
    float** MatriceImgP1;
    float** MatriceImgM2;
    float** MatriceImgP2;

    // Chargement de l'image carree
    MatriceImgR1 = LoadImagePgm(NAME_IMG_IN,&length,&width);

    // Translation de l'image en X
    MatriceImgR2 = translate(MatriceImgR1, length, width, 4, 0);

    // Sauvegarde de MatriceImgR2 sous forme d'image pgm
    SaveImagePgm(NAME_IMG_OUT,MatriceImgR2,length,width);

    // Allocation memoire pour la FFT
    MatriceImgI1=fmatrix_allocate_2d(length,width);
    MatriceImgI2=fmatrix_allocate_2d(length,width);
    MatriceImgM1=fmatrix_allocate_2d(length,width);
    MatriceImgP1=fmatrix_allocate_2d(length,width);
    MatriceImgM2=fmatrix_allocate_2d(length,width);
    MatriceImgP2=fmatrix_allocate_2d(length,width);

    // Initialisation a zero de toutes les matrices
    for(i=0;i<length;i++) 
    {
        for(j=0;j<width;j++) 
        {
	        MatriceImgI1[i][j]=0.0;
	        MatriceImgI2[i][j]=0.0;
	        MatriceImgM1[i][j]=0.0;
	        MatriceImgP1[i][j]=0.0;
	        MatriceImgM2[i][j]=0.0;
	        MatriceImgP2[i][j]=0.0;
        }
    }

    // Decalage des images pour obtenir un spectre au centre
    translateSpectrum(MatriceImgR1, length, width);
    translateSpectrum(MatriceImgR2, length, width);
  
    // FFT de l'image non decalee
    computeModuleAndPhase(MatriceImgR1, MatriceImgI1, MatriceImgM1, MatriceImgP1, length, width);

    // FFT de l'image decalee
    computeModuleAndPhase(MatriceImgR2, MatriceImgI2, MatriceImgM2, MatriceImgP2, length, width);

    // Sauvegarde des spectres
    SaveImagePgm(NAME_SPC_OUT_1,MatriceImgM1,length,width);
    SaveImagePgm(NAME_SPC_OUT_2,MatriceImgM2,length,width);
  
    // Impression du changement de phase pour une harmonique
    for(i = 1; i <= 2; i++)
    {
        printf("Harmonique %d,%d:\n", i, i);
        printf("1) Module: %.2f <--> %.2f\n", MatriceImgM1[i][i], MatriceImgM2[i][i]);
        printf("2) Phase: %.2f <--> %.2f\n", MatriceImgP1[i][i], MatriceImgP2[i][i]);
    }

    // Liberation memoire pour les matrices
    free_fmatrix_2d(MatriceImgR1);
    free_fmatrix_2d(MatriceImgR2);
    free_fmatrix_2d(MatriceImgI1); 
    free_fmatrix_2d(MatriceImgI2); 
    free_fmatrix_2d(MatriceImgM1);
    free_fmatrix_2d(MatriceImgP1);
    free_fmatrix_2d(MatriceImgM2);
    free_fmatrix_2d(MatriceImgP2);

    // Retour sans probleme
    printf("\n C'est fini ... \n\n\n");
    return 0; 	 
}