//program to calculate an histogramme from a 256*256 image in black and white //copy tha blabla? // image.h header file for MSc IT Project // Do not alter contents // simply copy to working directory include into source file as:- // #include "image.h" #include #include #include "image.h" using namespace std; void read_image(ifstream &fi, unsigned char image[] [256]); void write_image(ofstream &fo, unsigned char image[] [256]); main(int argc, char *argv[]) { //this will execute the code only if the program is launched with the command line option c if(argc==2 && strcmp(argv[1], "c") ) { // was a test to see if it worked cout << "tupue" ; //int mode= ios::binary; mode is not an int but how declare a binary? unsigned char image[256][256]; //declare the input stream ifstream binarystreamimage; binarystreamimage.open("lena", ios::binary|ios::in); //test if the image can not open and display an error if (!binarystreamimage) { cout << "can not open image \n"; exit(1); //terminate the program } //declare an array to hold the value of each pixels greyscale values int histoArray[256]; // not needed anymore : int sumpixels; int a,b,i=0; //just counter variables int morefrequentgreyscale=0; int freq[256]; int color; read_image (binarystreamimage, image); memset( freq, 0, 256 ); for (i=0;i<256;i++) { histoArray[i] =0; } for (a=0; a<256; a++){ for (b=0;b<256; b++){ /* color=image[a][b]; while(color>morefrequentgreyscale) //morefrequentgreyscale=color; morefrequentgreyscale=image[a][b]; */ color=image[a][b]; freq[color]++; if( freq[color] > morefrequentgreyscale ) morefrequentgreyscale = freq[color]; } } cout << " the more frequent Greyscale is: \t" << morefrequentgreyscale << "\n"; binarystreamimage.close(); /*execute quand il y a l'option -c*/ } else { /*les autres cas*/ //int mode= ios::binary; mode is not an int but how declare a binary? unsigned char image[256][256]; //declare the input stream ifstream binarystreamimage; binarystreamimage.open("claire", ios::binary|ios::in); //test if the image can not open and display an error if (!binarystreamimage) { cout << "can not open image \n"; exit(1); //terminate the program } //declare an array to hold the value of each pixels greyscale values int histoArray[256]; // not needed anymore : int sumpixels; int a,b,i=0; //just counter variables read_image (binarystreamimage, image); //now the array image [i][j] contains the value of tyhe elements in row i, and in colum j //mikmak to store the values in the array? /*int ValGrey[256]; //il faut passer toutes les lignes de l'image en revue for(unsigned int ligne=0;ligne<256; ligne++) { //pour chaque ligne, il faut passer toutes les colones en revue for(unsigned int colone=0;colone<256;colone++) { //il faut récupérer la valeur du point en image[ligne][colone] char recup=image[ligne][colones]; //et incrémnter le compteur adequat ValGrey[recup]++; } } //il ne reste plus qu'à faire afficher toutes ces valeurs for(unsigned int i=0;i<256;i++) { std::cout<<"nombre de "<