metamofia's Avatar
Go4Expert Member
Hmm, i tried my best. Oh, is it 0-3? Or perhaps it's 100-200? Thanks for replying
metamofia's Avatar
Go4Expert Member
Hi! I think i finally got what you meant actually. Okay for image[] it has 262144 values ranging from 0-255. For image256[] it has 65536 values ranging from 0-255. I hope i answered rightly this time. Hope to hear frm u soon.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Yes, I think you had a mental block before where you assumed that an array with N elements could only contain the values from 0-N.

OK, so this shows that array1 is correctly defined as having 256 elements and that the crash you reported earlier isn't caused by writing past the end of array1.

Looking at the code:
Code:
if(no_of_rows == 512 && no_of_cols == 512)
{
  { 
    pDC->MoveTo(600+i, 398);
    pDC->LineTo(600+i, array1[i]/262144);
  }
}
(not sure why the double braces), does this display correctly? If so then I'd suggest the red code should be changed to array1[i]/65536.
metamofia's Avatar
Go4Expert Member
hi, i tried the code u given me and i just got a flat horizontal line like the one attached below. well right now, my supervisor wanted me me to do a for loop for finding which intensity value has the most number of pixel
ie:
array1[40] = 5409
array1[300] = 492

so the intensity of 300 has the most pixel value. to do this i have to do the 'for' loop. any idea how about do i start from?
metamofia's Avatar
Go4Expert Member
hi this is the image sorry for mising out on the prev post.
Attached Images
File Type: jpg clip_image006.jpg (29.8 KB, 1 views)
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
How can array1[300] exist when it is only defined to have 256 elements? I thought we'd settled this question, remember the whole "range of image256[]" discussion?

If you really do have array1[300] then as it is defined unsigned short array1[256] then you have undefined behaviour due to the very common bug of writing past the end of an array.

I don't understand the question. This for loop isn't difficult to write. How far have you got with it and what have you tried? Can you think of an algorithm for how to determine the highest number in an array?

Also you didn't answer a rather important question (note: ALL questions I ask are important, so if you don't understand why I asked something, feel free to ask why I asked and I'll explain): does the "array1[i]/262144" loop display correctly?
metamofia's Avatar
Go4Expert Member
oh sorry it was a typo. i was in a rush bit today. im still trying to forge an algorithm to determine which intensity value has the most number of pixels, so with this i can use proportion to display the histogram within the scale. well i dont really understand what u meant by does the "array1[i]/262144" loop display correctly? do u mean by if there's anything showing up when i put it as array1[i]/262144? as the matter of fact im just trying to play around with the code in red below. thanks for ur help


{
pDC->MoveTo(600+i, 398);
pDC->LineTo(600+i, array[i]/262144);
}
metamofia's Avatar
Go4Expert Member
but as for now, i have been given the task to find the highest value in array1[i] ie
array1[200]=5000
array1[3]=4003
array[49]=592

so in this case i want my code to identify that array1[200] has the highest number of pixel corresponding to intensity 200 in the image. i never wrote this kind of codes before so im guessing a for loop with a if statement? help me thanks alot.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
What you're asking is spectacularly easy, just think about it for a few minutes. You can do it in two lines of code. This is the problem with the internet, it's too easy to post a question, so you don't bother trying to figure it out for yourself.

> im guessing a for loop with a if statement?

Well, rather than posting your guesses, why not write some code around that guess and see what happens? If it solves the immediate problem then you're sorted. If not, note down what happens so that when you want some code that does that, you've already worked it out.

Don't really know how to express "does it display correctly" in simpler terms. If you don't understand the question then I recommend you invest in a dictionary.
metamofia's Avatar
Go4Expert Member
oh, okay well i was thinking of this:

Code:
int highest=0;
  for (int i=0; i<256; i++)
{
      if (array1[i] > array1[highest])
      highest = i;
}
what do you think? i cant check it if it was right or wrong in my programme cos this dont display anything. and if u were asking about the display of histogram, nope. its distorted when i run it when i input array1[i]/262144.

Last edited by metamofia; 5Oct2009 at 13:44..