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:
Define an intensity image in the MATLAB® workspace and add noise to it by typing the following at the MATLAB command prompt:
I= double(imread('circles.png')); I= imnoise(I,'salt & pepper',0.02);
Iis a 256-by-256 matrix of 8-bit unsigned
The model provided with this example already includes this code
executes it prior to simulation.
To view the image this matrix represents, at the MATLAB command prompt, type
The intensity image contains noise that you want your model to eliminate.
Create a Simulink® model, and add the blocks shown in the following table.
Image From Workspace
Computer Vision System Toolbox™ > Sources
Computer Vision System Toolbox > Filtering
Computer Vision System Toolbox > Sinks
Use the Image From Workspace block
to import the noisy image into your model. Set the Value parameter
Use the Median Filter block to eliminate the black and white speckles in the image. Use the default parameters.
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.
Connect the blocks as shown in the following figure.
Set the configuration parameters. Open the Configuration dialog box by selecting Model Configuration Parameters from the Simulation menu. Set the parameters as follows:
Solver pane, Stop
Solver pane, Type =
Solver pane, Solver =
(no continuous states)
Run the model.
The original and filtered images are displayed.
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.