Skip to content
Snippets Groups Projects
Commit 62df13fb authored by edona.edi's avatar edona.edi
Browse files

Dernier push pour le rendu avant 00:00 le 19 juin 2023.

parent 535d95ae
No related branches found
No related tags found
No related merge requests found
File deleted
...@@ -31,7 +31,7 @@ int main() ...@@ -31,7 +31,7 @@ int main()
int height = p1.pixels.m; int height = p1.pixels.m;
int width = p1.pixels.n; int width = p1.pixels.n;
struct gfx_context_t *ctxt = gfx_create("Image avce modification", width, height); struct gfx_context_t *ctxt = gfx_create("Image avec modification", width, height);
if (!ctxt) if (!ctxt)
{ {
fprintf(stderr, "Graphics initialization failed!\n"); fprintf(stderr, "Graphics initialization failed!\n");
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -26,6 +26,7 @@ error_code pgm_read_from_file(pgm *p, char *filename){ ...@@ -26,6 +26,7 @@ error_code pgm_read_from_file(pgm *p, char *filename){
return ok; return ok;
} }
// Creation d'un fichier pour insere valeur
error_code pgm_write_to_file(pgm *p, char *filename){ error_code pgm_write_to_file(pgm *p, char *filename){
FILE *f = fopen(filename,"w"); FILE *f = fopen(filename,"w");
fprintf(f,"F2\n%d %d\n%d\n",p->pixels.m,p->pixels.n,p->max); fprintf(f,"F2\n%d %d\n%d\n",p->pixels.m,p->pixels.n,p->max);
...@@ -101,29 +102,92 @@ error_code pgm_symmetry_vert(pgm *sym, pgm *orig){ ...@@ -101,29 +102,92 @@ error_code pgm_symmetry_vert(pgm *sym, pgm *orig){
return ok; return ok;
} }
/// @brief Rotation de l'image vers la gauche en matrice
/// @param orig
/// @param rot
/// @return
error_code pgm_rotation_gauche(pgm *orig, pgm *rot){ error_code pgm_rotation_gauche(pgm *orig, pgm *rot){
matrix_alloc(&rot->pixels,orig->pixels.m,orig->pixels.n); matrix_alloc(&rot->pixels,orig->pixels.m,orig->pixels.n);
for(int lig = 0; lig<orig->pixels.m; ++lig){ for(int lig = 0; lig<orig->pixels.m; ++lig){
for(int col =0; col< orig->pixels.n;++col){ for(int col =0; col< orig->pixels.n;++col){
int elem =orig->pixels.data[lig][col]; int elem =orig->pixels.data[lig][col];
//Rotation mise en place (a la place des colonne on insere la ligne)
// a la place de lig : col-1 - la col en cours
matrix_set(rot->pixels, orig->pixels.n - 1 - col, lig, elem); matrix_set(rot->pixels, orig->pixels.n - 1 - col, lig, elem);
} }
} }
return ok; return ok;
} }
/// @brief Rotation en de l'image vers la droite en matrice
/// @param orig
/// @param rot
/// @return
error_code pgm_rotation_droite(pgm *orig, pgm *rot){ error_code pgm_rotation_droite(pgm *orig, pgm *rot){
matrix_alloc(&rot->pixels,orig->pixels.m,orig->pixels.n); matrix_alloc(&rot->pixels,orig->pixels.m,orig->pixels.n);
for(int lig = 0; lig<orig->pixels.m; ++lig){ for(int lig = 0; lig<orig->pixels.m; ++lig){
for(int col =0; col< orig->pixels.n;++col){ for(int col =0; col< orig->pixels.n;++col){
int elem =orig->pixels.data[lig][col]; int elem =orig->pixels.data[lig][col];
//Rotation mise en place (a la place des ligne on insere la colonne)
// a la place de col : lig -1 - la ligne en cours
matrix_set(rot->pixels,col,orig->pixels.m- 1 - lig, elem); matrix_set(rot->pixels,col,orig->pixels.m- 1 - lig, elem);
} }
} }
return ok; return ok;
} }
///Savoir si c'est une feuille
/// @brief Rogner une image (rectangle)
/// @param x
/// @param y
/// @param orig
/// @param rogne
/// @return
error_code pgm_rogner(int x,int y,pgm *orig,pgm *rogne){
// le rectangle
int rogHeight =200;
int rogWidth =400;
matrix_alloc(&rogne->pixels,rogHeight, rogWidth);
for (int j = 0; j < rogHeight; ++j) {
for (int i = 0; i < rogWidth; ++i) {
// emplacement du rognage
int srcX = x + i;
int srcY = y + j;
// modification des valeurs (de la matrice)
int elem= orig->pixels.data[srcY][srcX];
matrix_set(rogne->pixels,j,i,elem);
}
}
return ok;
}
////////////////////////////////////////////////////////////////////////////////////////
////
/// Manque de temps pour effectuer la derniere etapes car soucis avec les arbre quadtree
///
/////////////////////////////////////////////////////////////////////////////////////////
// void compression_sans_perte(node *arbre){
// if(!is_leaf(arbre)){
// for (int i = 0; i < 4; i++)
// {
// compression_sans_perte(arbre->enf[i]);
// }
// if(derniere_branche(arbre)){
// int valeur, toutes_egales = valeur_enfants(arbre);
// if(toutes_egales){
// arbre->info= valeur;
// destroy(arbre);
// }
// }
// }
// }
////////////////////////////////////////////////////////////////////////////////
//// Traitement des arbres quadtree
//// Il y a des erreurs lors que je transforme mon fichier en arbre (trop grand)
//// La transformation fonctionne lors le fichier est plus petit
///////////////////////////////////////////////////////////////////////////////
/* ///Savoir si c'est une feuille
bool is_leaf(node *tree){ bool is_leaf(node *tree){
// printf("in is_leaf\n"); // printf("in is_leaf\n");
// verification si l'enfant[0] n'a pas d'enfant // verification si l'enfant[0] n'a pas d'enfant
...@@ -203,7 +267,7 @@ int depth(node *qt){ ...@@ -203,7 +267,7 @@ int depth(node *qt){
} }
} }
/// @brief /// @brief Position du noeud
/// @param li /// @param li
/// @param col /// @param col
/// @param arbre /// @param arbre
...@@ -220,6 +284,8 @@ node *position(int li, int col, node *arbre){ ...@@ -220,6 +284,8 @@ node *position(int li, int col, node *arbre){
} }
return arbre; return arbre;
} }
// transformation d'une matrice en arbre
node *matrice_a_arbre(pgm *orig){ node *matrice_a_arbre(pgm *orig){
// calcule la profondeur grace a une matrice // calcule la profondeur grace a une matrice
int depth = log((orig->pixels.m * orig->pixels.n)) / log(4); int depth = log((orig->pixels.m * orig->pixels.n)) / log(4);
...@@ -260,7 +326,7 @@ node *cycli_rotation_gauche(node *arbre){ ...@@ -260,7 +326,7 @@ node *cycli_rotation_gauche(node *arbre){
} }
return arbre; return arbre;
} }
// transformation d'un arbre en matrice
pgm *arbre_a_matrice(node *arbre,pgm *mat){ pgm *arbre_a_matrice(node *arbre,pgm *mat){
for(int li =0;li <=mat->pixels.m; ++li){ for(int li =0;li <=mat->pixels.m; ++li){
for(int col =0; col<=mat->pixels.n;++col){ for(int col =0; col<=mat->pixels.n;++col){
...@@ -270,6 +336,7 @@ pgm *arbre_a_matrice(node *arbre,pgm *mat){ ...@@ -270,6 +336,7 @@ pgm *arbre_a_matrice(node *arbre,pgm *mat){
} }
return mat; return mat;
} }
// affichage de la matrice
error_code affichage_image(pgm *rot, pgm *mat){ error_code affichage_image(pgm *rot, pgm *mat){
for(int li =0;li <=mat->pixels.m; ++li){ for(int li =0;li <=mat->pixels.m; ++li){
for(int col =0; col< mat->pixels.n;++col){ for(int col =0; col< mat->pixels.n;++col){
...@@ -280,30 +347,6 @@ error_code affichage_image(pgm *rot, pgm *mat){ ...@@ -280,30 +347,6 @@ error_code affichage_image(pgm *rot, pgm *mat){
return ok; return ok;
} }
/// @brief Rogner une image (rectangle)
/// @param x
/// @param y
/// @param orig
/// @param rogne
/// @return
error_code pgm_rogner(int x,int y,pgm *orig,pgm *rogne){
// le rectangle
int rogHeight =200;
int rogWidth =400;
matrix_alloc(&rogne->pixels,rogHeight, rogWidth);
for (int j = 0; j < rogHeight; ++j) {
for (int i = 0; i < rogWidth; ++i) {
// emplacement du rognage
int srcX = x + i;
int srcY = y + j;
// modification des valeurs (de la matrice)
int elem= orig->pixels.data[srcY][srcX];
matrix_set(rogne->pixels,j,i,elem);
}
}
return ok;
}
/// @brief liberation noeud /// @brief liberation noeud
/// @param n /// @param n
void destroy(node* n) void destroy(node* n)
...@@ -311,7 +354,6 @@ void destroy(node* n) ...@@ -311,7 +354,6 @@ void destroy(node* n)
if (n == NULL) { if (n == NULL) {
return; return;
} }
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
destroy(n->enf[i]); destroy(n->enf[i]);
} }
...@@ -321,7 +363,7 @@ void destroy(node* n) ...@@ -321,7 +363,7 @@ void destroy(node* n)
/// @brief Print arbre /// @brief Print arbre
/// @param tree /// @param tree
/// @param level /// @param level
//MODIFICATION //MODIFICATION - ne focntion pas correctement
void print_tree(node * tree, int level){ void print_tree(node * tree, int level){
if (tree == NULL) if (tree == NULL)
...@@ -360,5 +402,4 @@ void print_tree(node * tree, int level){ ...@@ -360,5 +402,4 @@ void print_tree(node * tree, int level){
} }
if (has_child) printf(")"); if (has_child) printf(")");
} */
}
File deleted
#include "image/image.h" #include "image/image.h"
// interface utilisateur
void interface_utilisateur(char *filename, pgm *orig,pgm* out){ void interface_utilisateur(char *filename, pgm *orig,pgm* out){
int input; int input;
int input_2; int input_2;
...@@ -8,17 +9,18 @@ void interface_utilisateur(char *filename, pgm *orig,pgm* out){ ...@@ -8,17 +9,18 @@ void interface_utilisateur(char *filename, pgm *orig,pgm* out){
printf("2. symetrie\n"); printf("2. symetrie\n");
printf("3. rotation\n"); printf("3. rotation\n");
printf("4. rogner\n"); printf("4. rogner\n");
printf("5. filtre\n"); printf("5. filtrage\n");
printf("7. floutage\n"); printf("6. compression\n");
printf("8. compression\n");
scanf("%d",&input); scanf("%d",&input);
// lecture de l'image
pgm_read_from_file(orig,filename); pgm_read_from_file(orig,filename);
switch (input) { switch (input) {
case 1: case 1:
//Transformation de l'image en negatif
pgm_negative(out,orig); pgm_negative(out,orig);
break; break;
case 2: case 2:
//Transformation de l'image en symetrie (hor / vert)
printf("Souhaitez-vous une symetrie :\n"); printf("Souhaitez-vous une symetrie :\n");
printf("1. horizontal\n"); printf("1. horizontal\n");
printf("2. vertical\n"); printf("2. vertical\n");
...@@ -27,6 +29,7 @@ void interface_utilisateur(char *filename, pgm *orig,pgm* out){ ...@@ -27,6 +29,7 @@ void interface_utilisateur(char *filename, pgm *orig,pgm* out){
else pgm_symmetry_vert(out,orig); else pgm_symmetry_vert(out,orig);
break; break;
case 3: case 3:
// Rotation effectuer en matrice
printf("Souhaitez-vous faire une rotation :\n"); printf("Souhaitez-vous faire une rotation :\n");
printf("1. à gauche\n"); printf("1. à gauche\n");
printf("2. à droite\n"); printf("2. à droite\n");
...@@ -35,6 +38,7 @@ void interface_utilisateur(char *filename, pgm *orig,pgm* out){ ...@@ -35,6 +38,7 @@ void interface_utilisateur(char *filename, pgm *orig,pgm* out){
else pgm_rotation_droite(orig,out); else pgm_rotation_droite(orig,out);
break; break;
case 4: case 4:
// rogner l'image
printf("valeur de x \n"); printf("valeur de x \n");
scanf("%d",&input); scanf("%d",&input);
printf("valeur de y \n"); printf("valeur de y \n");
...@@ -43,17 +47,18 @@ void interface_utilisateur(char *filename, pgm *orig,pgm* out){ ...@@ -43,17 +47,18 @@ void interface_utilisateur(char *filename, pgm *orig,pgm* out){
pgm_rogner(input,input_2,orig,out); pgm_rogner(input,input_2,orig,out);
break; break;
case 5: case 5:
// filtrage de la matrice
matrix_convolution(orig,out);
break; break;
case 6: case 6:
break;
case 7:
break;
case 8:
break; break;
default: default:
break; break;
} }
// Modification inscrite dans le nouveau fichier
pgm_write_to_file(out,"image.pgm"); pgm_write_to_file(out,"image.pgm");
//liberation des matrice / image
pgm_destroy(out); pgm_destroy(out);
pgm_destroy(orig); pgm_destroy(orig);
...@@ -64,10 +69,8 @@ int main(){ ...@@ -64,10 +69,8 @@ int main(){
pgm p; pgm p;
pgm neg; pgm neg;
char *filename = "mandrill.pgm"; char *filename = "mandrill.pgm";
//pgm_read_from_file(&p,filename);
interface_utilisateur(filename,&p,&neg); interface_utilisateur(filename,&p,&neg);
//char *filename = "test.pgm"; //char *filename = "test.pgm";
// node * arbre = newNode(); // node * arbre = newNode();
// print_tree(arbre, 0); // print_tree(arbre, 0);
// node *arbre = matrice_a_arbre(&p); // node *arbre = matrice_a_arbre(&p);
...@@ -76,9 +79,6 @@ int main(){ ...@@ -76,9 +79,6 @@ int main(){
// node *arbre_rot = cycli_rotation_gauche(arbre); // node *arbre_rot = cycli_rotation_gauche(arbre);
// pgm *mat = arbre_a_matrice(arbre_rot,&p); // pgm *mat = arbre_a_matrice(arbre_rot,&p);
// affichage_image(&neg, mat); // affichage_image(&neg, mat);
//pgm_rogner(20,40,&p,&neg);
//destroy(arbre); //destroy(arbre);
//destroy(arbre_rot); //destroy(arbre_rot);
//pgm_destroy(mat); //pgm_destroy(mat);
......
#include "matrix.h" #include "matrix.h"
#include "../image/image.h"
//allocation de la memoire pour la création matrice //allocation de la memoire pour la création matrice
...@@ -18,23 +18,6 @@ error_code matrix_alloc(matrix *mat, int m, int n){ ...@@ -18,23 +18,6 @@ error_code matrix_alloc(matrix *mat, int m, int n){
mat->data[l] = &mat->data[0][l*n]; mat->data[l] = &mat->data[0][l*n];
} }
// for (int i = 0; i < m; i++)
// {
// mat->data[i] = malloc(n*sizeof(int));
// }
return ok;
}
// initialiser la matrice a une valeur
error_code matrix_init(matrix *mat, int m, int n, int val){
matrix_alloc(mat,m,n);
for(int lig = 0; lig<mat->m;++lig){
for( int col= 0;col<mat->n; ++col){
mat->data[lig][col]= val;
}
}
return ok; return ok;
} }
...@@ -76,6 +59,7 @@ error_code matrix_print(matrix mat){ ...@@ -76,6 +59,7 @@ error_code matrix_print(matrix mat){
return ok; return ok;
} }
//Prendre une valeur dans une matrice
error_code matrix_get(int *elem, matrix mat,int ix, int iy){ error_code matrix_get(int *elem, matrix mat,int ix, int iy){
if(mat.m<= ix || mat.n<= iy){ if(mat.m<= ix || mat.n<= iy){
return err; return err;
...@@ -84,6 +68,7 @@ error_code matrix_get(int *elem, matrix mat,int ix, int iy){ ...@@ -84,6 +68,7 @@ error_code matrix_get(int *elem, matrix mat,int ix, int iy){
return ok; return ok;
} }
//Modication de la matrice avec une nouvelle valeur
error_code matrix_set(matrix mat, int ix, int iy, int32_t elem){ error_code matrix_set(matrix mat, int ix, int iy, int32_t elem){
if(mat.m<= ix || mat.n<= iy){ if(mat.m<= ix || mat.n<= iy){
return err; return err;
...@@ -91,22 +76,40 @@ error_code matrix_set(matrix mat, int ix, int iy, int32_t elem){ ...@@ -91,22 +76,40 @@ error_code matrix_set(matrix mat, int ix, int iy, int32_t elem){
mat.data[ix][iy]=elem; mat.data[ix][iy]=elem;
return ok; return ok;
} }
error_code matrix_convolution(pgm *orig,int kernel_sizex, int kernel_sizey,pgm *out){
/// @brief Creation d'une matrice convolution ( filtrage)
/// @param orig
/// @param out
/// @return
error_code matrix_convolution(pgm *orig,pgm *out){
matrix_alloc(&out->pixels,orig->pixels.m,orig->pixels.n); matrix_alloc(&out->pixels,orig->pixels.m,orig->pixels.n);
long int kernel[3][3] = {
{1, 1, 1},
{1, 1, 1},
{1, 1, 1}
};
// Parcours des pixels internes de l'image originale
for (int y = 1; y < orig->pixels.m - 1; ++y) { for (int y = 1; y < orig->pixels.m - 1; ++y) {
for (int x = 1; x < orig->pixels.n - 1; ++x) { for (int x = 1; x < orig->pixels.n - 1; ++x) {
int sum = 0; long int sum = 0;
for (int ky = 0; ky < kernel_sizey; ky++) { // Parcours du noyau de convolution
for (int kx = 0; kx < kernel_sizex; kx++) { for (int ky = 0; ky <=1; ky++) {
int imgX = x + kx - kernel_sizex / 2; for (int kx = 0; kx <=1; kx++) {
int imgY = y + ky - kernel_sizey/ 2; // Coordonnées de l'image originale
sum += orig->pixels.data[y + ky][x + kx] * out->pixels.data[ky + 1][kx + 1]; int imgX = x + kx;
} int imgY = y + ky;
} // Traitement d'une valeur trop grand ou inversement
if(orig->pixels.data[y][x]> orig->max)orig->pixels.data[y][x] = orig->max;
else if(orig->pixels.data[y][x] < 0) orig->pixels.data[y][x] = 0;
// Accumulation de la somme de convolution
sum += orig->pixels.data[imgY][imgX] * kernel[ky + 1][kx + 1];
}
}
// Affectation du résultat de la convolution au pixel correspondant de l'image de sortie
sum/=9;
out->pixels.data[y][x] = sum; out->pixels.data[y][x] = sum;
} }
} }
return ok;
} }
\ No newline at end of file
\ No newline at end of file
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#ifndef _MATRIX_H_ #ifndef _MATRIX_H_
#define _MATRIX_H_ #define _MATRIX_H_
...@@ -15,14 +16,15 @@ typedef enum _error_code { ...@@ -15,14 +16,15 @@ typedef enum _error_code {
ok, err ok, err
} error_code; } error_code;
#include "../image/image.h"
error_code matrix_alloc(matrix *mat, int m, int n); error_code matrix_alloc(matrix *mat, int m, int n);
error_code matrix_init(matrix *mat, int m, int n, int val); error_code matrix_init(matrix *mat, int m, int n, int val);
error_code matrix_destroy(matrix *mat); error_code matrix_destroy(matrix *mat);
error_code matrix_init_from_array(matrix *mat, int m, int n, int* data); error_code matrix_init_from_array(matrix *mat, int m, int n, int* data);
error_code matrix_print(matrix mat); error_code matrix_print(matrix mat);
//error_code matrix_clone(matrix *cloned, matrix mat);
//bool matrix_is_equal(matrix mat1, matrix mat2);
error_code matrix_get(int *elem, matrix mat,int ix, int iy); error_code matrix_get(int *elem, matrix mat,int ix, int iy);
error_code matrix_set(matrix mat, int ix, int iy, int32_t elem); error_code matrix_set(matrix mat, int ix, int iy, int32_t elem);
error_code matrix_convolution(pgm *orig, pgm *out);
#endif #endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment