xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
You can try it in a testbed. Create a small program that just sets up a test array and runs the above code on it, then displays the value of highest. If that corresponds to the maximum value setup then you can be confident it works.

In what way is the histogram distorted when you use array1[i]/262144? Can you post a screenshot?
metamofia's Avatar
Go4Expert Member
okay, i will post it below pls have a look.
Attached Images
File Type: jpg clip_image008.jpg (30.7 KB, 2 views)
metamofia's Avatar
Go4Expert Member
however, i managed to work on that AFTER coming up with:
Code:

int highest=0;
for (int i=0; i<256; i++)
{
if (array1[i] > array1[highest])
highest = i;
}


and i managed to edit into this:
Code:

CPen* gOldPen = pDC->SelectObject(&greenPen);//green colour pen for histogram lines
//starting of histogram drawing (intensity vs pixel value)
pDC->MoveTo(600, 398);
for (i=1; i<255; i++)
{ 
pDC->MoveTo(600+i, 398);
pDC->LineTo(600+i, array1[i]/262144);
}
and i got a proper histogram but just that its not drawn to scale. any idea why is this so?

Attached Images
File Type: jpg clip_image009.jpg (27.7 KB, 4 views)

Last edited by metamofia; 6Oct2009 at 09:04.. Reason: typo error
metamofia's Avatar
Go4Expert Member
sorry, i mean this code:

Code:
 
CPen* gOldPen = pDC->SelectObject(&greenPen);
//starting of histogram drawing (intensity vs pixel value)
pDC->MoveTo(600, 398);
for (i=1; i<256; i++)
{ 
pDC->MoveTo(600+i, 398);
pDC->LineTo(600+i, (398-array1[i]*398/array1[highest]));
}
that got me the histogram which is not scaled.

Last edited by metamofia; 6Oct2009 at 11:37..
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
What I do in cases like this, if I can't step through the code in a debugger, is to start writing "debug" information to a log file, showing where in the code it is, and anything relevant (comments, values of variables etc) that might help me find out why the code isn't doing what I expect it to.

So in this case since the code in red presumably isn't working, add an fprintf before that line that writes relevant information out to a file (which you've previously opened with fopen()), perhaps printing i, array[i], array[highest], the result of the calculation and anything else relevant you can think of. Don't worry that you have to get it all right first time; you won't, and as you go back over the code and the log file you may realise you could use something else from the code, so just add that extra bit in and rerun the program.

As you read the code try to determine what you think the code SHOULD BE doing, and use the log file to determine what the code IS ACTUALLY doing. Then by comparing the two you should be able to work out what is wrong.
metamofia's Avatar
Go4Expert Member
okay where do i have to find to display the debugging information? and where can the log file be found at? thanks
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
I don't understand the first question, and the answer to the second is wherever you put the file. It was you that specified the parameters to the fopen() function. Default directory is often the program's current directory, but you can specify an exact location with fopen("c:\\some\\path\\file.txt","w");
metamofia's Avatar
Go4Expert Member
okay thanks