-3

I want to apply Median Filtering on a black & white 256x256 image with window size 3, 5 and 7... I can't find a sort algorithm with which I can work with. Can you help me and give me some ideas?

Shiplu Mokaddim
  • 52,462
  • 12
  • 127
  • 180

2 Answers2

0

You can use the selection algorithm to find median without sorting: http://en.wikipedia.org/wiki/Selection_algorithm

But any sort can work. Just sort and take the number in the middle.

Vlad Krasnov
  • 977
  • 6
  • 12
0

I made a sorting code:

int m = 1

for ( i = 0; i = 2; i++)

for ( j = 0, j = 2, j++)

x[m] <- outputImage[i,j];

m = m + 1;

}

}

for ( i = 1; i = 9; i++)

for ( j = 9; j = i; j-- )

    if x[m] < x [m - 1]

        x[m] = x[m - 1]

}

}

}

m = 1 for ( i = 0; i = 2; i++)

for ( j = 0, j = 2, j++)

outputImage[i,j] = x[m];

m = m + 1;

}

}

Ok after the sorting I take the number in the middle... My issue now is that I don't know how I will apply this to my code as the for loops of the code are like this, I want to use median filtering in 3x3 window size (I have putted salt n pepper noise):

for (i = 0; i < ROWS; i++)

{
    for (j = 0; j < COLUMNS; j++)

    {   

            outputImage[i][j] = inputImage[i][j];

    }

}
    for( p = 0; p <500; p++)

    {
        outputImage[rand() % 256 ] [rand() % 256] = 0;

        }