Example #1
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;
}
Example #2
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; 	 
}