Erosion Operation On Binary and Graylevel Images in C#

Overview
Erosion is one of the two basic operators in the area of mathematical morphology. The basic effect of the operator on a binary image is to erode away the boundaries of regions of foreground pixels (i.e. white pixels, typically). Thus areas of foreground pixels shrink in size, and holes within those areas become larger.
General Working
The erosion operator takes two pieces of data as inputs. The first is the image which is to be erosion. The second is a set of coordinate points known as a Structuring Element. It is this structuring element that determines the precise effect of the erosion on the input image. The mathematical definition of grayscale erosion is identical except for the way in which the set of coordinates associated with the input image is derived. In addition, these coordinates are 3-D rather than 2-D. The brief procedure for implementing the erosion in the binary image, and in the graylevel image are explained below.
The erosion is applied on the binary image in a single pass. During the pass, if the pixel in hand is equal to binary 0, then apply the structuring element on the image by starting from that particular pixel as the origin.
The sample project supposes that, in the threshold image, the background is white and the foreground is black. If the sample image is not so, then you have to adjust accordingly.
The erosion can also be applied on the graylevel images also in a single pass. During the passing through the image, the structuring element is applied on each pixel of the image, such that the origin of the structuring element is applied on that particular pixel. In this case the corresponding pixel of the output image contains the minimum of the pixels surrounding it. In this case, only those pixels are compared with each other, where the structuring element contains.
Explanation
Let us take the example of the following image:
and the following Structuring Element:
0 1 0
1 1 1
0 1 0
The following image shows the effect of it on the above image:
In the above images, the boxes shows the pixels, and the white colored boxes shows that the binary pixel contains 1, while the black box shows that the corresponding pixel contains 0. It can be seen that only the pixels in the only input image that were surrounded by the white pixels are left, other have vanished. This erosion effect can be seen in the example below. Erosion can be made directional by using less symmetrical structuring elements. e.g. a structuring element that is 10 pixels wide and 1 pixel high will erode in a horizontal direction only. Similarly, a 3×3 square structuring element with the origin in the middle of the top row rather than the center, will erosion the bottom of a region more strongly than the top.
Let us take the example of the following image sample ( note that each pixel is represented by a box, whereas the pixel intensity is shown in the box as a number) :
and the following be the structuring element:
0 1 0
1 1 1
0 1 0
now, the dilated image pixel setup is as:
In order to understand the working, take the example of the pixel in the 3rd row, and in the 4th column. Its intensity is 56. Now, the pixel in the images are compared in the image where the structuring element has one. The intensity values of those pixels are 198 , 32 , 56 , 16 , 78. The minimum of these is 16 intensity value, thus it is the intensity value of the pixel in the 3rd row, and in the 4th column of the output image.
Guidelines for Use
One of the simplest applications of erosion is for bridging gaps in the binary mode. For example, take the following fig:
The following image shows that the two pixel gaps on maximum are bridged:
In the graylevel mode tBright regions surrounded by dark regions shrink in size, and dark regions surrounded by bright regions grow in size. Small bright spots in images will disappear as they are eroded away down to the surrounding intensity value, and small dark spots will become larger spots. The effect is most marked at places in the image where the intensity changes rapidly, and regions of fairly uniform intensity will be left more or less unchanged except at their edges:
The following picture shows the effect of two erosion passes on the image:
Sample Project
The algorithm is coded in C# using unsafe so the quality and speed of the program may not be affected. The class BitmapData is used to read and process the pixels in the image. This is the speicality of C# to provide such a speed even on image processing applications. There is a set of modules that are designed to implement the algorithm. The interface designed for the sample project as:
You can perform the erosion operation on binary as well as on graylevel images using the same project, specifying the type of the image in the dialog box. You also use specify desired masks in the "Specify Mask" section.
 
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Basic Image Processing in Csharp

The C# provides a good support for processing on the image, and the purpose of this article...

Implementation Of Branch And Bound Algorithm

What is Branch and Bound Algorithm? These notes follow the discussion of branch and...

Implementation of Calculating the RTS Invariant Moments Of Area

Why Using Moments of Area? It is seen that the usage of moments of area highly...

Conversion of a Color Image to a Grayscale Image

What is a Color Image? It is possible to construct (almost) all visible colors by...

GrayLevel Image Contras Stretching in C#

Overview Contrast stretching (often called normalization) is a simple image...