Problem with median filter c++

Discussion in 'C++' started by metamofia, Nov 3, 2009.

  1. metamofia

    metamofia New Member

    Joined:
    Sep 28, 2009
    Messages:
    47
    Likes Received:
    0
    Trophy Points:
    0
    Hi, i have done with implementing codes for median filter on a 8-bit bitmap image. somehow i get a distorted image, totally distorted.. so this is my code:

    Code:
     
    void CLEO_MedivisionView::OnNoiseremovalMedianfilter()
    { 
    int x, y, k, s;
    int medianarray1[9];
     
    if (no_of_rows == 512 && no_of_cols==512)
    {
    for(x=1; x<no_of_cols-1; x++)
    {
    for (y=1; y<no_of_rows-1; y++)
    {
    medianarray1[4] = image[y*no_of_cols + x];        //this is for moving the 3*3 window 
                                                                                  to the image of 2D array //
    medianarray1[0] = image[y-1*no_of_cols + x-1];
    medianarray1[1] = image[y-1*no_of_cols + x];
    medianarray1[2] = image[y-1*no_of_cols + x+1];
    medianarray1[3] = image[y*no_of_cols + x-1];
    medianarray1[5] = image[y*no_of_cols + x+1];
    medianarray1[6] = image[y+1*no_of_cols + x-1];
    medianarray1[7] = image[y+1*no_of_cols + x];
    medianarray1[8] = image[y+1*no_of_cols + x+1]; 
    
    for (k=0; k<9; k++) {
    for(s=0; s<9-1; s++){
    if(medianarray1[s]>medianarray1[s+1]){
    int temp = medianarray1[s+1];
    medianarray1[s+1] = medianarray1[s];
    medianarray1[s] = temp;
    }
    }
    }
    image[y*no_of_cols + x]= medianarray1[4];
    }
    }
    }
    Draw();
    }
    
    can someone highlight to me where i actually went wrong?
     
    Last edited: Nov 3, 2009

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice