Newer
Older
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include "traitementPGM.h"

poulpe
committed
#include "Matrix.h"
#include "gfx.h"
void write_error_graphic_file(const char *filename, const uint32_t size_n[],const double error_n[],const uint32_t length_data);
void Integration_numerique(void);
void Convolution_filtrage(void);
void write_error_graphic_file(const char *filename, const uint32_t size_n[],const double error_n[],const uint32_t length_data)
{
FILE *f = fopen(filename, "w");
for (uint32_t i = 0; i < length_data; i += 1)
{
fprintf(f, "%u,%lf\n", size_n[i], error_n[i]);
}
fclose(f);
}
void Integration_numerique()
{
uint32_t size_n[] = {5, 10, 50, 100, 500, 1000};
double error_n[6];
for (uint32_t i = 0; i < sizeof(size_n) / sizeof(size_n[0]); i += 1)
{
printf("N = %u\n", size_n[i]);
printf("Res integre : %.5lf\n", interg(1, 5, size_n[i], my_function_x));
error_n[i] = E_n(size_n[i]);
printf("E(N) = %lf\nI = %lf\n", error_n[i], VALUE_I);
}
write_error_graphic_file("graphique_data.txt", size_n, error_n, 6);
}

poulpe
committed
// void Convolution_test()
// {
// matrix* m1 = matrix_create(10,10);
// matrix* m2 = matrix_create(3,3);

poulpe
committed
// int tab []= {1,1,1,1,1,1,1,1,1};

poulpe
committed
// matrix_from_array(m2,3,3,tab);

poulpe
committed
// matrix_print(m2);

poulpe
committed
// matrix_setValue(&m1,8);

poulpe
committed
// matrix res = matrix_creat(10,10);

poulpe
committed
// matrix_print(m1);
// matrix_print(m2);

poulpe
committed
// convolve_matrix(&res,&m1,&m2,1/(double)9); // For create blur kernel
// matrix_print(res);

poulpe
committed
// matrix_destroy(&m1);
// matrix_destroy(&m2);
// matrix_destroy(&res);
// }

poulpe
committed
// char filname[] = "part3_5.pgm";
char filname[] = "part2.pgm";
// char filname[] = "/home/poulpe/Pictures/Images TP-20220425/part3_3.pgm";
char output_image[] = "out.pgm";
char output_convolve[] = "convolve.pgm";

poulpe
committed
if (pgm_read_from_file(&img, filname) == -1)
return;

poulpe
committed
printf("%d %d\n",img.pixels.col,img.pixels.row);
// normalise_matrix(&img.pixels,img.max,7);
// PrintImagePGM(img, filname);
pgm_write_to_file(&img,output_image);
// exit(0);

poulpe
committed
// matrix* kernel = matrix_create(3,3);
// matrix_init(kernel,3,3);
//T tab []= {0,0,0,0,1,0,0,0,0};
//T tab []= {1,1,1,1,1,1,1,1,1};
//T tab []= {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
//T tab[]= {1,4,6,4,4,16,24,16,46,24,36,24,64,16,24,16,41,4,6,4,1};
//T tab[] = {0,-1,0,-1,5,-1,0,-1,0};
T tab[] = {0,-1,0,-1,4,-1,0,-1,0};

poulpe
committed
matrix* kernel = matrix_create_from_array(3,3,tab,9);
matrix_print(kernel);
pgm res;
res.max = img.max;

poulpe
committed
matrix_init(&res.pixels,img.pixels.col,img.pixels.row);
// normalise_matrix(&img.pixels,img.max,7);

poulpe
committed
// pgm_write_to_file(&res,"tmp_1.pgm");
convolve_matrix(&res.pixels,&img.pixels,kernel,1);
int32_t norm_max = matrix_max(&res.pixels);
int32_t norm_min = matrix_min(&res.pixels);

poulpe
committed
printf("Min : %d, Max : %d\n",norm_min,norm_max);
normalise_matrix(&res.pixels,norm_min,norm_max,res.max);
pgm_write_to_file(&res,output_convolve);
matrix_free(&img.pixels);
matrix_free(&res.pixels);
matrix_destroy(kernel);
}
int main()
{
printf("TP math - Integrales\n");
//Integration_numerique();
Convolution_filtrage();