# a question on producing a pixel histogram of a picture

• 04-07-2007
tracyhaha
a question on producing a pixel histogram of a picture
i tried to produce a pixel histogram with dimension 256 * 256 (that shows the number of certain pixel in the histogram, see the attachment ) by writing a function, i tried to write the follwing code:

Code:

```void histogram (){         int row, col, i, j, n, x, y, f;         unsigned char image_num[256];         unsigned char image_1[HEIGHT][WIDTH], image[HEIGHT][WIDTH];         unsigned char image_2[HEIGHT][WIDTH];         readImage("SweetieCoupleBack.bmp", image);    <-- a function that can be used to read an image                 for (i = 0; i < 256; i++)                 image_num[i] = 0;                 for (row = 0; row < HEIGHT; ++row){                 for(col = 0; col < WIDTH; ++col) {                         for (i = 0;  image[row][col] = i; i++) {                                 image_num [i] ++;}                 }}                                         for (i = 0; i < 256 ; i++){                 for (x = 0; x < 256; x ++){                         for (y = 0 ; y <= image_num[i] / 256 ; y++){                                 image_2[y][x] = 255;}                 image_2[y][x] = 0;}}                                                         writeImage("Histogram.bmp", image_2);  <-- a function that can be used to write in a new image }```

however, the histogram cannot be produced, i want to ask why, and how to solve this problem, thx~~~
• 04-07-2007
quzah
What do you mean it can't be produced? What's wrong with it? What does it produce? I don't know why people on message boards can't complete their thoughts ever. No one would really have a conversation that sounded like that.

Quzah.
• 04-07-2007
You were on a roll here - good explanation of what you wanted to do, good try at code for it. I was just waiting for you to finish by posting what the problem was with your output.

It's like hearing a song and the music quits on the next to last note--> hate that! :)

This assignment in your output looks very wrong to me. Can you explain it's purpose, here:

Code:

```for (row = 0; row < HEIGHT; ++row){                 for(col = 0; col < WIDTH; ++col) {                         for (i = 0;  image[row][col] = i; i++) {                                 image_num [i] ++;}                 } } And please, show what your output is, and what you WANT it to be (if different that the attached image for input to the program). Adak```
• 04-07-2007
Salem
You should only need two nested loops to scan the source image to produce your 1D array of histogram information.

You should only need two nested loops to generate the new image from your 1D array of histogram information.