Skip to content
Snippets Groups Projects
Commit ef2cc7a4 authored by jorge.leitemac's avatar jorge.leitemac :juggling_tone5:
Browse files

fonction conv qui marche pas

parent a6615c6c
No related branches found
No related tags found
No related merge requests found
#include "pgm.h"
void foo(int* elem){
*elem *= 2;
}
int main(){
int boxBlur[] = {1,1,1,1,1,1,1,1,1};
pgm p;
pgm_read_from_file(&p, "./img/mandrill.pgm");
pgm_write_to_file(&p, "./img/mandrill2.pgm");
......@@ -20,7 +19,7 @@ int main(){
//SYM HORIZONTAL
pgm symH;
pgm_symmetry_vert(&symH, &p);
pgm_symmetry_hori(&symH, &p);
pgm_write_to_file(&symH, "./img/symH_mandrill.pgm");
//SYM VERTICAL
......@@ -38,9 +37,16 @@ int main(){
pgm_crop(&crop, &p, 100, 200, 100, 200);
pgm_write_to_file(&crop, "./img/crop_mandrill.pgm");
matrix kernel;
matrix_init_from_array(&kernel, 3, 3, boxBlur);
matrix_print(kernel);
pgm conv;
pgm_conv(&conv, &p, &kernel, 9);
pgm_write_to_file(&crop, "./img/conv_mandrill.pgm");
matrix_destroy(&(kernel));
matrix_destroy(&(conv.pixels));
matrix_destroy(&(p.pixels));
matrix_destroy(&(symH.pixels));
matrix_destroy(&(symV.pixels));
......
......@@ -214,5 +214,64 @@ pgm_error pgm_photomaton(pgm *photomaton, const pgm *const orig){
return failure;
}
return success;
}
//Kernel = matrice de convolution
pgm_error pgm_conv(pgm *conv, const pgm *const orig,const matrix *const kernel, double norm){
conv->max = orig->max;
//conv = orig * kernel
int cpt = 0;
int32_t valeurs[orig->pixels.m * orig->pixels.n];
int nC = 0;
int mC = 0;
int moy = 0;
norm = (norm == 0) ? 1 : norm;
for (int n = 0; n < orig->pixels.m; n++)
{
for (int m = 0; m < orig->pixels.n; m++)
{
//POURQUOI /2 ????
mC = m-(kernel->m-1)/2;
nC = n-(kernel->n-1)/2;
for (int i = 0; i < kernel->m; i++)
{
for (int j = 0; j < kernel->n; j++)
{
if(mC <= orig->pixels.m && nC <= orig->pixels.n && nC > 0 && mC > 0){
moy += orig->pixels.data[nC][mC] * kernel->data[i][j];
}
nC++;
}
nC = n-(kernel->n-1)/2;
mC++;
}
moy = moy / norm;
if(moy < 0){
moy = 0;
}
if(moy >= orig->max){
moy = orig->max;
}
valeurs[cpt] = moy;
cpt++;
moy = 0;
}
}
if (matrix_init_from_array(&conv->pixels, orig->pixels.m, orig->pixels.n, valeurs) != OK) {
return failure;
}
return success;
}
\ No newline at end of file
......@@ -38,5 +38,5 @@ pgm_error pgm_photomaton(pgm *photomaton,const pgm *const orig);
pgm_error pgm_crop(pgm *crop, const pgm *const orig,int32_t x0, int32_t x1,int32_t y0, int32_t y1);
//Filtres avec convultion
pgm_error pgm_conv(pgm *conv, const pgm *const orig,const matrix *const kernel);
pgm_error pgm_conv(pgm *conv, const pgm *const orig,const matrix *const kernel, double norm);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment