Skip to content

Commit a9ad8b8

Browse files
add save histogramme to pbm
1 parent fc9b413 commit a9ad8b8

File tree

4 files changed

+61
-11
lines changed

4 files changed

+61
-11
lines changed

Header/Contour.h

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Image derive(Image m , int seuil);
1010
Image laplacien(Image derive , int seuil);
1111

1212
void contour(Image , char* type , int seuil);
13+
void hough(Image , int theta);
14+
1315
Image contour_with_sobel(Image m) ;
1416
Image contour_with_Prewitt(Image m );
1517
Image contour_with_Roberts(Image m);

Header/Operations.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ struct Image and(const Image , const Image);
4545
struct Image or(const Image ,const Image);
4646
struct Image xor(const Image ,const Image);
4747

48+
void saveHistogramme(int* , char*);
4849
#endif

Source/Operations.c

+56-11
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,15 @@ void histogramme(Image m)
466466
printf("%d \t", LUT[i]);
467467
}
468468
write_Histogramme_to_File(LUT);
469+
saveHistogramme(LUT, "./image/histo/histogramme.pgm");
469470
free(LUT);
470471
}
471472

472473
void write_Histogramme_to_File(int *hist)
473474
{
474475
FILE *file = NULL;
475476
int i = 0;
476-
file = fopen("./image/cours/histogramme.txt", "a");
477+
file = fopen("./image/histo/histogramme_file.txt", "a");
477478
if (file != NULL)
478479
{
479480
fprintf(file, "Numero Count\n");
@@ -548,24 +549,24 @@ struct Image interpolationPlusProcheVoisin(struct Image img, int x, int y)
548549

549550
struct Image and (const Image f, const Image g)
550551
{
551-
int largeur , hauteur =0;
552-
largeur = MIN_VALUE(f.largeur , g.largeur);
553-
hauteur = MIN_VALUE(g.hauteur , g.hauteur);
554-
552+
int largeur, hauteur = 0;
553+
largeur = MIN_VALUE(f.largeur, g.largeur);
554+
hauteur = MIN_VALUE(g.hauteur, g.hauteur);
555+
555556
Image fprim = seuillage_historgramme(f);
556557
Image gprim = seuillage_historgramme(g);
557-
Image result ;
558-
result.M = generate_matrice(largeur , hauteur);
559-
strcpy(result.name , "P1");
560-
strcpy(result.description , "# image And");
558+
Image result;
559+
result.M = generate_matrice(largeur, hauteur);
560+
strcpy(result.name, "P1");
561+
strcpy(result.description, "# image And");
561562
result.largeur = largeur;
562563
result.hauteur = hauteur;
563564
result.MAX_PIXEL_VALUE = 1;
564565
for (int i = 0; i < largeur; i++)
565566
{
566567
for (int j = 0; j < hauteur; j++)
567568
{
568-
// result.M[i][j] = fprim.M[i][j] && gprim.M[i][j];
569+
// result.M[i][j] = fprim.M[i][j] && gprim.M[i][j];
569570
result.M[i][j] = fprim.M[i][j] != gprim.M[i][j] ? 0 : 1;
570571
//(fprim.M[i][j] && gprim.M[i][j]);
571572
}
@@ -589,7 +590,7 @@ struct Image or (const Image f, const Image g)
589590
{
590591
for (int j = 0; j < f.hauteur; j++)
591592
{
592-
result.M[i][j] = fprim.M[i][j] || gprim.M[i][j] ;
593+
result.M[i][j] = fprim.M[i][j] || gprim.M[i][j];
593594
//(fprim.M[i][j] == 0 && gprim.M[i][j] == 0) ? 0 : 1;
594595
// (fprim.M[i][j] || gprim.M[i][j]);
595596
}
@@ -629,4 +630,48 @@ struct Image xor (const Image f, const Image g)
629630
freeMatrice(fprim.M, fprim.largeur);
630631
freeMatrice(gprim.M, gprim.largeur);
631632
return result;
633+
}
634+
635+
void saveHistogramme(int *hist, char *path)
636+
{
637+
Image m;
638+
float min, max;
639+
int i, j;
640+
m.M = generate_matrice(256, 256);
641+
float *histotmp = calloc(256, sizeof(float));
642+
643+
//recherche du max et min dans histo
644+
for (max = 0, min = INFINITY, i = 0; i < 256; i++)
645+
{
646+
if (hist[i] > max)
647+
max = hist[i];
648+
if (hist[i] < min)
649+
min = hist[i];
650+
}
651+
printf("%f %f", max, min);
652+
//On normalise l'histogramme
653+
for (i = 0; i < 256; i++)
654+
{
655+
histotmp[i] = ((hist[i] - min) / max) * 255.0;
656+
}
657+
658+
for (i = 0; i < 256; i++)
659+
{
660+
printf("%f\t", histotmp[i]);
661+
}
662+
663+
/*Affichage sous forme image*/
664+
for (i = 0; i < 255; i++)
665+
for (j = 0; j < histotmp[i]; j++)
666+
m.M[255 - j][i] = 255;
667+
668+
m.hauteur = 256;
669+
m.largeur = 256;
670+
strcpy(m.name, "P2");
671+
strcpy(m.description, "# Image de l'egalisation de l'histogamme");
672+
m.MAX_PIXEL_VALUE = 255;
673+
write_Image_to_file(m, path);
674+
675+
freeMatrice(m.M, 256);
676+
free(histotmp);
632677
}

main.c

+2
Original file line numberDiff line numberDiff line change
@@ -121,5 +121,7 @@ write_Image_to_file_Pbm(r3 ,"./image/cours/xor.pgm");
121121
write_Image_to_file(m1, "./image/contour/derive.pgm");
122122
write_Image_to_file(laplacien(img , 15) , "./image/contour/laplacien.pgm");
123123
contour(img , "prewitt" , 60);
124+
histogramme(img2);
125+
124126
return 0;
125127
}

0 commit comments

Comments
 (0)