Median filtering is a common image enhancement technique for removing salt and pepper noise. Because this filtering is less sensitive than linear techniques to extreme changes in pixel values, it can remove salt and pepper noise without significantly reducing the sharpness of an image. In this topic, you use the Median Filter block to remove salt and pepper noise from an intensity image:
I= double(imread('circles.png')); I= imnoise(I,'salt & pepper',0.02);
Iis a 256-by-256 matrix of 8-bit unsigned integer values.
The model provided with this example already includes this code in file>Model Properties>Model Properties>InitFcn, and executes it prior to simulation.
The intensity image contains noise that you want your model to eliminate.
Image From Workspace
Computer Vision System Toolbox™ > Sources
Computer Vision System Toolbox > Filtering
Computer Vision System Toolbox > Sinks
The Median Filter block replaces the central value of the 3-by-3 neighborhood with the median value of the neighborhood. This process removes the noise in the image.
Use the Video Viewer blocks to display the original noisy image, and the modified image. Images are represented by 8-bit unsigned integers. Therefore, a value of 0 corresponds to black and a value of 255 corresponds to white. Accept the default parameters.
Solver pane, Stop time = 0
Solver pane, Type = Fixed-step
Solver pane, Solver = Discrete (no continuous states)
The original noisy image appears in the Video Viewer window. To view the image at its true size, right-click the window and select Set Display To True Size.
The cleaner image appears in the Video Viewer1 window. The following image is shown at its true size.
You have used the Median Filter block to remove noise from your image. For more information about this block, see the Median Filter block reference page in the Computer Vision System Toolbox Reference.