# Noise Removal using Salt and Pepper algorithm in C# by asif

Most scanned images contains noise in form of darker dots and disturbances caused by the scanning process.

If these are not removed before the feature extraction and classification, the image may mistakenly be interpreted wrong. Salt and Pepper noise removal does just what we desire; it erases the black dots, called the Pepper, and it also fills in holes in the image, called Salt.

Area is the total # of On pixels in the binary image. As we have discussed about the binary image and what the pixels and their intensity values. A pixel in the binary image has one of two values i.e., either 1 or 0 where 1 demonstrates a white pixel and 0 for the black one. Now area in an image is the total number of On pixels in the image. We browse through the whole image and calculate the total number of pixels in the image.

## C# Sample Program:

### Guidelines for Use

To illustrate Conversion of Color Image to Grayscale image, we start with a simple image containing some distinct artificial objects (specifically text)

Now we apply Grayscale conversion to the image to convert it to Grayscale image.

Now we apply Binary conversion to the image to convert it to Binary image.

## Attachments:

Project Files: NoiseAndArea.zip

The method is based on two basic binary image morphological operations: Dilations and Erosions that are based on the Minkowski addition and subtraction.

Dilations: For a binary image , and the dilation of image A by B is defined as

Erosions: For a binary image , and the erosion of image A by B is defined as , where a+b are vector addition, and ; i.e B* denotes the reflection of B across the origin and A’ denotes the complement of A.

This may be a bit tricky to understand so here is an other way to describe it:
Dilation 2:
Erosion 2:

To simplify it even more we can from the first definitions define and obtain the relations:
:equation 1
:equation 2
Where

Suppose that B contains the origin 0, then the equation 1 says that A+B is the set of all points p such that the translation of B by the vector p intersects A.
The figures below will perhaps clarify it:

Suppose that B contains the origin 0, then the equation 1 says that A+B is the set of all points p such that the translate of B by the vector p intersects A.
The figures below will perhaps clarify it:

The set A-B consists of all points p such that the translate of B by the vector p is completely contained inside A. This is illustrated like this:

With these two operations, the dilation and erosion, we can define two other operations, the open and close operation.  The open operation is an erosion followed by a dilation and as defined as follows:.  The close operation is a dilation followed by a erosion: .

Opening an image will eliminate small islands, sharp peaks and thin lines. Closing an image will fuse narrow breaks, close small holes and smooth contours.
If we then do this in the right order we will get great results. First perform an opening of A by B, this will remove all the black dots (the pepper), then perform a closing on A by B and all holes will be filled (the salt). For example, if we have a scanned image, A, that look like this:

and a structuring element B:

Then with the Salt and Pepper removing we will end up with something like this:

Area: