Skip to content
Snippets Groups Projects
Commit 069abfd1 authored by damian.boquetec's avatar damian.boquetec
Browse files

convolution 30 % done and crop still buggy

parent ff65a8d6
Branches master
No related tags found
No related merge requests found
...@@ -141,21 +141,52 @@ pgm_error pgm_crop(pgm *crop, const pgm *const orig, int32_t x0, int32_t x1, int ...@@ -141,21 +141,52 @@ pgm_error pgm_crop(pgm *crop, const pgm *const orig, int32_t x0, int32_t x1, int
if (x0 < 0 || y0 < 0 || x0 > x1 || y0 > y1 || x1 > orig->pixels.l || y1 > orig->pixels.l){ if (x0 < 0 || y0 < 0 || x0 > x1 || y0 > y1 || x1 > orig->pixels.l || y1 > orig->pixels.l){
return failure; return failure;
} }
//Still buggy for rectangles
int l = x1 - x0; int l = x1 - x0;
int c = y1 - y0; int c = y1 - y0;
crop->max = 255; crop->max = 255;
matrix_alloc(&crop->pixels, l, c); matrix_alloc(&crop->pixels, l, c);
for (int i = x0, k = 0; i < x1; i++, k++){ for (int i = x0, k = 0; i < x1; i++, k++){
for (int j = y0, m = 0; j < y1; j++, m++){ for (int j = y0, m = 0; j < y1; j++, m++){
crop->pixels.data[k][m] = orig->pixels.data[i][j]; crop->pixels.data[k][m] = orig->pixels.data[i][j];
} }
} }
return success; return success;
} }
/* pgm_error add_zeros_in_pgm(pgm *zeroedPgm, const pgm *const orig){
pgm_error pmg_conv(pgm *conv, const pgm *const orig, const matrix *const kernel); if (zeroedPgm == NULL || orig == NULL){
*/ return failure;
\ No newline at end of file }
zeroedPgm->max = orig->max;
matrix_alloc(&zeroedPgm->pixels, (orig->pixels.l + 2), (orig->pixels.c + 2));
for(int i = 0; i < zeroedPgm->pixels.l; i++){
for (int j = 0; j < zeroedPgm->pixels.c; j++){
zeroedPgm->pixels.data[i][j] = 0;
}
}
for(int i = 1, k = 0; i < zeroedPgm->pixels.l - 1; i++, k++){
for(int j = 1, m = 0; i < zeroedPgm->pixels.c - 1; j++, m++){
zeroedPgm->pixels.data[i][j] = orig->pixels.data[k][m];
}
}
return success;
}
pgm_error pmg_conv(pgm *conv, const pgm *const orig, const matrix *const kernel){
if (conv == NULL || orig == NULL || kernel){
return failure;
}
conv->max = orig->max;
matrix_alloc(&conv->pixels, orig->pixels.l, orig->pixels.c);
for (int i = 1; i <= orig->pixels.l; i++){
for (int j = 1; j <= orig->pixels.c; j++){
//attention au valeurs < 0 ou > 255
}
}
return success;
}
...@@ -23,6 +23,7 @@ pgm_error pgm_symmetry_vert(pgm *sym, const pgm *const orig); ...@@ -23,6 +23,7 @@ pgm_error pgm_symmetry_vert(pgm *sym, const pgm *const orig);
pgm_error pgm_symmetry_cent(pgm *sym, const pgm *const orig); pgm_error pgm_symmetry_cent(pgm *sym, const pgm *const orig);
pgm_error pgm_photomaton(pgm *photomaton, const pgm *const orig); 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); pgm_error pgm_crop(pgm *crop, const pgm *const orig, int32_t x0, int32_t x1, int32_t y0, int32_t y1);
pgm_error add_zeros_in_pgm(pgm *zeroedPgm, const pgm *const orig);
pgm_error pmg_conv(pgm *conv, const pgm *const orig, const matrix *const kernel); pgm_error pmg_conv(pgm *conv, const pgm *const orig, const matrix *const kernel);
#endif #endif
\ No newline at end of file
#include "pgm.h" #include "pgm.h"
int main(){ int main(){
pgm a; pgm a;
pgm neg; pgm neg;
...@@ -10,6 +9,12 @@ int main(){ ...@@ -10,6 +9,12 @@ int main(){
pgm photomatonx4; pgm photomatonx4;
pgm photomatonx16; pgm photomatonx16;
pgm cropped; pgm cropped;
pgm zeroPgm;
//pgm convolution;
int conv[9] = {1,1,1,1,0,1,1,1,1};
matrix convKernel;
matrix_init_from_array(&convKernel, 3, 3, conv, 9);
printf("%d", pgm_read_from_file(&a, "mandrill.pgm")); printf("%d", pgm_read_from_file(&a, "mandrill.pgm"));
...@@ -30,8 +35,14 @@ int main(){ ...@@ -30,8 +35,14 @@ int main(){
printf("%d", pgm_photomaton(&photomatonx16, &photomatonx4)); printf("%d", pgm_photomaton(&photomatonx16, &photomatonx4));
//printf("%d", pgm_write_to_file(&photomatonx16, "photomatonx16.pgm")); //printf("%d", pgm_write_to_file(&photomatonx16, "photomatonx16.pgm"));
printf("%d", pgm_crop(&cropped, &a, 100, 300, 100, 200)); printf("%d", pgm_crop(&cropped, &a, 100, 300, 100, 300));
printf("%d", pgm_write_to_file(&cropped, "cropped.pgm")); //printf("%d", pgm_write_to_file(&cropped, "cropped.pgm"));
printf("%d", add_zeros_in_pgm(&zeroPgm, &a));
printf("%d", pgm_write_to_file(&zeroPgm, "zero.pgm"));
//printf("%d", pmg_conv(&convolution, &a, &convKernel));
//printf("%d", pgm_write_to_file(&convolution, "convolution.pgm"));
matrix_destroy(&a.pixels); matrix_destroy(&a.pixels);
matrix_destroy(&neg.pixels); matrix_destroy(&neg.pixels);
...@@ -41,6 +52,7 @@ int main(){ ...@@ -41,6 +52,7 @@ int main(){
matrix_destroy(&photomatonx4.pixels); matrix_destroy(&photomatonx4.pixels);
matrix_destroy(&photomatonx16.pixels); matrix_destroy(&photomatonx16.pixels);
matrix_destroy(&cropped.pixels); matrix_destroy(&cropped.pixels);
matrix_destroy(&convKernel);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
\ 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