Soyez le premier à donner votre avis sur cette source.
Snippet vu 20 805 fois - Téléchargée 34 fois
/// Programme effectuant une moyenne de l'histogramme d'une image//// /// Le plus gros est la lecture de l'en tete de l'image //////////// /// DEUFF /////////////// 11/09/03 ////////////////////////////////// #include "stdafx.h" #include "stdio.h" #include "stdlib.h" #include "windows.h" int main(int argc,char*argv[]) { FILE *imgDep; unsigned long i, nb, nbLu, *histo; char type[2]; int tailleFic, reserved, offBit; int biSize, biWidth, biHeight; short biPlanes, biBitCount; int biCompression, biSizeImage, biXpix, biYpix, biClrUsed, biClrImportant; unsigned char couleur[4],*pixel; /////////// LECTURE DES DONNEES DE LIMAGE//////////////////////////////////////////////////////////////// imgDep = fopen("C:\\Temp\\030908_113556.bmp","rb"); if (imgDep == NULL) {printf ("Problemes images depart 1"); return (0);} nb = 2; nbLu = fread (type, sizeof(char),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 2"); return(0); } printf("imgDep %c %c ",type[0],type[1]); nb = 1; nbLu = fread (&tailleFic, sizeof(int),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 3"); return(0); } printf("taille = %d ",tailleFic); nb = 1; nbLu = fread (&reserved, sizeof(int),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 4"); return(0); } printf("reserve = %d\n\n",reserved); nb = 1; nbLu = fread (&offBit, sizeof(int),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 5"); return(0); } printf("offBits = %d octets ",offBit); nb = 1; nbLu = fread (&biSize, sizeof(int),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 6"); return(0); } printf("biSize=%d octets \n\n",biSize); nb = 1; nbLu = fread (&biWidth, sizeof(int),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 7"); return(0); } printf("biWidth=%d ",biWidth); nb = 1; nbLu = fread (&biHeight, sizeof(int),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 8"); return(0); } printf("biHeight=%d \n\n",biHeight); nb = 1; nbLu = fread (&biPlanes, sizeof(short),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 9"); return(0); } printf("biPlanes=%d ",biPlanes); nb = 1; nbLu = fread (&biBitCount, sizeof(short),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 10"); return(0); } printf("biBitCount=%d ",biBitCount); nb = 1; nbLu = fread (&biCompression, sizeof(int),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 11"); return(0); } printf("biCompression=%d \n\n",biCompression); nb = 1; nbLu = fread (&biSizeImage, sizeof(int),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 12"); return(0); } printf("biSizeImage=%d ",biSizeImage); nb = 1; nbLu = fread (&biXpix, sizeof(int),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 13"); return(0); } printf("biXpix=%d ",biXpix); nb = 1; nbLu = fread (&biYpix, sizeof(int),nb,imgDep); if (nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 14"); return(0); } printf("biYpix=%d \n\n",biYpix); nb = 1; nbLu = fread(&biClrUsed,sizeof(int),nb,imgDep); if(nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 4"); return(0); } printf("biClrUsed = %d ",biClrUsed); nb = 1; nbLu = fread(&biClrImportant,sizeof(int),nb,imgDep); if(nbLu!=nb) { fclose(imgDep); printf("Problemes images depart 5"); return(0); } printf("biClrImportant = %d\n\n\n\n",biClrImportant); /* for (i=0;i<biClrUsed;i++) { nb = 4; nbLu = fread(couleur,sizeof(unsigned char),nb,imgDep); if (nbLu!=nb) { fclose (imgDep); printf (" Problemes images depart 6 "); return (0); } printf("couleur %d, %d, %d, %d\n",couleur[0],couleur[1],couleur[2],couleur[3]); }*/ nb=( biWidth * biHeight * biPlanes * biBitCount )/8; printf ("nb = %d\n\n",nb); pixel = (unsigned char*) malloc (nb*sizeof(unsigned char)); if (pixel) nbLu= fread(pixel,sizeof(unsigned char),nb,imgDep); if (nbLu!=nb) { fclose (imgDep); return(0); } fclose (imgDep); //////////////////// CALCUL DE LHISTOGRAMME //////////////////////////////////////////////////////////// histo=(unsigned long*)malloc(biClrUsed*sizeof(unsigned long)); for (i=0;i<256;i++) {histo[i]=0;} for(i=0;i<nb;i++) {histo[pixel[i]]=histo[pixel[i]]+1;} char s[10]; FILE *fichisto; fichisto = fopen("C:\\Program Files\\Endoscope\\Capture\\histo3.xls","w"); for (i=0;i<256;i++) { sprintf (s,"%8d\n",histo[i]); fwrite(s,sizeof(s),1,fichisto); } fclose (fichisto); ////////////////// CALCUL DE LA LUMINANCE DE LIMAGE (OU MOYENNE DE LHISTOGRAMME) ////////////////////// int N=biHeight*biWidth; // calcul du nombre totale de pixel int g=0; for (i=0;i<=255;i++) { g= g + (i*histo[i]);} int Y= g/N; ///////////////////////////// AFFICHAGE ///////////////////////////////////////////////////////// printf(" --------------------------------------- \n"); printf(" | LUMINANCE = %d =",Y); if (Y<70) printf (" TROP SOMBRE |\n"); else printf(" IMAGE BONNE |\n"); printf(" --------------------------------------- \n\n\n\n\a"); return(0); }
20 juil. 2006 à 16:44
je veux afficher l'histogramme d'une image BMP mais en utilisant le Borland C++ builder 6, je pense qu'il faut utiliser le composant graphique TPaitBox, mais je ne sais pas qu'elle est l'instruction qui va me permettre d'afficher l'histogramme sur ce composant!
aidez moi SVP
a+
31 mai 2005 à 15:56
qu'est ce que je peux faire pour que cela puisse compiler correctement?
merci!!!!
Stephanie
27 févr. 2004 à 00:20
par contre , niveau code, peut faire meuh.. ;)
perso, j'appele ca du hardcore goret coding style
mais bon ca sa vient en codant.. donc persevere !!
deja, histoire de raccourcir un peu le code, utilise une boucle for (ou while pour une meilleure gestion des erreurs) .... et des tableaux de chaine de char...
sinon en MFC le stdio.h il aime pas tjs....
bon courage
9 janv. 2004 à 10:25
9 janv. 2004 à 10:23
Sera fait des que j'aurai un creux.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.