a question on producing a pixel histogram of a picture

This is a discussion on a question on producing a pixel histogram of a picture within the C Programming forums, part of the General Programming Boards category; i tried to produce a pixel histogram with dimension 256 * 256 (that shows the number of certain pixel in ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    1

    Question 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~~~
    Attached Images Attached Images  

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,767
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 09:55 AM
  2. Question about the C99 standard (concerning union)
    By coyotte508 in forum C Programming
    Replies: 4
    Last Post: 05-07-2008, 03:57 PM
  3. Max & Min value and refine histogram
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 07-20-2002, 09:04 AM
  4. Still can't print a Histogram from fail input
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 07-11-2002, 01:24 PM
  5. what does this warningmean???
    By kreyes in forum C Programming
    Replies: 5
    Last Post: 03-04-2002, 07:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21