Hello everyone, I am trying to create a program(within MATLAB) that will take a m(rows) x n(columns) matrix(example a 3x3 matrix), surround the perimeter of the matrix with zeroes, making it a 5x5 matrix. What I am trying to do is create a 2d median filter.:confused:

[1 2 3]

[4 5 6]

[7 8 9]

[0 0 0 0 0]

[0 1 2 3 0]

[0 4 5 6 0]

[0 7 8 9 0]

[0 0 0 0 0]

also take the median(kernel) of odd sizes, such as 3x3, 5x5, 7x7 and so on. for example, take the first nine for a 3x3 which will be:

[0 0 0]

[0 1 2]

[0 4 5]

placing the numbers of the matrix in order: (0,0,0,0,0,1,2,4,5), taking the median which in this case of a 3x3...the 5th number(0) will replace the center value 1. and then the 3x3 kernel will slide to the left one and take the median of:

[0 0 0]

[1 2 3]

[4 5 6] and replacing the center value 2 and slide over again and repeat the sequence until all center values of the mxn matrix are replaced.

I was told for loops would work but ive had no luck so far. any help would be greatly appreciated and please make comments in the steps so I can understand what each line does.

Thanks

-Greg