Corrosion and expansion of images

Source: Internet
Author: User
Tags scale image

Morphology in Digital image processing

transferred from:http://blog.csdn.net/sunny3106/archive/2007/08/15/1745485.aspx

(Excerpt from a document, because the number of stickers is limited, after the formula picture is not able to, the computer re-installed documents have not been found, embarrassing)

An introduction
Mathematical morphology is a discipline based on set theory and a powerful tool for geometrical morphology analysis and description. The history of mathematical morphology can be traced back to the 19th century. 1964 Matheron and Serra of France in the research results of integral geometry, the mathematical morphology is introduced into the field of image processing, and the image processing system based on mathematical morphology is developed. The book "Image Analysis and Mathematical Morphology", published in 1982, is an important milestone in the development of mathematical morphology, suggesting that mathematical morphology tends to be complete and applied in theory. The rapid development of mathematical morphology, because of its fast parallel, easy to implement hardware, has aroused widespread concern. At present, mathematical morphology has been widely used in computer vision, signal processing and image analysis, pattern recognition, calculation method and data processing.
Mathematical morphology can be used to solve image processing problems such as noise suppression, feature extraction, edge detection, image segmentation, shape recognition, texture analysis, image restoration and reconstruction, image compression and so on. In this paper, the basic theory of mathematical morphology and its application in image processing are reviewed.

Definition and classification of two mathematical morphology
Mathematical morphology is a mathematical tool for analyzing images based on morphological and structural elements. Its basic idea is to measure and extract the corresponding shape in the image with certain structure elements to achieve the purpose of image analysis and recognition. The application of mathematical morphology can simplify the image data, maintain their basic shape characteristics, and remove irrelevant structures. There are 4 basic operations for mathematical morphology: expansion, corrosion, opening and closing. They are featured in binary images and grayscale images. Based on these basic operations, it can be deduced and combined into practical algorithms of mathematical morphology.

(1) Two-value morphology
The morphological transformation of binary images in mathematical morphology is a processing process for sets. The essence of its morphological operator is to express the interaction between the set of object or shape and the structure element, and the shape of the structure element determines the shape information of the signal extracted by this operation. Morphological image processing is to move a structure element in the image, and then the structure element and the following two value image are intersection, and so set operation.
The basic morphological operations are corrosion and swelling.
In morphology, structural elements are the most important and basic concepts. The function of structural elements in morphological transformation is equivalent to the "filter window" in signal processing. Using B (x) to represent structural elements, the definition of each point x, Corrosion and expansion in Workspace E is:

The result of corrosion of E with B (x) is to translate the structural element B into a set consisting of all the points of E. The result of the expansion of E with B (x) is that the structure element B is translated to make the intersection of B and e a non-empty point of the set. The process of first corrosion and swelling is called open operation. It has the effect of eliminating small objects, separating objects in slender places and smoothing the boundaries of larger objects.the process of first swelling and corrosion is called closed operation. It has the function of filling the small hole inside the object, connecting the neighboring object and smoothing the boundary.
It can be seen that the two-value morphological expansion and corrosion could be transformed into a set of logical operations, the algorithm is simple, suitable for parallel processing, and easy to implement hardware, suitable for two-value image segmentation, refinement, extraction skeleton, edge extraction, shape analysis. However, in different applications, the choice of structural elements and their corresponding processing algorithms are not the same, the different target images need to design different structural elements and different processing algorithms. The size and shape selection of structural elements will directly affect the results of morphological operation of the image. Therefore, many scholars combine their own application practice, put forward a series of improved algorithms. As proposed by Liang Yong, the edge detection algorithm with multi-directional morphological structure elements has good edge location capability and excellent noise smoothing ability. Sipo proposed a design method combining the structure elements of a quasi-circular structure element or a sequence structure element with the shortest line segment structural elements, used for skeleton extraction, can greatly reduce the computational amount of the morphological operation, and can meet the scale, translation and rotation compatibility, suitable for the analysis and description of the shape.

(2) Gray mathematical morphology
The binary mathematical morphology can be easily extended to the gray image space. Only the arithmetic object of the grayscale mathematical morphology is not a set, but an image function. Under f (x, y) is the input image, and B (x, y) is a structural element. The expansion and corrosion operations of the input image y with structural element B are defined as:

