|
Go4Expert Member
|
|
| 2Oct2009,14:04 | #21 |
|
Hmm, i tried my best. Oh, is it 0-3? Or perhaps it's 100-200? Thanks for replying
|
|
Go4Expert Member
|
|
| 2Oct2009,14:15 | #22 |
|
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.
|
|
Mentor
|
![]() |
| 2Oct2009,14:42 | #23 |
|
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);
}
}
|
|
Go4Expert Member
|
|
| 5Oct2009,07:33 | #24 |
|
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? |
|
Go4Expert Member
|
|
| 5Oct2009,07:41 | #25 |
|
hi this is the image sorry for mising out on the prev post.
|
|
Mentor
|
![]() |
| 5Oct2009,11:55 | #26 |
|
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? |
|
Go4Expert Member
|
|
| 5Oct2009,12:23 | #27 |
|
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); } |
|
Go4Expert Member
|
|
| 5Oct2009,12:34 | #28 |
|
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. |
|
Mentor
|
![]() |
| 5Oct2009,13:24 | #29 |
|
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. |
|
Go4Expert Member
|
|
| 5Oct2009,13:37 | #30 |
|
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;
}
Last edited by metamofia; 5Oct2009 at 13:44.. |

