Hello, Im programming an image reader and I need to print out a histogram that shows how many times a given pixel value is present in a image - actually it doesn't have to be the graph, just a table with two columns would be enough

i have written a class for the whole program but i have everything else working except the histogram, any suggestions would be appreciated

# include <iostream>						
# include <fstream>
# include <string>
# include <cmath>
# include <iomanip>
# include <ctime>

using namespace std;

class image									
{
private:									
    int height, width, depth;
    char header[100];
    char line[100];
    char comment;
    short **data;
    
public:										
    ifstream fin;
    ofstream fout;
    string filename;


    void reader();							
    void writer();
    void rotate_clock();
    void rotate_anti();
    void resize();
    void histogram();
    void delete_p();
};

and heres the function i have written

void image::histogram()
{
	int counter[256];

	for (int z=0; z<256; z++)
	{
		counter[z]=0;
	}
	counter[264]=depth;

	for (int value=0; value<=depth; value++)
	{
		cout<<setw(7)<<value<<setw(17)<<counter[depth]<<endl;
		counter[depth]++;
	}
}

i have no idea how to get it to work

> char comment;
How big a comment?

> counter[264]=depth;
Do array bounds mean anything to you?

What is depth?

The basics for a histogram is
counter[pixel]++
for all pixels

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.