1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

histogram equalization for medical images

Discussion in 'C' started by metamofia, Sep 28, 2009.

  1. metamofia

    metamofia New Member

    Joined:
    Sep 28, 2009
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    hi, im currently on a final year project and im doing hist. equalization for medical images. im progressing pretty alright.. so far, i have came up with codes to do this project.

    Code:
    void CLEO_MedivisionView::OnToolsHistogram()
    {
    // TODO: Add your command handler code here
        int x_tick, y_tick;
        int j;
        int a_loop, b_loop;
        int k, t, f, i;
        int x;
        int q;
        unsigned int intMFC;
        unsigned int intMFC1;
        unsigned int intMFC2;
        unsigned short array1[256];
        char c[10];
        char p[10];
        char l[10];
        CString MFCString;
    //unsigned short array1[65535];
        pDC = GetDC(); //OnDraw member function
        hdc = pDC->GetSafeHdc();
        CPen aPen;
        aPen.CreatePen(PS_SOLID, 2, RGB(255, 225, 225));
        CPen* pOldPen = pDC->SelectObject(&aPen);
    
        pDC->MoveTo(600,400); //drawing of x-axis
        pDC->LineTo(920,400);
        pDC->MoveTo(920,400);
        pDC->LineTo(915,405);
        pDC->MoveTo(920,400);
        pDC->LineTo(915,395); //drawing of x-axis
    
        x_tick = 600; //declaring constants
        y_tick = 400;
        for (j=1; j<=10; j++) //control the loop so that it draws ticks every 30 pixels
        {
            pDC->MoveTo(x_tick+(j*30),y_tick-5);
            pDC->LineTo(x_tick+(j*30),y_tick+5);
        }
        pDC->MoveTo(600,400); //drawing of y-axis
        pDC->LineTo(600,80);
        pDC->MoveTo(600,80);
        pDC->LineTo(605,85);
        pDC->MoveTo(600,80);
        pDC->LineTo(595,85); //drawing of y-axis
        for (t=1; t<=10; t++) //control the loop so that it draws ticks every 30 pixels
        {
            pDC->MoveTo(x_tick-5,y_tick-(t*30));
            pDC->LineTo(x_tick+5,y_tick-(t*30));
        }
        intensity= "Intensity"; //labelling of x-axis
        SetBkColor(hdc, RGB(0, 0, 0));
        SetTextColor(hdc, RGB(255, 255 ,255 ));
        TextOut(hdc, 930, 390, LPCTSTR(intensity), 9);
        pixels = "Pixels"; //labelling of y-axis
        SetTextColor(hdc, RGB(255, 255 ,255 ));
        TextOut(hdc, 580, 55, LPCTSTR(pixels), 6);
        numeric = "0"; //number zero (universal)
        SetTextColor(hdc, RGB(95, 158, 160));
        TextOut(hdc, 585, 400, LPCTSTR(numeric),1);
        intMFC = 0; //declaring constants
        a_loop = 595;
        for (k=1; k<=5; k++) //for every two ticks, draw legend of +52 each time it loops
        {
            intMFC = intMFC+52;
            itoa(intMFC,c,10);
            CString MFCString;
            MFCString = c;
            if (intMFC<100) //if number is XX then just show 2 digits
            {
                test = c;
                SetTextColor(hdc, RGB(95, 158 ,160));
                TextOut(hdc, a_loop+(k*60), 405, LPCTSTR(test), 2);
            }
            else if (intMFC>=100) //if number is XXX then show 3 digits
            {
                test = c;
                SetTextColor(hdc, RGB(95, 158, 160));
                TextOut(hdc, a_loop+(k*60), 405, LPCTSTR(test), 3);
            }
        }
        intMFC1 = 0; //declaring of contants
        intMFC2 = 0;
        b_loop = 392;
    
        if (no_of_rows == 256 && no_of_cols == 256) // opens if image its by 256*256
    
        {
            for (f=1; f<=5; f++) // for 5-ticks axis
            {
                intMFC1 = (((256 * 256)/5)+0.3) * f; // calculate each of the 5 marking is +13107
                itoa(intMFC1,p,10);
                CString MFCString;
                MFCString = p;
                test1 = p;
                SetTextColor(hdc, RGB(95, 158 ,160));
                TextOut(hdc, 540, b_loop-(f*60), LPCTSTR(test1), 5); // type casting
            }
        }
        else if (no_of_rows == 512 && no_of_cols == 512) // if image is 512*512 run this
        {
            for (q=1; q<=5; q++) // for 5-ticks axis
            {
                intMFC2 = (((512 * 512)/5)+0.8) * q; // to calculate each marking is +52428
                itoa(intMFC2,l,10);
    
                MFCString = l;
                if (intMFC2<100000) //'if' statement used because if digit is less
    //than 100000, it shows crap at the last digit position
                {
                    test2 = l;
                    SetTextColor(hdc, RGB(95, 158 ,160));
                    TextOut(hdc, 540, b_loop-(q*60), LPCTSTR(test2), 5);
                }
                else if (intMFC2>=100000) //if digit is more or equal to 100000, do this
                {
                    test2 = l;
                    SetTextColor(hdc, RGB(95, 158, 160));
                    TextOut(hdc, 540, b_loop-(q*60), LPCTSTR(test2),6);
                }
            }
        }
    
    
    //count pixel intensity
    //'for' loop couting from 0 to 255 which simply zeros out each element in array1 to prepare the array to do the count of the bytes in the image
        for (i=0;i<255;i++)
        {
            array1[i]=0;
        }
    //'for' loop to loop through the bytes of the image
        for (i=0; i<262143; i++)
        {
            array1[image[i]]++;
        }
    

    so this is the code so far and i have commented out the function of each code descriptions.. right now i have write up the code to get the pixel value of the image. so i need to draw lines on the histogram to represent it.. how do i go about doing it?

    i will attach what its suppose to display until this codes in this thread. thanks for the help in adv!
     

    Attached Files:

    Last edited by a moderator: Sep 28, 2009
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    > 'for' loop to loop through the bytes of the image

    OK, one way to check the colour if an individual pixel is to call GetPixel which will return the RGB() value it finds at that point on the screen. So GetPixel(x,y) where (x,y) is black will return RGB(0,0,0). Probably if the image is greyscale then R=G=B but if not you'll need to find some way of computing intensity from three RGB values.

    However if you prefer to get the data directly from image[] then you'll need to know how image[n] is converted to one or more pixels on the screen, and you can use that to calculate the intensity of the pixel(s) represented by each entry in image[].

    Otherwise array1[image]++; (as you already have done) seems a good way to me of increasing the count for each individual intensity value, and the representation for that in the histogram could just be a case of drawing a vertical line that is array1[n] pixels long at x=n, and from the code I can see you already know how to draw a straight line.
     
  3. metamofia

    metamofia New Member

    Joined:
    Sep 28, 2009
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    hey thanks for replying to my post. so i wanna draw a vertical line for example:
    pDC->MoveTo(x,y);
    pDC->LineTo(x,y);

    the values of x need to be in referrence with image and y would be in referrence to i? or is it vice versa?
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Depends which way round you're drawing it. You could experiment and see which way fits what you had in mind.
    If you're drawing a series of horizontal lines, say:
    Code:
    ------
    --------------
    -
    
    ---------------------
    -----------------
    
    then MoveTo(0,i) and LineTo(image,i) could do the trick, or if vertical lines coming up from the bottom then you'll have to swap the parameters and do some subtraction (because (0,0) is at the top left, not at the bottom left according to the normal rules of graphing).
     
  5. metamofia

    metamofia New Member

    Joined:
    Sep 28, 2009
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    yeah.. i tried it but nothing displays on the graph.. is there any alternative way that i could do to troubleshoot this?
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    What is the code in the for loop? It's difficult to determine what's wrong with it if I can't see it.
     
  7. metamofia

    metamofia New Member

    Joined:
    Sep 28, 2009
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    ouh which for loop you are talking about? the most recent for loop is to calculate the pixel intensity. so i actually want to draw a line for 'testing' if the code which i wrote ACTUALLY works, or otherwise.
     
  8. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    In your previous post you said "i tried it but nothing displays on the graph". That's the code I'm talking about. You know, the code that doesn't work and that I can't work out what's wrong with it if I can't see it? It might not be in a for loop, there are other ways of looping, but for is the most likely.
     
  9. metamofia

    metamofia New Member

    Joined:
    Sep 28, 2009
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    hi thanks for replying. well somehow i have edited the codes over time. i will update to u about it now.

    Code:
    [SIZE=2][COLOR=#00ffff][SIZE=2][COLOR=#00ffff]
    [COLOR=black]//**************************************************************************************//[/COLOR]
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2][COLOR=black]void[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] CLEO_MedivisionView::OnUpdateToolsHistogram(CCmdUI *pCmdUI)[/COLOR]
    [COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]// TODO: Add your command update UI handler code here[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black][/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]if[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] (fileopen) {[/COLOR]
    [COLOR=black]pCmdUI->Enable([/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]true[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]);[/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]else[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] {[/COLOR]
    [COLOR=black]pCmdUI->Enable([/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]false[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]);[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]void[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] CLEO_MedivisionView::OnToolsHistogram()[/COLOR]
    [COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]// TODO: Add your command handler code here[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] x_tick, y_tick;[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] j;[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] a_loop, b_loop;[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] k, t, f, i;[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] x;[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] q;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]unsigned[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]int[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black] intMFC;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]unsigned[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]int[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black] intMFC1;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]unsigned[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]int[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black] intMFC2;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]unsigned[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]short[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black] array1[256];[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]char[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] c[10];[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]char[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] p[10];[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]char[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] l[10];[/COLOR]
    [COLOR=black]CString MFCString;[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//unsigned short array1[65535];[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]pDC = GetDC(); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//OnDraw member function[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]hdc = pDC->GetSafeHdc();[/COLOR]
    [COLOR=black]CPen aPen;[/COLOR]
    [COLOR=black]aPen.CreatePen(PS_SOLID, 2, RGB(255, 225, 225));[/COLOR]
    [COLOR=black]CPen* pOldPen = pDC->SelectObject(&aPen);[/COLOR]
    [COLOR=black] [/COLOR]
    [COLOR=black]pDC->MoveTo(600,400); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//drawing of x-axis[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]pDC->LineTo(920,400);[/COLOR]
    [COLOR=black]pDC->MoveTo(920,400);[/COLOR]
    [COLOR=black]pDC->LineTo(915,405);[/COLOR]
    [COLOR=black]pDC->MoveTo(920,400);[/COLOR]
    [COLOR=black]pDC->LineTo(915,395); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//drawing of x-axis[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black][/COLOR]
    [COLOR=black]x_tick = 600; [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//declaring constants[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]y_tick = 400;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]for[/SIZE][/SIZE][SIZE=2][SIZE=2](j=1; j<=10; j++) [/SIZE][/SIZE][SIZE=2][SIZE=2]//control the loop so that it draws ticks every 30 pixels
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]pDC->MoveTo(x_tick+(j*30),y_tick-5); [/COLOR]
    [COLOR=black]pDC->LineTo(x_tick+(j*30),y_tick+5); [/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]pDC->MoveTo(600,400); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//drawing of y-axis[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]pDC->LineTo(600,80);[/COLOR]
    [COLOR=black]pDC->MoveTo(600,80);[/COLOR]
    [COLOR=black]pDC->LineTo(605,85);[/COLOR]
    [COLOR=black]pDC->MoveTo(600,80);[/COLOR]
    [COLOR=black]pDC->LineTo(595,85); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//drawing of y-axis[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]for[/SIZE][/SIZE][SIZE=2][SIZE=2](t=1; t<=10; t++) [/SIZE][/SIZE][SIZE=2][SIZE=2]//control the loop so that it draws ticks every 30 pixels
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]pDC->MoveTo(x_tick-5,y_tick-(t*30)); [/COLOR]
    [COLOR=black]pDC->LineTo(x_tick+5,y_tick-(t*30));[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]intensity= [/COLOR][/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]"Intensity"[/SIZE][/SIZE][SIZE=2][SIZE=2]; [/SIZE][/SIZE][SIZE=2][SIZE=2]//labelling of x-axis
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]SetBkColor(hdc, RGB(0, 0, 0));[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(255, 255 ,255 ));[/COLOR]
    [COLOR=black]TextOut(hdc, 930, 390, LPCTSTR(intensity), 9);[/COLOR]
    [COLOR=black]pixels = [/COLOR][/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]"Pixels"[/SIZE][/SIZE][SIZE=2][SIZE=2]; [/SIZE][/SIZE][SIZE=2][SIZE=2]//labelling of y-axis
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]SetTextColor(hdc, RGB(255, 255 ,255 ));[/COLOR]
    [COLOR=black]TextOut(hdc, 580, 55, LPCTSTR(pixels), 6); [/COLOR]
    [COLOR=black]numeric = [/COLOR][/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]"0"[/SIZE][/SIZE][SIZE=2][SIZE=2]; [/SIZE][/SIZE][SIZE=2][SIZE=2]//number zero (universal)
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]SetTextColor(hdc, RGB(95, 158, 160));[/COLOR]
    [COLOR=black]TextOut(hdc, 585, 400, LPCTSTR(numeric),1);[/COLOR]
    [COLOR=black]intMFC = 0; [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//declaring constants[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]a_loop = 595;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]for[/SIZE][/SIZE][SIZE=2][SIZE=2](k=1; k<=5; k++) [/SIZE][/SIZE][SIZE=2][SIZE=2]//for every two ticks, draw legend of +52 each time it loops
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{ [/COLOR]
    [COLOR=black]intMFC = intMFC+52;[/COLOR]
    [COLOR=black]itoa(intMFC,c,10);[/COLOR]
    [COLOR=black]CString MFCString;[/COLOR]
    [COLOR=black]MFCString = c;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2](intMFC<100) [/SIZE][/SIZE][SIZE=2][SIZE=2]//if number is XX then just show 2 digits
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]test = c;[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(95, 158 ,160));[/COLOR]
    [COLOR=black]TextOut(hdc, a_loop+(k*60), 405, LPCTSTR(test), 2);[/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]else[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2](intMFC>=100) [/SIZE][/SIZE][SIZE=2][SIZE=2]//if number is XXX then show 3 digits
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]test = c;[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(95, 158, 160));[/COLOR]
    [COLOR=black]TextOut(hdc, a_loop+(k*60), 405, LPCTSTR(test), 3);[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]intMFC1 = 0; [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//declaring of constants[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]intMFC2 = 0;[/COLOR]
    [COLOR=black]b_loop = 392;[/COLOR]
    [COLOR=black][/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2] (no_of_rows == 256 && no_of_cols == 256) [/SIZE][/SIZE][SIZE=2][SIZE=2]// initiate if image its by 256*256
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]for[/SIZE][/SIZE][SIZE=2][SIZE=2](f=1; f<=5; f++) [/SIZE][/SIZE][SIZE=2][SIZE=2]// for 5-ticks axis
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{ [/COLOR]
    [COLOR=black]intMFC1 = (((256 * 256)/5)+0.3) * f; [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]// calculate each of the 5 marking is +13107[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]itoa(intMFC1,p,10); [/COLOR]
    [COLOR=black]CString MFCString;[/COLOR]
    [COLOR=black]MFCString = p;[/COLOR]
    [COLOR=black]test1 = p;[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(95, 158 ,160));[/COLOR]
    [COLOR=black]TextOut(hdc, 540, b_loop-(f*60), LPCTSTR(test1), 5); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]// type casting[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]} [/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]else[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2] (no_of_rows == 512 && no_of_cols == 512) [/SIZE][/SIZE][SIZE=2][SIZE=2]// if image is 512*512 run this
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]for[/SIZE][/SIZE][SIZE=2][SIZE=2](q=1; q<=5; q++) [/SIZE][/SIZE][SIZE=2][SIZE=2]// for 5-ticks axis 
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{ [/COLOR]
    [COLOR=black]intMFC2 = (((512 * 512)/5)+0.8) * q; [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]// to calculate each marking is +52428[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]itoa(intMFC2,l,10); [/COLOR]
    [COLOR=black][/COLOR]
    [COLOR=black]MFCString = l; [/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2](intMFC2<100000) [/SIZE][/SIZE][SIZE=2][SIZE=2]//'if' statement used because if digit is less
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//than 100000, it shows crap at the last digit position[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]test2 = l;[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(95, 158 ,160));[/COLOR]
    [COLOR=black]TextOut(hdc, 540, b_loop-(q*60), LPCTSTR(test2), 5); [/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]else[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2](intMFC2>=100000) [/SIZE][/SIZE][SIZE=2][SIZE=2]//if digit is more or equal to 100000, do this
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]test2 = l;[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(95, 158, 160));[/COLOR]
    [COLOR=black]TextOut(hdc, 540, b_loop-(q*60), LPCTSTR(test2),6);[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black] [/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//count pixel intensity[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black][/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//'for' loop couting from 0 to 255 which simply zeros out each element in array1 to prepare the array to do the count of the bytes in the image[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]for[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] (i=0;i<255;i++) [/COLOR]
    [COLOR=black]{[/COLOR]
    [COLOR=black]array1[i]=0;[/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]if[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] (no_of_rows == 512 && no_of_cols == 512)[/COLOR]
    [COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//'for' loop to loop through the bytes of the image[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]for[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] (i=0; i<262143; i++)[/COLOR]
    [COLOR=black]{ [/COLOR]
    [COLOR=black]array1[image[i]]++;[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]else[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]if[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black] (no_of_rows == 256 && no_of_cols == 256)[/COLOR]
    [COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]for[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] (i=0; i<65535; i++)[/COLOR]
    [COLOR=black]{[/COLOR]
    [COLOR=black]array1[image256[i]]++;[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black][/COLOR]
    [COLOR=black] [/COLOR]
    [COLOR=black] [/COLOR]
    [COLOR=darkgreen]pDC->MoveTo( 600, 400);[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=darkgreen]for[/COLOR][/SIZE][/SIZE][SIZE=2][COLOR=#ffffff][SIZE=2][COLOR=#ffffff][COLOR=darkgreen] (i=1; i<255; i++)[/COLOR]
    [COLOR=darkgreen]{[/COLOR]
    [COLOR=darkgreen]pDC->MoveTo( 600 + i, 400);[/COLOR]
    [COLOR=red]pDC->LineTo( 600 + i, Y );[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}
    [/COLOR]

    the code in green and red is the new addition to it and its supposed to draw lines for the number of pixels in respect to its intensity value ie how many pixels has a value of 20. so this code is somewhat 'approved' from my supervisor. the only thing is that, the code line in red needs to be changed. im not too sure what i should input on the position 'Y'. i can try a few errors but i get my app to crash at times. so maybe u can help me on what to replace the Y with. thanks in advance!
    [/COLOR][/SIZE][/COLOR][/SIZE]
     
  10. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Did you try 400-array1?

    This may need scaling though if array1 ever exceeds 400 (so if array can reach 800, then you'll need to divide by 2 to fit the graph to the screen).

    What is the range of numbers stored in image256 (ie what are the min and max)?
     
  11. metamofia

    metamofia New Member

    Joined:
    Sep 28, 2009
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    hi, the values in image256 is from 0-65535. i tried what u asked me to do. what i got is a distorted histogram with some of it go below negative values. i will post the image on the attachment here. anysuggestions?
     

    Attached Files:

  12. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    > the values in image256 is from 0-65535

    That'll be why you get the crash then. array1 is defined as only having 256 elements, so if, for example, image256[N]=4000, then array1[image256[N]]++ will attempt to update array1[4000], which doesn't exist. If image256 can contain values from 0-65535 then array1 must be defined unsigned short array1[65536].

    The negative values suggest wraparound, i.e. some values of array1 exceed the maximum value for unsigned short. What compiler are you using?
     
  13. metamofia

    metamofia New Member

    Joined:
    Sep 28, 2009
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    ouh im lost here. array1 has 256 element which will represent the pixel intensity from 0-255 yeah? image and image256 are variables to represent 512*512 and 256*256 image. if so, how does this clash? im using microsoft visual studio 2005 if thats what ur asking yeah. anyway if possible let me know what codes i should replace with my current set of codes. thanks alot!
     
  14. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    > array1 has 256 element which will represent the pixel intensity from 0-255 yeah?

    Well, you're designing the software so you should know what thhe various arrays and variables are for. But as I understand it, no, array1 counts the number of pixels at intensity i, so if the original image contains 250 pixels at intensity 17, then array[17] will equal 250.

    OK, sorry, I hadn't noticed you had image[] and image256[] as different arrays. Try using sensible names! So with reference to:
    Code:
    for (i=0; i<262143; i++)
    { 
    array1[image[i]]++;
    }
    
    what is the range of values that image can contain? And with reference to:
    Code:
    for (i=0; i<65535; i++)
    {
    array1[image256[i]]++;
    }
    
    what is the range of values that image256 can contain?

    With reference to both, why are you updating array1 from both image and image256?

    In VS2005 I think unsigned short is 2 bytes but check that with sizeof(), or search the help. So this means the maximum value is 65535, but for values over 32767 it is possible these will be considered negative by the WinAPI functions and so scaling is likely to be needed. If you want to map these values to a line from 0-400 pixels long then first multiply array1 by 400 (make sure you have enough headroom in the integer type you're using) then divide by the maximum possible value of array1.

    So for example if array1 can contain values from 0-65535, then you should calculate array1*400/65535 and this will scale the value to the correct range. 65535*400=26214000 so make sure you're using integers that can contain values this high (so probably it's worth using 32-bit integers for the scaling calculation).

    Prior to plotting, you could scan array1 checking for the maximum value then scale it accordingly, let's say the maximum value is in mx, then the calculation would be array1*400/mx.
     
  15. metamofia

    metamofia New Member

    Joined:
    Sep 28, 2009
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    hi, for image[] it should contain 0-262143 and image256[] should have 0-65535. so at ur advise, which set of codes do i need to change? and change to what? yeah my supervisor told me about scaling too. i came up with the equation too but i think i should at least see a HISTOGRAM before i can do any scaling cos i might never know i might be wrong prior to what i have done so far in the codes.
     
  16. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Hmm...

    > for image[] it should contain 0-262143 and image256[] should have 0-65535
    Code:
    for (i=0; i<262143; i++) { array1[image[i]]++; }
    for (i=0; i<65535; i++) { array1[image256[i]]++; }
    
    Seems a bit of a coincidence. Are you answering the question that I asked?

    What you're saying is that image[] contains 262143 values that can each be in the range 0-262143, and image256 contains 65535 values that can each be in the range 0-65535.

    Or are you saying that image[] contains 262143 values that can be in the range UNKNOWN1-UNKNOWN2, and image256 contains 65535 values that can each be in the range UNKNOWN3-UNKNOWN4?

    If the latter please fill in the four unknowns, because that's actually what I'm trying to determine.
     
  17. metamofia

    metamofia New Member

    Joined:
    Sep 28, 2009
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    Hi, when you were saying about range, do you mean the numbr of pixels? or the range of intensity value?
     
  18. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Neither. I'm asking about the numeric values in the array. So if, say, the smallest possible number that can be found in image256 is 23 and the biggest is 76, then the range of image256 is 23-76.
     
  19. metamofia

    metamofia New Member

    Joined:
    Sep 28, 2009
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    oh, okay understood. the range for the array image[] is 0-262143 (512*512=262144 numbers) and for array image256[] is 0-65535 (256*256=65536 numbers). i hope this helps. thanks :) the code below is the latest updated one so u might want to refer to this one and not the rest. thanks alot :)

    Code:
    [SIZE=2][COLOR=#00ffff][SIZE=2][COLOR=#00ffff]
    [COLOR=black]//**************************************************************************************//[/COLOR]
    [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][SIZE=2][COLOR=black]void[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] CLEO_MedivisionView::OnUpdateToolsHistogram(CCmdUI *pCmdUI)[/COLOR]
    [COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]// TODO: Add your command update UI handler code here[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black][/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]if[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] (fileopen) {[/COLOR]
    [COLOR=black]pCmdUI->Enable([/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]true[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]);[/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]else[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] {[/COLOR]
    [COLOR=black]pCmdUI->Enable([/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]false[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]);[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]void[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] CLEO_MedivisionView::OnToolsHistogram()[/COLOR]
    [COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]// TODO: Add your command handler code here[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] x_tick, y_tick;[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] j;[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] a_loop, b_loop;[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] k, t, f, i;[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] x;[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]int[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] q;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]unsigned[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]int[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black] intMFC;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]unsigned[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]int[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black] intMFC1;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]unsigned[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]int[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black] intMFC2;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]unsigned[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]short[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black] array1[256];[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]char[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] c[10];[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]char[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] p[10];[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]char[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] l[10];[/COLOR]
    [COLOR=black]CString MFCString;[/COLOR]
    [COLOR=black][/COLOR]
    [COLOR=black]pDC = GetDC(); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//OnDraw member function[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]hdc = pDC->GetSafeHdc();[/COLOR]
    [COLOR=black]CPen aPen, greenPen;[/COLOR]
    [COLOR=black]aPen.CreatePen(PS_SOLID, 2, RGB(255, 225, 225));[/COLOR]
    [COLOR=black]greenPen.CreatePen(PS_SOLID, 1, RGB(124, 252, 0));[/COLOR]
    [COLOR=black]CPen* pOldPen = pDC->SelectObject(&aPen);[/COLOR]
    [COLOR=black] [/COLOR]
    [COLOR=black]pDC->MoveTo(600,400); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//drawing of x-axis[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]pDC->LineTo(920,400);[/COLOR]
    [COLOR=black]pDC->MoveTo(920,400);[/COLOR]
    [COLOR=black]pDC->LineTo(915,405);[/COLOR]
    [COLOR=black]pDC->MoveTo(920,400);[/COLOR]
    [COLOR=black]pDC->LineTo(915,395); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//drawing of x-axis[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black][/COLOR]
    [COLOR=black]x_tick = 600; [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//declaring constants[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]y_tick = 400;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]for[/SIZE][/SIZE][SIZE=2][SIZE=2](j=1; j<=10; j++) [/SIZE][/SIZE][SIZE=2][SIZE=2]//control the loop so that it draws ticks every 30 pixels
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]pDC->MoveTo(x_tick+(j*30),y_tick-5); [/COLOR]
    [COLOR=black]pDC->LineTo(x_tick+(j*30),y_tick+5); [/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]pDC->MoveTo(600,400); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//drawing of y-axis[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]pDC->LineTo(600,80);[/COLOR]
    [COLOR=black]pDC->MoveTo(600,80);[/COLOR]
    [COLOR=black]pDC->LineTo(605,85);[/COLOR]
    [COLOR=black]pDC->MoveTo(600,80);[/COLOR]
    [COLOR=black]pDC->LineTo(595,85); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//drawing of y-axis[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]for[/SIZE][/SIZE][SIZE=2][SIZE=2](t=1; t<=10; t++) [/SIZE][/SIZE][SIZE=2][SIZE=2]//control the loop so that it draws ticks every 30 pixels
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]pDC->MoveTo(x_tick-5,y_tick-(t*30)); [/COLOR]
    [COLOR=black]pDC->LineTo(x_tick+5,y_tick-(t*30));[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]intensity= [/COLOR][/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]"Intensity"[/SIZE][/SIZE][SIZE=2][SIZE=2]; [/SIZE][/SIZE][SIZE=2][SIZE=2]//labelling of x-axis
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]SetBkColor(hdc, RGB(0, 0, 0));[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(255, 255 ,255 ));[/COLOR]
    [COLOR=black]TextOut(hdc, 930, 390, LPCTSTR(intensity), 9);[/COLOR]
    [COLOR=black]pixels = [/COLOR][/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]"Pixels"[/SIZE][/SIZE][SIZE=2][SIZE=2]; [/SIZE][/SIZE][SIZE=2][SIZE=2]//labelling of y-axis
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]SetTextColor(hdc, RGB(255, 255 ,255 ));[/COLOR]
    [COLOR=black]TextOut(hdc, 580, 55, LPCTSTR(pixels), 6); [/COLOR]
    [COLOR=black]numeric = [/COLOR][/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]"0"[/SIZE][/SIZE][SIZE=2][SIZE=2]; [/SIZE][/SIZE][SIZE=2][SIZE=2]//number zero (universal)
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]SetTextColor(hdc, RGB(95, 158, 160));[/COLOR]
    [COLOR=black]TextOut(hdc, 585, 400, LPCTSTR(numeric),1);[/COLOR]
    [COLOR=black]intMFC = 0; [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//declaring constants[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]a_loop = 595;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]for[/SIZE][/SIZE][SIZE=2][SIZE=2](k=1; k<=5; k++) [/SIZE][/SIZE][SIZE=2][SIZE=2]//for every two ticks, draw legend of +52 each time it loops
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{ [/COLOR]
    [COLOR=black]intMFC = intMFC+52;[/COLOR]
    [COLOR=black]itoa(intMFC,c,10);[/COLOR]
    [COLOR=black]CString MFCString;[/COLOR]
    [COLOR=black]MFCString = c;[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2](intMFC<100) [/SIZE][/SIZE][SIZE=2][SIZE=2]//if number is XX then just show 2 digits
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]test = c;[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(95, 158 ,160));[/COLOR]
    [COLOR=black]TextOut(hdc, a_loop+(k*60), 405, LPCTSTR(test), 2);[/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]else[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2](intMFC>=100) [/SIZE][/SIZE][SIZE=2][SIZE=2]//if number is XXX then show 3 digits
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]test = c;[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(95, 158, 160));[/COLOR]
    [COLOR=black]TextOut(hdc, a_loop+(k*60), 405, LPCTSTR(test), 3);[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]intMFC1 = 0; [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//declaring of constants[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]intMFC2 = 0;[/COLOR]
    [COLOR=black]b_loop = 392;[/COLOR]
    [COLOR=black][/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2] (no_of_rows == 256 && no_of_cols == 256) [/SIZE][/SIZE][SIZE=2][SIZE=2]// initiate if image its by 256*256
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]for[/SIZE][/SIZE][SIZE=2][SIZE=2](f=1; f<=5; f++) [/SIZE][/SIZE][SIZE=2][SIZE=2]// for 5-ticks axis
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{ [/COLOR]
    [COLOR=black]intMFC1 = (((256 * 256)/5)+0.3) * f; [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]// calculate each of the 5 marking is +13107[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]itoa(intMFC1,p,10); [/COLOR]
    [COLOR=black]CString MFCString;[/COLOR]
    [COLOR=black]MFCString = p;[/COLOR]
    [COLOR=black]test1 = p;[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(95, 158 ,160));[/COLOR]
    [COLOR=black]TextOut(hdc, 540, b_loop-(f*60), LPCTSTR(test1), 5); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]// type casting[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]} [/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]else[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2] (no_of_rows == 512 && no_of_cols == 512) [/SIZE][/SIZE][SIZE=2][SIZE=2]// if image is 512*512 run this
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]for[/SIZE][/SIZE][SIZE=2][SIZE=2](q=1; q<=5; q++) [/SIZE][/SIZE][SIZE=2][SIZE=2]// for 5-ticks axis 
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{ [/COLOR]
    [COLOR=black]intMFC2 = (((512 * 512)/5)+0.8) * q; [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]// to calculate each marking is +52428[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]itoa(intMFC2,l,10); [/COLOR]
    [COLOR=black][/COLOR]
    [COLOR=black]MFCString = l; [/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2](intMFC2<100000) [/SIZE][/SIZE][SIZE=2][SIZE=2]//'if' statement used because if digit is less
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//than 100000, it shows crap at the last digit position[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]test2 = l;[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(95, 158 ,160));[/COLOR]
    [COLOR=black]TextOut(hdc, 540, b_loop-(q*60), LPCTSTR(test2), 5); [/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]else[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]if[/SIZE][/SIZE][SIZE=2][SIZE=2](intMFC2>=100000) [/SIZE][/SIZE][SIZE=2][SIZE=2]//if digit is more or equal to 100000, do this
    [/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black]{[/COLOR]
    [COLOR=black]test2 = l;[/COLOR]
    [COLOR=black]SetTextColor(hdc, RGB(95, 158, 160));[/COLOR]
    [COLOR=black]TextOut(hdc, 540, b_loop-(q*60), LPCTSTR(test2),6);[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//count pixel intensity[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black][/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//'for' loop couting from 0 to 255 which simply zeros out each element in array1 to prepare the array to do the count of the bytes in the image[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]for[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] (i=0;i<255;i++) [/COLOR]
    [COLOR=black]{[/COLOR]
    [COLOR=black]array1[i]=0;[/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]if[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] (no_of_rows == 512 && no_of_cols == 512)[/COLOR]
    [COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//'for' loop to loop through the bytes of the image[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]for[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] (i=0; i<=262144; i++)[/COLOR]
    [COLOR=black]{ [/COLOR]
    [COLOR=black]array1[image[i]]++;[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]else[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]if[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black] (no_of_rows == 256 && no_of_cols == 256)[/COLOR]
    [COLOR=black]{[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]for[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] (i=0; i<=65536; i++)[/COLOR]
    [COLOR=black]{[/COLOR]
    [COLOR=black]array1[image256[i]]++;[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black][/COLOR]
    [COLOR=black]CPen* gOldPen = pDC->SelectObject(&greenPen); [/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//green colour pen for histogram lines[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]//starting of histogram drawing (intensity vs pixel value)[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]pDC->MoveTo( 600, 398);[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]for[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black] (i=1; i<255; i++)[/COLOR]
    [/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black]if[/COLOR][/SIZE][/SIZE][SIZE=2][SIZE=2][COLOR=black](no_of_rows == 512 && no_of_cols == 512)[/COLOR]
    [COLOR=black]{[/COLOR]
    [COLOR=black]{ [/COLOR]
    [COLOR=black]pDC->MoveTo(600+i, 398);[/COLOR]
    [COLOR=black]pDC->LineTo(600+i, array1[i]/262144);[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]} [/COLOR]
    [/SIZE][/SIZE][COLOR=black][SIZE=2][SIZE=2]else[/SIZE][/SIZE][SIZE=2][SIZE=2] [/SIZE][/SIZE][SIZE=2][SIZE=2]if[/SIZE][/SIZE][/COLOR][SIZE=2][SIZE=2][COLOR=black](no_of_rows == 256 && no_of_cols == 256)[/COLOR]
    [COLOR=black]{[/COLOR]
    [COLOR=black]{[/COLOR]
    [COLOR=black]pDC->MoveTo(600+i, 398);[/COLOR]
    [COLOR=black]pDC->LineTo(600+i, [COLOR=red]array1[i][/COLOR]);[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    [COLOR=black]}[/COLOR]
    
    as before, the code in red is the one im still unsure about as my supervisor said it should be changed to something else. tried array1[] but gave me distortions. hope u can help me to find a way out of this. thanks.
    [/SIZE][/SIZE]
     
    Last edited: Oct 2, 2009
  20. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    The wording still suggests to me that you're answering the wrong question. Consider the following code:
    Code:
    int arr[3];
    arr[0]=100;
    arr[1]=200;
    arr[2]=300;
    
    What is the range of the array arr?
     

Share This Page