/* ------------------------------------------------------------------------------------------ */ void routine_generate_sample(uint8 background, uint8 foreground, char *filename, char *dst_path) /* ------------------------------------------------------------------------------------------ */ { // creation d'un carre d'intensite foreground sur un fond d'intensite background char complete_filename[1024]; //int i, j; long size = 32; long i0, i1, j0, j1; uint8 **X; i0 = 0; i1 = size-1; j0 = 0; j1 = size-1; X = ui8matrix(0, size-1, 0, size-1); init_ui8matrix_param(X, 0, size-1, 0, size-1, background, 0, 0); init_ui8matrix_param(X, size/4, size-1-size/4, size/4, size-1-size/4, foreground, 0, 0); generate_path_filename_extension(dst_path, filename, "pgm", complete_filename); puts(complete_filename); SavePGM_ui8matrix(X, 0, size-1, 0, size-1, complete_filename); free_ui8matrix(X, 0, size-1, 0, size-1); }
/* ------------------------------------------------------------------------------------------------------- */ void convolve_kernel_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, float32 **K, int radius, uint8 **Y) /* ------------------------------------------------------------------------------------------------------- */ { int i, j; int ii, jj; uint8 **T; float32 y; T = ui8matrix(i0-radius, i1+radius, j0-radius, j1+radius); zero_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius); dup_ui8matrix(X, i0, i1, j0, j1, T); extend_ui8matrix(T, i0, i1, j0, j1, radius); for(i=i0; i<=i1; i++) { for(j=j0; j<=j1; j++) { y = 0.0f; for(ii=-radius; ii<=radius; ii++) { for(jj=-radius; jj<=radius; jj++) { y += T[i+ii][j+jj] * K[ii][jj]; } } if(y<0.0f) y = 0.0f; if(y>255.0f) y = 255.0f; Y[i][j] = (uint8) y; } } free_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius); }
/* ----------------------------------------------------------------------------------------------------------- */ void routine_median_filter(char *src_path, char *noise_path, char *filename0, char *filename, char *denoise_path) /* ----------------------------------------------------------------------------------------------------------- */ { char complete_filename[1024]; char *sep; int radius; int k; int ndigit = 1; long i0, i1, j0, j1; uint8 **X0, **X, **Y; float32 p; // chargement de l'image sans bruit dans X0 et de l'image bruitee dans X // Y doit contenir l'image traitee generate_path_filename_extension(src_path, filename0, "pgm", complete_filename); X0 = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); generate_path_filename_extension(noise_path, filename, "pgm", complete_filename); X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); Y = ui8matrix(i0, i1, j0, j1); // ------------------- // -- median kernel -- // ------------------- sep = "_M_"; radius = 1; // parametre du bloc de code k = radius; median_ui8matrix(X, i0, i1, j0, j1, radius, Y); p = psnr(X0, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(denoise_path, filename, sep, k, ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); // ajouter ici d'autre instances du bloc de code avec d'autres valeurs de radius }
/* ---------------------------------------------------------------------- */ void routine_impulse_noise(char *src_path, char *filename, char *noise_path) /* ---------------------------------------------------------------------- */ { char complete_filename[1024]; char *sep = "_IN_"; // Impulse Noise float32 percent; int ndigit = 3; // codage du 3 chiffres du pourcentage de bruit impulsionnel dans le nom du fichier long i0, i1, j0, j1; uint8 **X, **Y; float32 p; // chargement de l'image et allocation d'une image avec des bords generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename); X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); Y = ui8matrix(i0, i1, j0, j1); percent = 0.5f; // parametre du bloc de code //printf("%4d : ",(int)(10.0f*percent)); impulse_noise_ui8matrix(X, i0, i1, j0, j1, percent/100.0f, Y); p = psnr(X, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(noise_path, filename, sep, (int)(10.0f*percent), ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); // ajouter ici d'autre instances du bloc de code avec d'autres valeurs de percent }
/* --------------------------------------------------------------------------------- */ void median_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, int radius, uint8 **Y) /* --------------------------------------------------------------------------------- */ { int i, j; int ii, jj; int k; uint8 **T; float32 y; uint8 *vec; vec = ui8vector(0,(2*radius+1)*(2*radius+1)); T = ui8matrix(i0-radius, i1+radius, j0-radius, j1+radius); zero_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius); dup_ui8matrix(X, i0, i1, j0, j1, T); extend_ui8matrix(T, i0, i1, j0, j1, radius); for(i=i0; i<=i1; i++) { for(j=j0; j<=j1; j++) { k = 0; for(ii=-radius; ii<=radius; ii++) { for(jj=-radius; jj<=radius; jj++) { //y += T[i+ii][j+jj] * K[ii][jj]; vec[k]= T[i+ii][j+jj];//X[ii][jj]; k ++; } } if(y<0.0f) y = 0.0f; if(y>255.0f) y = 255.0f; sort_selection_ui8vector(vec,0,k); Y[i][j] = (uint8) vec[radius*radius]; } } free_ui8matrix(T, i0-radius, i1+radius, j0-radius, j1+radius); //free_ui8vector(vec); }
/* ---------------------------------------------------------- */ void routine_fgl(char *src_path, char *filename, char *dst_path) /* ---------------------------------------------------------- */ { char complete_filename[1024]; char *sep1 = "_FGL_"; char *sep2 = "_FGLG_"; int k; int ndigit = 2; uint8 **X, **Y, **Z; long i0, i1, j0, j1; float32 alpha; generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename); X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); Y = ui8matrix(i0, i1, j0, j1); Z = ui8matrix(i0, i1, j0, j1); /*alpha = 0.4; // parametre k = (int) (10*alpha); fgl_ui8matrix(X, i0, i1, j0, j1, alpha, Y); //roberts_ui8matrix(Y, i0, i1, j0, j1, Z); sobel_ui8matrix(Y, i0, i1, j0, j1, Z); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep1, k, ndigit, "pgm", complete_filename); puts(complete_filename); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep2, k, ndigit, "pgm", complete_filename); puts(complete_filename); SavePGM_ui8matrix(Z, i0, i1, j0, j1, complete_filename);*/ alpha = 0.8; // parametre k = (int) (10*alpha); fgl_ui8matrix(X, i0, i1, j0, j1, alpha, Y); roberts_ui8matrix(Y, i0, i1, j0, j1, Z); //sobel_ui8matrix(Y, i0, i1, j0, j1, Z); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep1, k, ndigit, "pgm", complete_filename); puts(complete_filename); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep2, k, ndigit, "pgm", complete_filename); puts(complete_filename); SavePGM_ui8matrix(Z, i0, i1, j0, j1, complete_filename); double_intensity_ui8matrix(Z, i0, i1, j0, j1, Z); double_intensity_ui8matrix(Z, i0, i1, j0, j1, Z); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, "VISU", k, ndigit, "pgm", complete_filename); puts(complete_filename); SavePGM_ui8matrix(Z, i0, i1, j0, j1, complete_filename); // free free_ui8matrix(X, i0, i1, j0, j1); free_ui8matrix(Y, i0, i1, j0, j1); }
/* -------------------------------- */ void test_histogram_equalization(void) /* -------------------------------- */ { puts("=================================="); puts("=== test_histogram_equalization==="); puts("=================================="); long i0, i1, j0, j1; char *filename; char complete_filename[1024]; char *src_path = IMAGE_SRC_PATH; char *noise_path = IMAGE_NOISE_PATH; char *denoise_path = IMAGE_DENOISE_PATH; uint8 **X, **Y; filename = "carre64_GN_20"; generate_path_filename_extension(noise_path, filename, "pgm", complete_filename); puts(complete_filename); X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); Y = ui8matrix(i0, i1, j0, j1); ui32histogram_equalize_ui8matrix(X, i0, i1, j0, j1, Y); generate_path_filename_sep_extension(denoise_path, filename, "_HISTO_", "pgm", complete_filename); puts(complete_filename); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); // filename = "Hawkes_Bay"; filename = "femme"; generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename); X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); Y = ui8matrix(i0, i1, j0, j1); ui32histogram_equalize_ui8matrix(X, i0, i1, j0, j1, Y); generate_path_filename_sep_extension(denoise_path, filename, "_HISTO_", "pgm", complete_filename); puts(complete_filename); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); printf("\n -> VOIR FICHIERS DE SORTIES\n"); }
// -------------------------------------------- void bench_mandelbrot_SIMD(int n, int max_iter) // -------------------------------------------- { // ne rien modifier dans cette fonction int h, w; float a0, a1, b0, b1; vuint32 **M32; uint32 **wM32; uint8 **M8; // chronometrie int iter, niter = 4; int run, nrun = 5; double t0, t1, dt, tmin, t; double cycles; //puts("---------------------------"); //puts("-- bench_mandelbrot_SIMD --"); //puts("---------------------------"); h = w = n; M32 = vui32matrix(0, h-1, 0, w/4-1); M8 = ui8matrix(0, h-1, 0, w-1); wM32 = (uint32**) M32; // ne pas changer a0 = -1.5; a1 = +0.5; b0 = -1.0; b1 = +1.0; CHRONO(calc_mandelbrot_SIMD_F32(M32, h, w, a0, a1, b0, b1, max_iter), cycles); printf("SIMD F32: %10.2f\n", cycles/(n*n)); CHRONO(calc_mandelbrot_SIMD_I32(M32, h, w, a0, a1, b0, b1, max_iter), cycles); // facultatif printf("SIMD I32: %10.2f\n\n", cycles/(n*n)); DEBUG(convert_ui32matrix_ui8matrix(wM32, 0, h-1, 0, w-1, M8)); DEBUG(SavePGM_ui8matrix(M8, 0, h-1, 0, w-1, "M_v.pgm")); free_vui32matrix(M32, 0, h-1, 0, w/4-1); free_ui8matrix(M8, 0, h-1, 0, w-1); }
/* ------------------------------------------------------------ */ void routine_sobel(char *src_path, char *filename, char *dst_path) /* ------------------------------------------------------------ */ { char complete_filename[1024]; char *sep = "_S"; uint8 **X, **Y; long i0, i1, j0, j1; generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename); X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); Y = ui8matrix(i0, i1, j0, j1); sobel_ui8matrix(X, i0, i1, j0, j1, Y); generate_path_filename_sep_extension(dst_path, filename, sep, "pgm", complete_filename); puts(complete_filename); double_intensity_ui8matrix(Y, i0, i1, j0, j1, Y); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); free_ui8matrix(Y, i0, i1, j0, j1); }
/* ----------------------------------------------------------------------------------------- */ void routine_contour_threshold(char *src_path, char *filename, uint8 threshold, char *dst_path) /* ----------------------------------------------------------------------------------------- */ { char complete_filename[1024]; char *sep; int k; int optimal_threhsold; int ndigit = 3; // nombre de chiffres pour coder le seuil uint8 value = 255; uint8 **X, **Y; long i0, i1, j0, j1; puts("================================="); printf(" === %s ===\n", filename); puts("================================="); k = threshold; generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename); X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); Y = ui8matrix(i0, i1, j0, j1); display_ui8matrix(X, i0, i1, j0, j1, "%4d", filename); puts("\n=============================================\n"); sep = "_T_"; threshold_ui8matrix(X, i0, i1, j0, j1, threshold, value, Y); display_ui8matrix(Y, i0, i1, j0, j1, "%4d", "Thresold"); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename); puts(complete_filename); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); puts("\n=============================================\n"); sep = "_OTSU_"; optimal_threhsold = calc_otsu_threshold_ui8matrix(X, i0, i1, j0, j1); k = optimal_threhsold; threshold_ui8matrix(X, i0, i1, j0, j1, optimal_threhsold, value, Y); display_ui8matrix(Y, i0, i1, j0, j1, "%4d", "Otsu threshold"); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename); puts(complete_filename); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); free_ui8matrix(Y, i0, i1, j0, j1); }
/* --------------------------------------------------------------------------------- */ void routine_threshold(char *src_path, char *filename, uint8 threshold, char *dst_path) /* --------------------------------------------------------------------------------- */ { char complete_filename[1024]; char *sep = "_T_"; int k; int ndigit = 3; uint8 value = 255; uint8 **X, **Y; long i0, i1, j0, j1; k = threshold; generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename); X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); Y = ui8matrix(i0, i1, j0, j1); threshold_ui8matrix(X, i0, i1, j0, j1, threshold, value, Y); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, k, ndigit, "pgm", complete_filename); puts(complete_filename); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); free_ui8matrix(Y, i0, i1, j0, j1); }
// ---------------------------------------------- void bench_mandelbrot_scalar(int n, int max_iter) // ---------------------------------------------- { // ne rien modifier dans cette fonction int h, w; int i0, i1, j0, j1; float a0, a1, b0, b1; uint32 **M32; uint8 **M8; // chronometrie int iter, niter = 4; int run, nrun = 5; double t0, t1, dt, tmin, t; double cycles; //puts("-----------------------------"); //puts("-- bench_mandelbrot_scalar --"); //puts("-----------------------------"); h = w = n; M32 = ui32matrix(0, h-1, 0, w-1); M8 = ui8matrix(0, h-1, 0, w-1); a0 = -1.5; a1 = +0.5; b0 = -1.0; b1 = +1.0; CHRONO(calc_mandelbrot_scalar(M32, h, w, a0, a1, b0, b1, max_iter), cycles); printf("scalar: %10.2f\n", cycles/(n*n)); DEBUG(convert_ui32matrix_ui8matrix(M32, 0, h-1, 0, w-1, M8)); DEBUG(SavePGM_ui8matrix(M8, 0, h-1, 0, w-1, "M_scalar.pgm")); free_ui32matrix(M32, 0, h-1, 0, w-1); free_ui8matrix(M8, 0, h-1, 0, w-1); }
/* ----------------------------------------------------------------------------------------------------------- */ void routine_smooth_filter(char *src_path, char *noise_path, char *filename0, char *filename, char *denoise_path) /* ----------------------------------------------------------------------------------------------------------- */ { char complete_filename[1024]; char *sep; int k; float32 sigma; int radius; int ndigit; long i0, i1, j0, j1; uint8 **X0, **X, **Y; float32 **K; float32 p; // chargement de l'image bruitee dans X, et de l'image sans bruit dans X0 // Y doit contenir l'image traitee generate_path_filename_extension(src_path, filename0, "pgm", complete_filename); puts(complete_filename); X0 = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); generate_path_filename_extension(noise_path, filename, "pgm", complete_filename); puts(complete_filename); X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); Y = ui8matrix(i0, i1, j0, j1); // --------------------- // -- gaussian kernel -- // --------------------- sep = "_G_"; ndigit = 2; // codage sur 2 chiffre de la valeur de sigma dans le nom du fichier sigma = 0.5; // parametre du bloc de code k = (int) (10*sigma); // code radius = (int) ceil(2*sigma+1); printf("sigma = %.1f -> radius = %d\n", sigma, radius); K = alloc_kernel(radius); init_gaussian_kernel(K, radius, sigma); convolve_kernel_ui8matrix(X, i0, i1, j0, j1, K, radius, Y); p = psnr(X0, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(denoise_path, filename, sep, k, ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); free_kernel(K, radius); // ----------------- // -- average kernel // ----------------- sep = "_A_"; ndigit = 1; // codage sur 1 chiffre de la valeur de radius dans le nom du fichier radius = 1; // parametre du bloc de code k = radius; // code K = alloc_kernel(radius); init_average_kernel(K, radius); convolve_kernel_ui8matrix(X, i0, i1, j0, j1, K, radius, Y); p = psnr(X0, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(denoise_path, filename, sep, k, ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); free_kernel(K, radius); // liberation de la memoire free_ui8matrix(X0, i0, i1, j0, j1); free_ui8matrix(X, i0, i1, j0, j1); free_ui8matrix(Y, i0, i1, j0, j1); }
/* --------------------------------------------------------------------- */ void routine_gaussian_noise(char *src_path, char *filename, char *dst_path) /* --------------------------------------------------------------------- */ { char complete_filename[1024]; char *sep = "_GN_"; // Gaussian Noise int sigma; int ndigit = 2; // codage sur 2 chiffres de la valeur de sigma dans le nom du fichier long i0, i1, j0, j1; uint8 **X, **Y; float32 p; // chargement de l'image sans bruit dans X // Y doit contenir l'image traitee generate_path_filename_extension(src_path, filename, "pgm", complete_filename); puts(complete_filename); X = LoadPGM_ui8matrix(complete_filename, &i0, &i1, &j0, &j1); Y = ui8matrix(i0, i1, j0, j1); sigma = 1; // parametre du bloc de code gaussian_noise_ui8matrix(X, i0, i1, j0, j1, (float32) sigma, Y); p = psnr(X, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, sigma, ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); // ajouter ici d'autre instances du bloc de code avec d'autres valeurs de sigma sigma = 2; // parametre du bloc de code gaussian_noise_ui8matrix(X, i0, i1, j0, j1, (float32) sigma, Y); p = psnr(X, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, sigma, ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); sigma = 3; // parametre du bloc de code gaussian_noise_ui8matrix(X, i0, i1, j0, j1, (float32) sigma, Y); p = psnr(X, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, sigma, ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); sigma = 4; // parametre du bloc de code gaussian_noise_ui8matrix(X, i0, i1, j0, j1, (float32) sigma, Y); p = psnr(X, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, sigma, ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); sigma = 5; // parametre du bloc de code gaussian_noise_ui8matrix(X, i0, i1, j0, j1, (float32) sigma, Y); p = psnr(X, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, sigma, ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); sigma = 10; // parametre du bloc de code gaussian_noise_ui8matrix(X, i0, i1, j0, j1, (float32) sigma, Y); p = psnr(X, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, sigma, ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); sigma = 20; // parametre du bloc de code gaussian_noise_ui8matrix(X, i0, i1, j0, j1, (float32) sigma, Y); p = psnr(X, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, sigma, ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); sigma = 30; // parametre du bloc de code gaussian_noise_ui8matrix(X, i0, i1, j0, j1, (float32) sigma, Y); p = psnr(X, i0, i1, j0, j1, Y); generate_path_filename_sep_k_ndigit_extension(dst_path, filename, sep, sigma, ndigit, "pgm", complete_filename); printf("%s -> PSNR = %8.2f db\n", complete_filename, p); SavePGM_ui8matrix(Y, i0, i1, j0, j1, complete_filename); // liberation de la memoire free_ui8matrix(X, i0, i1, j0, j1); free_ui8matrix(Y, i0, i1, j0, j1); }
/* -------------------------------------------------------------------- */ void sobel_ui8matrix(uint8 **X, int i0, int i1, int j0, int j1, uint8 **Y) /* -------------------------------------------------------------------- */ { int i, j; int ii, jj; uint8 **T; float32 y; sint8 **Kx; Kx = si8matrix(-1,1, -1, 1); Kx[-1][-1]=-1; Kx[0][-1]=-2; Kx[1][-1]=-1; Kx[-1][0]=0; Kx[0][0]=0; Kx[1][0]=0; Kx[-1][1]=1; Kx[0][1]=2; Kx[1][1]=1; sint8 **Ky; Ky = si8matrix(-1,1, -1, 1); Ky[-1][-1]=-1; Ky[0][-1]=0; Ky[1][-1]=1; Ky[-1][0]=-2; Ky[0][0]=0; Ky[1][0]=2; Ky[-1][1]=-1; Ky[0][1]=0; Ky[1][1]=1; T = ui8matrix(i0-1, i1+1, j0-1, j1+1); zero_ui8matrix(T, i0-1, i1+1, j0-1, j1+1); dup_ui8matrix(X, i0, i1, j0, j1, T); extend_ui8matrix(T, i0, i1, j0, j1, 1); for(i=i0; i<=i1; i++) { for(j=j0; j<=j1; j++) { y = 0.0f; for(ii=-1; ii<=1; ii++) { for(jj=-1; jj<=1; jj++) { y += T[i+ii][j+jj] * Kx[ii][jj]; } } Y[i][j] = (uint8) fabs(y/8); } } for(i=i0; i<=i1; i++) { for(j=j0; j<=j1; j++) { y = 0.0f; for(ii=-1; ii<=1; ii++) { for(jj=-1; jj<=1; jj++) { y += T[i+ii][j+jj] * Ky[ii][jj]; } } Y[i][j] += (uint8) fabs(y/8); if(Y[i][j]<0.0f) Y[i][j] = 0.0f; if(Y[i][j]>255.0f) Y[i][j] = 255.0f; } } free_ui8matrix(T, i0-1, i1+1, j0-1, j1+1); free_ui8matrix(Kx, -1, 1, -1, 1); free_ui8matrix(Ky, -1, 1, -1, 1); }