There are two types of effects of expansion (or corrosion) operations on grayscale images:
(1) If the value of the structure element is positive, the output image will be brighter (or darker) than the input image;
(2) Depending on the gray values of the dark (or light) details in the input image and their shape relative to the structural elements, they are either subtracted or removed from the operation. The definition of opening and closing operations in grayscale mathematical morphology is consistent with the definition of binary mathematical morphology. The opening and closing operations with B for F are defined as:

(3) Fuzzy mathematical morphology
Fuzzy morphology is formed by using fuzzy set theory in mathematical morphology. The definition of fuzzy operator is different, and the definition of fuzzy morphological operation is not the same. Here, the definition method of Shinba is chosen. Fuzziness is determined by the degree to which the structure element adapts to the original image. The corrosion and expansion operations of fuzzy images are defined by their membership functions by using bounded supported fuzzy structural elements as:

wherex,y∈Z2 represent spatial coordinates,UA,UB represent the membership function of the image and the structure element, respectively. The results from (7) and (8) indicate that the membership function after the fuzzy morphology corrosion expansion operation Falls within the [0,1] interval. Fuzzy morphology is the generalization of traditional mathematical morphology from two value logic to fuzzy logic, which has similar computational results and similar algebraic characteristics to traditional mathematical morphology. The fuzzy morphology focuses on the shape feature and morphological transformation of the object in n-dimensional space, which is mainly used in the field of image processing, such as fuzzy enhancement, fuzzy edge detection and fuzzy segmentation.

The main application of three mathematical morphology in image processing

In recent years, mathematical morphology has been widely used in image processing. The following is a brief introduction to the application of mathematical morphology in edge detection, image segmentation, image thinning and noise filtering.

(1) edge detection

Edge detection is an essential step in most image processing, providing important information about the shape of the object. For binary images, edge detection is the boundary of a set A, recorded as B (A):

For grayscale images, edge detection is the morphological gradient of an image, which is recorded as G:

The mathematical morphology operation is used for edge detection, and there is a single problem of structural elements. It is sensitive to edges in the same direction as the structural elements, while the edges (or noises) in their different directions are smoothed out, i.e. the direction of the edges can be determined by the shape of the structure element. However, if symmetric structural elements are used, the orientation sensitivity to the edges of the image is weakened. So in the edge detection, we can consider using the multi-directional morphological structure elements, using different structural elements of the logical combination to detect the different directions of the edge.

Liang Yong and other people constructs the multi-directional morphological structure element in 8 directions, applies the basic morphology operation, obtains the 8 direction edge detection result, then carries on the normalization operation, the weighted summation, obtains the final image edge. The algorithm has a good effect on maintaining the image detail feature and smoothing edge.

(2) Image segmentation

The image segmentation algorithm based on mathematical morphology transforms the complex target X into a series of non-intersecting simple subsets X1, X2,...,XN, namely:

The segmentation process of the target X can be done as follows: First, the maximum internal "circle" of X isX1, then the X1 is subtracted from X, then the maximum x-x1 "Circle" X2 is obtained,..., and so on, Until the last collection is set to be empty. The following is an example of a two-value image, which describes the process of solving subsets X1,X2, ... andxn with mathematical morphology.

Set B as a structural element,B can be a simple geometric primitive such as a circle, a triangle, a square, and a "simple" shape set XI can be defined with the following formula:

In the formula of ni as an integer, the use of the definition XI segmentation target, sometimes the segmentation process is not unique phenomenon. To do this, you can use the following formula to define the simple set Xi:

Where Li is a point or a line, when Li is a point, it is equivalent to the (12) definition. (13) A simple shape defined by Xi can be moved by an Li along the nib . The center of the "generator" nib will bemoved along the "spine"Li. If the nib is a circle, the resulting Xi is called the Blum band. It has some special properties, such as Xi's boundary is smooth,Xi's maximum circle tangent to its boundary,Xi 's spine and generator are unique and so on.

With the definition of the simple shape set XI, the target x can be split in the following way. First, the maximum inner-tangent structure element Xi of x is calculated by the formula (14):

