IntensityImage * StudentPreProcessing::stepEdgeDetection(const IntensityImage &image) const {

	
	/*
	const std::vector<std::vector<double>> maskData {
		{ 0, 1, 0 },
		{ 1,-4, 1 },
		{ 0, 1, 1 }
	};
	*/
	
	/*const std::vector<std::vector<double>> maskData{
		{ 0, 0, 0, 1, 1, 1, 0, 0, 0 },
		{ 0,0,0,1,1,1,0,0,0 },
		{ 0,0,0,1,1,1,0,0,0 },
		{ 1,1,1,-4,-4,-4,0,0,0 },
		{ 1,1,1,-4,-4,-4,0,0,0 },
		{ 1,1,1,-4,-4,-4,0,0,0 },
		{ 0,0,0,1,1,1,0,0,0 },
		{ 0,0,0,1,1,1,0,0,0 },
		{ 0,0,0,1,1,1,0,0,0 }
	};
	
	const std::vector<std::vector<double>> maskData {
		{ 0.5, 1, 0.5 },
		{ 1,  -6, 1 },
		{ 0.5, 1, 0.5 }
	};
	*/
	
	const std::vector<std::vector<double>> laplacianMaskKernel {
		{ 1, 1, 1 },
		{ 1,-8, 1 },
		{ 1, 1, 1 }
	};

	const std::vector<std::vector<double>> gaussianMaskKernel {
		{ 1, 2, 1 },
		{ 2, 3, 2 },
		{ 1, 2, 1 }
	};

	Mask gaussianMask(gaussianMaskKernel, 3, 3, 15);
	
	IntensityImage * result = applyMaskToImage(image, gaussianMask);

	Mask laplacianMask(laplacianMaskKernel, 3, 3, 8, true);

	IntensityImage * finalResult = applyMaskToImage(image, laplacianMask);

	return finalResult;
}
Пример #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; 	 
}