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?