The disadvantage of mathematical morphology for image segmentation is the sensitivity to boundary noise. In order to improve this problem, Liu Zhimin and other people put forward a mathematical morphological shape description image segmentation algorithm based on the maximum inscribed circle of the image and a mathematical morphological shape description image segmentation algorithm based on the object minimum closure structure element, and the algorithm is used to segment the two-value image, and a good result is obtained. Deng a depth image segmentation algorithm based on mathematical morphology is proposed. Firstly, the image of Convex ridge and concave valley with step edge and Ridge edge is obtained by morphological operator, then the final segmentation result is obtained by using the control region growth process. Compared with the traditional method, the method has the advantages of fast speed and good noise resistance.

(3) Morphological skeleton extraction

The morphological skeleton describes the shape and orientation of the object. It has the properties of translational invariance, inverse expansion and equal power, and is an effective shape description method. the morphological skeleton of a binary image A can be obtained by selecting the appropriate structural element B, a continuous corrosion and opening operation for a, and setting S (a) represents the skeleton of a, defined as:

Jiang Fortitude and others using mathematical morphology method, the kernel shape of traffic sign is extracted form skeleton function, which is used as shape feature for pattern matching. the morphological skeleton function of a is represented by SKF (a) as:

The larger points in SKF (x) correspond to large n, and represent the main components of the morphological skeleton, that is, the body structure of the shape, while the smaller points in SKF (x) correspond to the small N, which is the detail component of the morphological skeleton, which is associated with the shape's edge information.

The morphological skeleton function completely and concisely expresses all the information of the morphological skeleton, so it can realize the recognition of different shape objects according to the pattern matching of the morphological skeleton function. The algorithm has displacement invariance, thus making the recognition more robust.

(4) Noise filtering

Filtering the noise in the image is an indispensable operation in image preprocessing. Combining the opening and closing operations can form a morphological noise filter.

For binary images, the noise is represented by the noise block around the target and the noise hole inside the target. By using the structural element B to open the set A, the noise block around the target can be eliminated, and the noise hole inside the target can be eliminated by a closed operation with B. In this method, the selection of structural elements is very important, it should be larger than all noise holes and noise blocks.

For grayscale images, filtering noise is the morphological smoothing. In practice, the open operation is used to eliminate the light detail which is smaller than the structure element, while maintaining the overall gray value of the image and the large bright area are basically unchanged, and the closed operation is used to eliminate the smaller dark details compared with the structural elements, while preserving the overall gray value of the image and the large dark area are basically unchanged. Combining these two operations can achieve the effect of filtering out the various noises in the bright and dark areas. Similarly, the selection of structural elements is an important issue.

Four methods for selecting structural elements

The analysis shows that the application of various mathematical morphology algorithms can be decomposed into two basic problems of morphological operation and structural element selection, and the rules of morphological operation are determined by definition, so the performance of morphological algorithm depends on the choice of structural elements, that is, the structure element determines the aim and performance of the morphological algorithm. Therefore, how to optimize the structural elements adaptively has become the focus of research and technical difficulties in the field of morphology. At present, many structural elements are used to process the image.

(1) Multi-structure element operation

In many morphological applications, only one structural element is often used, which usually does not produce satisfactory results. In pattern recognition, if a particular pattern is to be extracted, only one structure element is used, only the pattern that is identical to the shape and size of the structure element can be extracted, and the pattern represented by this structure element cannot be obtained even if there are other patterns with a small difference.

One of the effective ways to solve this problem is to combine the morphological operation with the set operation, and use multiple structural elements to operate the image, and then merge the image after the operation, that is, the multi-structure element morphology operation.

(2) Selecting structural elements using genetic algorithms

The idea of genetic algorithm is derived from natural selection, survival of the fittest, the evolution of the fittest and the principle of biological evolution, and it is formed by quoting stochastic statistical theory, which has high-efficiency parallel global optimization search ability, and can effectively solve the problems of complex optimization and combinatorial optimization of machine learning parameters.

