1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
//program to calculate an histogramme from a 256*256 image in black and white
#include <fstream>
#include <iostream>
#include "image.h"
#include <algorithm>
#include <iterator>
#include <vector>
using namespace std;
//do the definition of the functions
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") )
{ //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
}
read_image (binarystreamimage, image);
int freq[256]; // valeur de couleur est codé de 0 à 255
int color=0;
int morefrequentgreyscale=0;
memset( freq, 0, 256 );
for (int a=0; a<256; a++)
{
for (int b=0;b<256; b++){
color=image[a][b];
freq[color]++;
//if( freq[color] > morefrequentgreyscale )
//morefrequentgreyscale = freq[color];
}
}
int index = distance(histogramme.begin(),
max_element(histogramme.begin(), histogramme.end()));
cout << "tamere: \t" << index << "\n"; |
Partager