MATLAB: How to design a 5by5 ,5cross and X-1 median filter

filter designimage processingImage Processing ToolboxStatistics and Machine Learning Toolbox

I need to filter speckle noise from a noisy image by the application of 5*5 median filter,cross shaped median filter and a X-1 shaped median filter. I just cannot understand and do the code for it. Request for code.Thank you.

Best Answer

You can use the following two functions:
Here's an example:
out = medfilt2(im,[5 5]); %5x5 neighborhood
For a neighborhood that is not all 1's, use
nhood = [1 0 0 0 1;...
0 1 0 1 0;...
0 0 1 0 0;...
0 1 0 1 0;...
1 0 0 0 1;];
out = ordfilt2(im,ceil(nnz(nhood)/2),nhood); %cross-shaped neighborhood