In recent years, many foreign scholars have carried on the exploration and research,Ehrgardt designed the morphological filtering genetic algorithm for binary image denoising and based on the two-value texture characteristics to eliminate the predetermined target; Huttumen uses genetic algorithm to construct the soft morphological filter and its parameter optimization design method, in order to realize the noise reduction function of the gray-scale image. Yunong, Li Jinhu and other people use genetic algorithm to detect and extract the object of natural scene, and through adaptive optimization training, the structural elements have the morphological and structural features of the image object, which gives the structure element specific knowledge, and the morphological filtering process into the unique intelligence. In order to realize the complex change of the image has good filtering performance and robust adaptability. The essence is to solve the machine learning problem of knowledge acquisition and knowledge refining in filter design.

Five problems existing in mathematical morphology and further research directions

Mathematical morphology is a discipline based on set theory and a powerful tool for analyzing and describing geometric shapes. In recent years, mathematical morphology has been widely used in the fields of digital image processing, computer vision and pattern recognition, and has gradually formed a new method and theory of digital image analysis, which has aroused wide attention of researchers in relevant fields at home and abroad. At present, the problems and research direction of mathematical morphology mainly focus on the following aspects:

(1) Morphological operation is essentially a two-dimensional convolution operation, when the image dimension is large, especially with gray morphology, soft mathematical morphology, fuzzy morphology and other methods, the operation speed is very slow, and therefore not suitable for real-time processing.

(2) because the structural elements play a decisive role in the results of morphological operations, it is necessary to select the size and shape of the structural elements in the light of the actual application background and expectation.

(3) The definition of the core and soft boundary of structural elements in soft mathematical morphology, and the choice of weighted statistics * are also of great flexibility, which should be chosen rationally according to the topological structure of images, there is no uniform design standard.

(4) In order to achieve the best filtering effect, we need to combine the topological characteristics of the image to select the complex mode of open and closed operation.

(5) For fuzzy morphology, different fuzzy operators will directly affect the definition of fuzzy morphology and its operation results.

(6) The processing and analysis methods of gray image and color image are studied by combining mathematical morphology with neural network and fuzzy mathematics.

(7) To further study the development of the optical implementation of morphological operations and other hardware implementation methods.

(8) It is needed to improve the existing image processing methods by combining morphology with wavelet, fractal and so on. So how to realize the fast algorithm of gray morphology, soft mathematical morphology, fuzzy soft mathematical morphology, how to improve the universality of morphological operation, enhance the adaptability of morphological operation, combine the latest application progress of mathematical morphology, apply it to the field of image processing, enrich and develop the method of image processing and analysis using mathematical morphology, Become the future development direction of mathematical morphology.

Six Conclusion

The mathematical morphology has the advantages of intuitive simplicity and mathematical rigor in the image processing, and it provides a powerful means for image processing based on shape detail in quantitative description of image morphology. Based on the set theory of mathematical morphology, mainly through the selection of the corresponding structural elements of expansion, corrosion, open, closed #种基本运算的组合来处理图像. Mathematical morphology is widely used in image processing, there are many practical algorithms, but the selection of structural elements in each algorithm is an important problem.

Algorithm Ideas:The algorithm of corrosion:
Using a 3x3 structure element, scan each pixel of the image, and use the structure element with its covered two value image for "and" operations: if all are 1, the pixel of the resulting image is 1. Otherwise, it is 0. Result: The two value image is reduced by one lap definition: E = B? S = {x, y | Sxy? B} expansion algorithm: With a 3x3 structure element, scan each pixel of the image, with the structure element and its covered two value image to do "and" Operation: If all is 0, the result image of the pixel is 0. Otherwise 1 result: enlarge the two value image by one lap definition: E = B? S = {x, y | Sxy∩b≠ф}
Codes: VC + + codeTransferred from: http://blog.csdn.net/vincentzhao2009/archive/2009/10/24/4723469.aspx

Corrosion:

The structure element S is shifted x after the SX , if SX is included in x , we note this x Point, all meet the above conditions x The set of points is called the result of X being corroded by S (erosion). expressed in formulas as:

The method of corrosion is to compare the origin of s with the point on X one by one, if all the points on s are within the range of x , then the point of the origin of S is retained, Otherwise, the point is removed. The following is a detailed code, with a test image attached:

#include
#include
#include
#include
#include

