#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <stdbool.h> #include <string.h> #include <math.h> #include "traitementPGM.h" #include "Matrix.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 Convolution_test(void); void Convolution_1d(void); /** * @brief Create file and write data of eror computed inside * * @param filename The filename to use for the file created * @param size_n The array of size for data * @param error_n The array of error computed * @param length_data The length of data for both */ 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); } /** * @brief Compute the difference between * */ 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); } /** * @brief Convolve with filter for image reading and display * */ void Convolution_filtrage() { char filname[] = "part3_1.pgm"; char output_image[] = "out.pgm"; char output_convolve[] = "convolve.pgm"; char sdl_name[] = "convolution"; pgm img; if (pgm_read_from_file(&img, filname) == -1) { printf("Impossible de lire l'image shouaitée\n"); return; } printf("%d %d\n", img.pixels.col, img.pixels.row); pgm_write_to_file(&img, output_image); // 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}; matrix *kernel = matrix_create_from_array(3, 3, tab, 9); matrix_print(kernel); pgm res; res.max = img.max; matrix_init(&res.pixels, img.pixels.col, img.pixels.row); convolve_matrix(&res.pixels, &img.pixels, kernel, 9); int32_t norm_max = matrix_max(&res.pixels); int32_t norm_min = matrix_min(&res.pixels); printf("Min : %d, Max : %d\n", norm_min, norm_max); normalise_matrix(&res.pixels, norm_min, norm_max, res.max); PrintImagePGM(res, sdl_name); pgm_write_to_file(&res, output_convolve); matrix_free(&img.pixels); matrix_free(&res.pixels); matrix_destroy(kernel); } /** * @brief Convolve 1D signal * */ void Convolution_1d(void) { int PeriodeEchentillonage = 400; double signal[PeriodeEchentillonage]; double out[PeriodeEchentillonage]; int s1_amplitude = 1; int s1_frequence = 50; int s2_amplitude = 10; int s2_frequence = 5; double pi = 3.14; for (int i = 0; i < PeriodeEchentillonage; i++) { signal[i] = s1_amplitude * cos(2 * pi * s1_frequence * i) + s2_amplitude * cos(2 * pi * s2_frequence * i); // printf("%f\n",signal[i]); } convolution_signal(signal, out, PeriodeEchentillonage); } int main() { printf("TP math - Integrales\n"); Convolution_filtrage(); Convolution_1d(); return EXIT_SUCCESS; }