# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

## Remove Salt and Pepper Noise from Images

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:

`ex_vision_remove_noise`

1. 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);```

`I`is 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.

2. To view the image this matrix represents, at the MATLAB command prompt, type

``````imshow(I) ``````

The intensity image contains noise that you want your model to eliminate.

3. Create a Simulink® model, and add the blocks shown in the following table.

Block

Library

Quantity

Image From Workspace

Computer Vision System Toolbox™ > Sources

1

Median Filter

Computer Vision System Toolbox > Filtering

1

Video Viewer

Computer Vision System Toolbox > Sinks

2

4. Use the Image From Workspace block to import the noisy image into your model. Set the Value parameter to `I`.

5. 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.

6. 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.

7. Connect the blocks as shown in the following figure.

8. 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 time = `0`

• Solver pane, Type = `Fixed-step`

• Solver pane, Solver = ```Discrete (no continuous states)```

9. Run the model.

The original and filtered images are displayed.