unsigned char **get_matrix_space (int m,int N)
{
int i;
unsigned char **a;
a= (unsigned char * *) calloc (m,sizeof (unsigned char *));
for (I=0;ireturn A;
}

Main () {
FILE *FS,*FD;
unsigned char c1,c2,**ps,**pd,**get_matrix_space (int,int);
int width,height,l,i,j,l,m,match;
if ((fs= fopen ("SOURCEA.PGM", "RB")) ==null) {
printf ("Can ' t open%s\n", "SOURCE.PGM");
Exit (1);
}
if (fd = fopen ("DESTINATION.PGM", "WB")) ==null) {
printf ("Can ' t open%s\n", "DESTINATION.PGM");
Exit (1);
}

FSCANF (FS, "%c%c\n%d%d\n%d\n", &c1,&c2,&width,&height,&l);
Ps=get_matrix_space (Height,width);
Pd=get_matrix_space (Height,width);

For (I=0;i j=0;j fread (&ps[i][j],sizeof (unsigned char), 1,FS);
PD[I][J] = 0;
}
}

///////////////////////
Match = 1;
For (the I=0;i for (J=0;j for (m=i;m for (l=j;l if (ps[m][l]!=255) {
Match = 0;
}
}
}
if (match! = 0) {
pd[i][j]=255;
}
Match = 1;
}
}
//////////////////////
fprintf (FD, "%c%c\n%d%d\n%d\n", ' P ', ' 5 ', width,height,l);
For (I=0;i j=0;j fwrite (&pd[i][j],sizeof (unsigned char), 1,FD);
}
}
}

Expansion:

The structure element S is shifted by x to get sx , if sx and x intersect is not NULL, we note this x Point, all meet the above conditions x The set of points is called the result of X being expanded by S ((dilation)). expressed in formulas as:

The expansion method is to compare the origin of s with the point on x one by one, and if there is a point on s that falls within the range of x , then the point corresponding to the origin of S is the image. The following is a detailed code, with a test image attached:

#include
#include
#include
#include
#include

unsigned char **get_matrix_space (int m,int N)
{
int i;
unsigned char **a;

a= (unsigned char * *) calloc (m,sizeof (unsigned char *));
for (I=0;ireturn A;
}

Main () {
FILE *FS,*FD;
unsigned char c1,c2,**ps,**pd,**v,**get_matrix_space (int,int);
int width,height,l,i,j,l,m,windowsize,match;
if ((fs= fopen ("SOURCE.PGM", "RB")) ==null) {
printf ("Can ' t open%s\n", "SOURCE.PGM");
Exit (1);
}
if (fd = fopen ("DESTINATION.PGM", "WB")) ==null) {
printf ("Can ' t open%s\n", "DESTINATION.PGM");
Exit (1);
}

FSCANF (FS, "%c%c\n%d%d\n%d\n", &c1,&c2,&width,&height,&l);
Ps=get_matrix_space (Height,width);
Pd=get_matrix_space (Height,width);

For (I=0;i j=0;j fread (&ps[i][j],sizeof (unsigned char), 1,FS);
}
}
Match = 0;
//////////////////////
Use 2x2 squares as an expansive structural element.
For (the I=0;i for (J=0;j for (l=i;l for (m=j;m if (ps[l][m]==255) {
Match = 1;
}
}
}
if (match = = 1) {
PD[I][J] = 255;
Match = 0;
}
}
}
//////////////////////
fprintf (FD, "%c%c\n%d%d\n%d\n", ' P ', ' 5 ', width,height,l);
For (I=0;i j=0;j fwrite (&pd[i][j],sizeof (unsigned char), 1,FD);
}
}
}

MatlabORIGINALBW =imread (' f.jpg '); Se=strel (' line ', 20,0); Bw=imdilate (ORIGINALBW,SE); Imshow (BW) imwrite (BW, 'Corrosion ExpansionAfter the image. jpg ')
In general, the processing image will be converted to integer or logical re-processing.
S2=logical (ORIGINALBW)% This is a logical type (binary image), you can also use Uint8 to convert to 8-bit nonnegative integer (grayscale or color image) S3=imdilate (s2,s2, ' full ')

Corrosion and expansion of images

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.