Graduation project of image shape and classification based on matlab (including source text)

Image shape and classification based on matlab



Summary


Digital image processing is an emerging technology. With the development of computer hardware, real-time processing of digital images has become possible. Due to the emergence of various algorithms for digital image processing, its processing speed is getting faster and faster, and it can better serve People serve. Digital image processing is a technology that uses certain algorithms to process graphics and images by computer. Digital image processing technology has been widely used in various fields. The amount of information in image processing is large, and the requirements for processing speed are relatively high. MATLAB's powerful computing and graphic display functions make image processing easier and more intuitive. This paper introduces the characteristics of MATLAB language, based on the digital image processing environment of MATLAB, and introduces how to use MATLAB and its image processing toolbox for edge extraction and recognition classification of digital image shapes. The thesis mainly discusses the use of MATLAB to realize the edge extraction and automatic recognition and classification of triangles, squares, circles, ellipses, and rhombuses in images.


Keywords: MATLAB; digital image processing; image shape; image classification



Table of contents



1 Introduction 1

href=" zhuanlan.zhihu.com/write#__RefHeading___Toc327370568">1.1 The purpose and significance of the subject research 1

href=" zhuanlan.zhihu.com/write#__RefHeading___Toc327370569">1.2 Research status at home and abroad 1

href=" zhuanlan.zhihu.com/write#__RefHeading___Toc327370570">1.3 Research work and structure arrangement of this subject 2

2 Digital image shape and preprocessing 3

href="zhuanlan.zhihu.com/writ">2.1 Overview 3

href=" zhuanlan.zhihu.com/write#__RefHeading___Toc327370573">2.2 Preprocessing of digital images 4

ef=" zhuanlan.zhihu.com/write ">2.2.1 Digital Image 4

ef=" zhuanlan.zhihu.com/write ">2.2.2 Sampling 6

ef=" zhuanlan.zhihu.com/write ">2.2.3 Quantization 7

ef=" zhuanlan.zhihu.com/write ">2.2.4 The relationship between sampling, quantization and image details 7

href=" zhuanlan.zhihu.com/write#__RefHeading___Toc327370578">2.3 Several typical shape feature description methods 8

3 Shape features and extraction classification 9

href=" zhuanlan.zhihu.com/write#__RefHeading___Toc327370580">3.1 Rectangularity 10

href=" zhuanlan.zhihu.com/write#__RefHeading___Toc327370581">3.2 Circularity 10

href=" zhuanlan.zhihu.com/write#__RefHeading___Toc327370582">3.3 Moment 11

href=" zhuanlan.zhihu.com/write#__RefHeading___Toc327370583">3.4 Invariant moment 11

href=" zhuanlan.zhihu.com/write#__RefHeading___Toc327370584">3.5 Shape feature extraction based on invariant moments 12

ef=" zhuanlan.zhihu.com/write ">3.5.1 Feature extraction step 12

ef=" zhuanlan.zhihu.com/write ">3.5.2 Determination of edge extraction operator 12

ef=" zhuanlan.zhihu.com/write ">3.5.3 Commonly used operators for edge extraction 12

ef=" zhuanlan.zhihu.com/write ">3.5.4 Canny operator 13

href=" zhuanlan.zhihu.com/write#__RefHeading___Toc327370589">3.6 Experimental results and analysis of edge extraction 15

ef=" zhuanlan.zhihu.com/write ">3.6.1 Edge extraction algorithm analysis 15

ef=" zhuanlan.zhihu.com/write ">3.6.2 Image shape recognition results 15

Conclusion 25

Reference 26

Thanks 27

Appendix: 28


1 Introduction

This chapter briefly introduces the research purpose and significance of the topic, the current research status of the topic at home and abroad, and the arrangement of the paper content.

1.1 Purpose and significance of the subject research

With the advent of the information-based multimedia era and the popularity of the Internet worldwide, people are increasingly exposed to a large amount of various image information in their work and life. As an important information carrier, image has the characteristics of intuition, rich content, no language restrictions, and easy international communication. It is an important content of multimedia information. Image processing technology has been widely and deeply used in various industries. Various image databases have been successively established in the fields of design and manufacturing, medical and health care, art and culture, construction engineering, geography, and public security.

In the vast amount of information, it is extremely time-consuming to find interesting information, and people rely more and more on information retrieval and systems. Image feature extraction is the core content of content-based image retrieval system.

The focus of this paper is how to extract the shape features of the image from the static image.

A typical framework is: manually labeling and classifying the shape of the image. This method is a simple and easy method when the number of images is not large. However, when the amount of image data is very large, there are many difficulties in image retrieval based on text, at this time the automatic recognition of image shape comes in handy.

1.2 Research status at home and abroad

Because of the strong practicability of image feature extraction and recognition, it has been deeply studied in the fields of surveying and mapping, computer vision, pattern recognition and artificial intelligence at home and abroad. Abroad, such as the Mckeown laboratory in the United States, the VGG laboratory in the United Kingdom, the University of Bonn in Germany, the University of Graz in Austria, etc., and domestically such as Tsinghua University, Peking University, and the Chinese Academy of Sciences have done a lot of work in this area and achieved great results. Some of the achievements have already had preliminary practical value. On the basis of the above research, a series of graphics and image software have been launched at home and abroad in recent years, which have strong functions of image feature extraction and recognition. Popular foreign image feature extraction and recognition software, such as: VPStudio from Softelec in Germany, Imageseries from Hitachi in Japan, GTXRaster series from GTX in the United States, RxAutoImage Pro 2000 from Rasterex in Norway, etc. Domestic image feature extraction and recognition software, such as: SEAS system of Dongda Alpine, EDIS engineering drawing information system of Huazhong University of Science and Technology, NPPU-EDRS engineering drawing intelligent input and recognition system of NPU CAD Center, Tsinghua Unisplendour TH-DAIMS drawing processing system, etc.

From the above research status of feature extraction and recognition, due to the diversity and complexity of feature extraction and recognition problems, the existing theories and methods are still far from the actual requirements, and some fundamental problems still need further research. The existing feature extraction and recognition algorithms are basically still in the experimental stage, and their practicability, versatility, and accuracy are still far from the requirements of large-scale practical applications. All these applications are inseparable from the nature of the problem, so far no unified and effective theory applicable to all pattern recognition has been developed. Although each feature extraction and recognition algorithm has its own advantages in terms of processing ability, feature extraction ability, and feature recognition ability, there are still many shortcomings in the performance, versatility, degree of automation, and accuracy of the algorithm. Therefore, in order to make up for these shortcomings, the research on image feature extraction and recognition technology needs more attention and more efforts.

1.3 Research work and structure arrangement of this subject

This paper mainly uses MATLAB as a tool to realize the research and classification of digital image shape. The full text is divided into 3 chapters, and the structure is arranged as follows:

The first chapter is the introduction, which introduces the purpose and significance of the subject research and the research status at home and abroad.

The second chapter introduces the basic steps of digital image preprocessing.

The third chapter introduces the basic characteristics of image shape and its classification and recognition.

2 Digital image shape and preprocessing

2.1 Overview

Shape features are the best representation for objects with sharp boundaries in images. It is a salient feature of image objects, and in practice, shape features or main boundaries are usually used to retrieve and classify images. Image classification (recognition) belongs to the category of pattern recognition. Its main content is to perform image segmentation and feature extraction after some preprocessing (enhancement, restoration, compression) of the image, so as to perform judgment and classification. Image classification often adopts classic pattern recognition methods, including statistical pattern classification and syntactic (structural) pattern classification. In recent years, newly developed fuzzy pattern recognition and artificial neural network pattern classification have also received more and more attention in image recognition.

The human visual system's initial recognition of the scene is the shape of the object, and it can recognize many objects from two-dimensional images. Shape is an important parameter in human visual perception, recognition and understanding. Shape is one of the essential characteristics of describing objects, and it is also an important characteristic of describing image content. Describing the shape of an image is a very complex problem. In two dimensions, the shape can be defined as a function of the position and direction of a simple connecting curve in a two-dimensional range. The description of a shape thus involves the description of a closed curve, or of the area enclosed by a contour. The edges of image objects are called contours. Contour is the most basic concept in shape perception, and it is closely related to shape. People must first see the outline before perceiving a shape. When we see the shape of an object, we see an outline that distinguishes the object from the rest of the field of view. Intuitively, shape perception requires a sharp outline between visible regions of varying brightness. In mathematical language, the composition of the contour is the second derivative of the contour corresponding to the brightness, and only the linear change of the brightness does not produce the contour. When people pay attention to the shape of an object, they tend to look at certain areas fixedly; while when people pay attention to the outline, they regard the outline as a route to be traced, so there is a process of "shape formation" from the outline to the perception of shape . It can be said that the outline is only the boundary and is a local concept, while the shape is the whole and is a general concept.

Matlab is a very useful image processing software. Matlab is a powerful and easy-to-operate language developed by American MathWorks Corporation, which integrates the three basic functions of numerical calculation, symbolic calculation and graphic visualization. It is one of the internationally recognized excellent mathematics application software.

The basic data unit of Matlab is a matrix, and its instruction expressions are very similar to those commonly used in mathematics and engineering, so using Matlab to solve problems is much simpler than using C, FORTRAN and other languages ​​to complete the same thing.

Matlab includes a main package with hundreds of internal functions and more than 30 kinds of tool packages (Toolbox). Toolkits can be divided into functional toolkits and subject toolkits. The function toolkit is used to expand Matlab's symbolic calculation, visual modeling and simulation, word processing and real-time control functions. Subject toolkits are more specialized toolkits, such as control toolkits, signal processing toolkits, and communication toolkits.

Openness makes Matlab popular with users. Except for internal functions, all Matlab main package files and various toolkits are readable and modifiable files. Users can construct new special toolkits by modifying source programs or adding their own programs.

This article is to use Matlab to find out the features from the local "contour" to judge the overall "shape".

2.2 Preprocessing of digital images

2.2.1 Digital image

The so-called digital image is to divide the picture of the traditional image into small discrete points called picture element (pixel for short. Sometimes the abbreviation pel is also used) as shown in Figure 2-1. The grayscale of each pixel Values ​​are also represented as discrete or integer values. There is a difference between a digital image (digital imagine) and a traditional image, that is, an analog image (picture).


v2-55c82baee08e1da730057d1b30e11018_b.jpg


Figure 2-1 Digital image

Common digital image formats are as follows:

(1) PCX (Windows Paintbrush) format. Can handle image data such as 1, 4, 8, 16, 24 bits. The file content includes: file header (128 bytes), image data, and extended color mapping table data.

(2) BMP (Windows Bitmap) format. There are 1, 4, 8, 24-bit uncompressed images, and 8-bit RLE (Run-length Encoded) images. The file content includes: file header (a BITMAP FILEHEADER data structure), bitmap information data block (bitmap information header BITMAP INFOHEADER and a color table) and image data.

(3) HDF (Hierarchical Data Format) format. There are 8-bit, 24-bit raster datasets.

(4) JPEG (Joint Photographic Experts Group) format is an image compression format known as the Joint Photographic Experts Group.

(5) TIFF (Tagged Image File Format) format. Handle 1, 4, 8, 24-bit uncompressed images, 1, 4, 8, 24-bit packbit compressed images, 1-bit CCITT compressed images, etc. The content of the file includes four parts: file header, parameter pointer table and parameter field, parameter data table and image data.

(6) XWD (X Windows Dump) format. 1, 8-bit Zpixmaps, Xybitmaps, 1-bit Xypixmaps.

(7) PNG (Portable Network Graphics) format.

In order to obtain digital images from analog images such as general photos and scenery, it is necessary to perform sampling and quantization operations on traditional analog images (the two are collectively referred to as digitization). Digital Image Processing (Digital Image Processing) is a method and technology for image removal, enhancement, restoration, segmentation, and feature extraction through computers. The emergence and rapid development of digital image processing are mainly affected by three factors: one is the development of computers; the other is the development of mathematics (especially the creation and improvement of discrete mathematics theory); , military, industrial and medical applications demand growth.

The Matlab program is used to process digital images, which is very useful in digital images.

The image processing toolkit consists of a series of functions that support image processing operations. Supported image processing operations include: image geometric operations, neighborhood and area operations, image transformation, image restoration and enhancement, linear filtering and filter design, transformation (DCT transformation, etc.), image analysis and statistics, binary image operations wait. The application of Matlab in various aspects of image processing is introduced separately below.

(1) Read, write and display image file formats. Matlab provides the image file reading function imread(), which is used to read image files in formats such as bmp, tif, tiffpcx, jpg, gpeg, hdf, xwd, etc.; the image writing function imwrite(), and the image display function image (), imshow(), and so on.

(2) Basic operations of image processing. Matlab provides linear operations such as sum and difference of images, as well as nonlinear operations such as convolution, correlation, and filtering. For example, conv2(I, J) implements the convolution of two images I and J.

(3) Image transformation. Matlab provides one-dimensional and two-dimensional discrete Fourier transform (DFT), fast Fourier transform (FFT), discrete cosine transform (DCT) and its inverse transform functions, as well as continuous wavelet transform (CWT), discrete wavelet transform (DWT) and their inverse transform.

(4) Image analysis and enhancement. For the statistical calculation of images, Matlab provides image processing such as correction, histogram equalization, median filtering, contrast adjustment, and adaptive filtering.

(5) Mathematical morphology processing of images. For binary images, Matlab provides mathematical morphology operation functions; erosion (Erode), expansion (Dilate) operators, and based on this, open (Open), close (Close) operators, thicken (Thicken), Thin operator and other rich mathematical morphology operations.

The application of Matlab in the image mentioned above is realized by the corresponding Matlab function. When using it, you only need to input the parameters correctly according to the calling syntax of the function. For specific usage, please refer to the rich help documentation of Matlab. Image edges are very useful for image recognition and computer analysis. In Matlab, the function edge() is used to extract the edges of grayscale images. It supports six different edge extraction methods, namely Sobel method, Prewitt method, Robert method, Laplacian2Gaussian method , zero-crossing method and Canny method.

The basic image types are divided into the following categories:

(1) Index image

The indexed image includes an image matrix and an array of colormaps, where the colormap is an array sorted by color values ​​in the image. For each pixel, the image matrix contains a value, which is an index into the colormap. The colormap is an m*3 matrix of double-precision values, and each row specifies a single-color value of red, green, and blue (RGB). Colormap=[R, G, B], R, G, B are real values ​​with a range of [0, 1].

The relationship between the image matrix and the colormap depends on whether the image matrix is ​​of type double or uint8 (unsigned 8-bit integer). If the image matrix is ​​of type double, the value of the first point corresponds to the first row of the colormap, the second point corresponds to the second row of the colormap, and so on. If the image matrix is ​​uint8, there is an offset, the 0th point value corresponds to the first row of the color map, the first point corresponds to the second row, and so on; uint8 is long used for graphics file formats, which support 256 colors.

(2) Grayscale image

In MATLAB, grayscale images are stored in a matrix, and each element in the matrix represents a pixel. The matrix can be of double precision type, and its value range is [0, 1]; it can also be of uint8 type, and its data range is [0, 255]. Each element of the matrix represents a different brightness or gray level.

(3) Binary image

In a binary image, each point is one of two discrete values ​​representing on or off. The binary image is stored in a two-dimensional matrix of 0s (off) and 1s (on). From another perspective, a binary image can be viewed as a grayscale image that includes only black and white, or as an indexed image with only two colors.

Binary images can be saved as double precision or uint8 type double precision arrays, obviously using uint8 type is more space-saving. In Image Processing Toolbox, any function that returns a binary image returns a logical array of type uint8.

(4) RGB image

Like indexed images, RGB images use red, green, and blue brightness values ​​as a group to represent the color of each pixel. Unlike indexed images, these brightness values ​​are stored directly in the image array rather than in a colormap. The image array is M*N*3, M, and N represent the number of rows and columns of image pixels.

2.2.2 Sampling

Sampling is an operation that converts temporally and spatially continuous images into a collection of discrete points (sampling points, or pixels).

The image is basically a form of information continuously distributed on a two-dimensional plane. To input it into a computer, the two-dimensional signal must first be converted into a one-dimensional signal, so scanning is required. The most commonly used scanning method is to sequentially scan along a straight line (scanning line) in the horizontal direction from above at a certain interval on a two-dimensional plane, so as to take out the line scan (Laster scan) of the shade value (gray value). For the resulting one-dimensional signal, discrete signals can be obtained by calculating the value of each specific interval. For moving images, in addition to horizontal and vertical scanning, there is also scanning on the time axis.

Through sampling, if the number of pixels in the horizontal direction is M and the number of pixels in the vertical direction is N, then the size of the screen can be expressed as "M*N" pixels.

2.2.3 Quantization

After sampling, the image is decomposed into pixels that are discretely distributed in time and space, but the value of the pixel (gray value) is still a continuous value. The value of a pixel refers to the shade value of white-gray-black, and sometimes also refers to the intensity (brightness) value or grayscale value of light. The operation of converting these continuous shades or gray values ​​into discrete values ​​(integer values) is quantization.

If these continuously changing values ​​(gray values) are quantized to 8bit, the gray values ​​are divided into 256 levels from 0 to 255, corresponding to the shades of each gray value, called gray levels or gray scales .

When the value of 0-255 corresponds to white-black, there is a method of using 0 as white and 255 as black, and there is also a method of using 0 as black and 255 as white, depending on the input method of the image and what kind of image is used Views process images, etc. This is a problem that should be paid special attention to when programming. However, in the case of a binary image with only black and white binary values, generally set 0 to be white and 1 to be black.

Quantization levels are assigned to continuous gray values, that is, gray value methods include: uniform quantization, linear quantization, log quantization, MAX quantization, tapered quantization, etc.

2.2.4 The relationship between sampling, quantization and image details

In the digitization process above, it is necessary to determine the value N and the number K of the gray scale. In digital image processing, it is generally taken as an integer power of 2, namely:


v2-f10962025354097b8aa6c6960a525838_b.jpg

(2-1)


v2-71e2bdf3d60235dd2533a60d2846f69b_b.jpg

(2-2)

The binary storage bit b occupied by a digital image in the computer is



v2-b0ea2ef9993720a9f98a79da7cccf803_b.jpg

(2-3)


For example, a 512×512 digital image with 256 gray levels (m=8) requires about 2.1 million storage bits. With the increase of N and m, the storage required by the computer also increases rapidly.

Since the digital image is an approximation of the continuous image, it can be seen from the process of image digitization. The degree of this approximation mainly depends on the size and number of sampling samples (N value) and the quantization level K (or m value). The larger the value of N and K, the clearer the image.

2.3 Several typical shape feature description methods

There are many methods and techniques for shape analysis and classification. Generally speaking, shape feature representation methods can be divided into two categories: boundary-based and region-based. The former uses the outer bounds of the shape, while the latter uses the entire area. The most typical methods for these two types of shape features are Fourier descriptors, deformable template matching, and shape invariant moments, respectively. In addition, contour matching methods include geometric parameter method, boundary direction histogram method, wavelet important coefficient method and wavelet contour representation method, etc.

Several typical shape feature description methods:

(1) Boundary feature method

This method obtains the shape parameters of the image through the description of the boundary features. Among them, the method of Hough transform to detect parallel lines and the method of boundary direction histogram are classic methods. Hough transform is a method of connecting edge pixels to form a closed boundary of a region by using the global characteristics of the image. Regarding the histogram of edge size and direction, the usual method is to construct an image gray gradient direction matrix.

(2) Fourier shape descriptor method

The basic idea of ​​Fourier shape descriptors is to use the Fourier transform of the object boundary as the shape description, and use the closure and periodicity of the region boundary to transform the two-dimensional problem into a one-dimensional problem. Three shape expressions are derived from the boundary points, which are curvature function, centroid distance, and complex coordinate function.

(3) Geometric parameter method

The expression and matching of shapes adopt simpler regional feature description methods, such as the shape factor method of quantitative measures of shape (such as moments, areas, perimeters, etc.). In the QBIC system, geometric parameters such as roundness, eccentricity, main axis direction and algebraic invariant moments are used to perform image retrieval based on shape features.

It should be noted that the extraction of shape parameters must be based on image processing and image segmentation, and the accuracy of the parameters is bound to be affected by the segmentation effect. For images with poor segmentation effects, the shape parameters cannot even be extracted.

(4) Shape invariant moment method

The moment of the area occupied by the object is used as the shape description parameter for classification.

(5) Other methods

In recent years, the work on shape representation and matching also includes methods such as finite element method (Finite Element Method or FEM), rotation function (Turning Function) and wavelet descriptor (Wavelet Descriptor).

3 Shape features and extraction classification

This article mainly uses the geometric parameter method to judge the shape of the given image.

For image classification problems, the quality of feature extraction is the key factor to determine the classification performance. Before extracting the shape features of the object, the image must first be edge extracted to obtain the contour boundary of the object, and then the features of the contour boundary area need to be extracted. Among these features, some of them can be described by numerical values, but more features are geometric figures without obvious features. In order to facilitate image matching, further description of these geometric figures is required. The nature of the object in the image cannot be changed due to the translation, rotation, and change of the scale of the image. Therefore, when describing the shape, the selected descriptor should have the characteristics of translation invariance, rotation invariance, and scale invariance. Not only that, but the selected descriptor should also be able to describe the essential characteristics of the shape, so that the descriptor has good distinguishability.

The principle of image feature selection Feature extraction is to process and analyze the input information contained in the pattern, and extract the information that is not easily disturbed by random factors as the feature of the pattern. The feature extraction process is the process of removing redundant information, which can improve the recognition accuracy, reduce the amount of calculation and improve the operation speed. A good feature should have four characteristics:

(1) Distinction

Ideally, the feature values ​​of objects belonging to different classes should be significantly different. The greater the difference between a certain feature value of different categories, the stronger the ability to distinguish different categories with this feature, and the distinguishability of features can be measured by the distance between classes.

For the two types of triangles and circles, the class distance obtained by area calculation is relatively small, while the inter-class distance of the shape index is very large. Since the shape indexes of the two types of samples are basically the same, the feature variance is close to 0, so the inter-class distance Appears to be relatively large. If the feature "shape index" is selected as the basis for classification, its distinguishability is high; if the feature "area" is selected as the basis for classification, its distinguishability is low.

(2) Reliability

All objects within the same category should have a certain feature value as close as possible. The closer the eigenvalues ​​in the class are, the higher the reliability of using this eigenvalue to identify such objects is.

For example, for a group of circles of different sizes, if the feature "area" is selected as the basis for distinguishing it from other categories, its reliability is low, and the areas of different samples in the same circle category vary greatly, while the feature "shape index" is selected As the basis of classification, its reliability is very high, and the shape index of each sample in the same circle class is basically the same. The reliability of features is a direct manifestation of the convergence of sample attributes within a category.

(3) Independence

If multiple features must be used for classification, these features should be as uncorrelated as possible. If two highly correlated features basically reflect the same attribute of the object, they can be combined instead of being used alone.

For example, in the classification of geometric shapes, the two features of shape area and perimeter are highly correlated, and there is also a certain correlation between shape area and shape index, but the degree of correlation is relatively low. In an identification system, the distinguishability, reliability and independence of features are all for the composition of the whole system. For a single object, the distinguishability and reliability of features have no reference and comparison significance.

3.1 Rectangularity

The ratio of the area of ​​the target image to the area of ​​the smallest rectangle surrounding the image is used as a measurement parameter of the target rectangularity, which is denoted as


v2-99b29d39b06b64c033d7ee4b257d51e7_b.jpg

(3-1)


in

v2-0667d5748736f72095fe8c196aa22beb_b.jpg

represents the area of ​​the target image,

v2-6f79d8cd3af975586322110027c933a6_b.jpg

Indicates the area of ​​the smallest rectangle that encloses the image. The size of R can reflect the closeness of the target object to the rectangle. The value of rectangularity is bounded between 0 and 1.

3.2 circularity

For a figure with a certain area, generally the smaller the circumference, the smoother the circular surface and the closer it is to a circle; on the contrary, the larger the circumference, the more wrinkles on the circular surface and the more complex the shape. For this reason, circularity is generally used to measure the degree to which a graph is biased toward a circular shape. The circularity of the shape refers to the ratio of the square of the perimeter of the target object to its area, denoted as



v2-8107753043bb5fd008cdf97f3262b775_b.jpg

(3-2)



v2-3865c9be8e00f8c448d910cf7e26ca29_b.jpg

Among them: P represents the perimeter of the graph, and A represents the area surrounded by the perimeter. Theoretically speaking, the circularity of a circle is 1.0, the circularity of a square is =0.79, and the circularity of an equilateral triangle is

v2-3cb364be6cf8fc2fc13eb358d7bbc14d_b.jpg

=0.60.

In addition, there are two calculation formulas for circularity:



v2-83fef0ac0aedc607e90f2f14aed5b417_b.jpg

(3-3)


Among them, A is the area of ​​the area,

v2-4b37456bb3a9df0cdb6a0cbdb36cad32_b.jpg

is the minimum circumscribed circle area of ​​the region. This indicator also considers that the circular area is the most compact, and its compactness is 1. In the calculation, the minimum circumscribed circle area is used as the standard to measure the shape of the region.



v2-2f8b924e7eca113f89809ad40d5b8380_b.jpg

(3-4)

Among them, A is the area of ​​the region, and L is the length of the longest axis of the region. This index considers a circle as a standard shape, but it only considers the length of the longest axis, which can only roughly reflect the shape of the connected region.

3.3 moments

When the object is some simple geometric images, it is more appropriate to describe the parametric object with the above shape. If the boundary features of the image are complex, it is difficult to describe the shape of the object with the above parameters. For complex objects, we can describe complex objects through moment and contour descriptors. The moment feature is based on the statistical analysis of the distribution of gray values ​​within a region, and it is a description of the statistical average, which can describe the overall characteristics of the object from a global perspective. Moment is a linear feature, which is invariant to image rotation, scale, and translation, so it can be used to describe the shape characteristics of the region in the image.

3.4 Invariant moments

The two-dimensional moment invariant theory was proposed by Chinese-American scholar Hu Guiming in 1962, and moments were used for shape recognition. For a continuous image two-dimensional function f(x,y), its (p+q) moment is defined as the following Riemann integral form:



v2-1bc8f5926680e37f70cff0c339f934cb_b.jpg

(3-5)


Where p,q=0,1,2,L. According to the uniqueness theorem (Papoulis, 1965), if f(x,y) is piecewise continuous, that is, as long as there are non-zero values ​​in the xy plane region, then all moments of each order exist, and the sequence of moments {

v2-54cb7fb5ee39fb526f1cfd0d40f16a4c_b.jpg

}

uniquely identified by f(x,y). on the contrary,{

v2-54cb7fb5ee39fb526f1cfd0d40f16a4c_b.jpg

} also uniquely determines f(x,y).

The position of the above moment feature is normalized to obtain the central moment of the image f(x,y):

For a digital image f(x,y), the above integral is replaced by a double summation, and the (p+q) order moment at point (x,y) is defined as:



v2-6eae513890e18fa772987b6dcc0b8fd2_b.jpg

(3-6)


It can be seen that the central geometric moment also conforms to the property of scale invariance.

3.5 Shape feature extraction based on invariant moments

3.5.1 Feature extraction steps









Figure 3-1 Flowchart of shape feature extraction system


1. Make sure to use the Canny operator to extract the edge of the image to obtain the edge image;

2. Perform contour tracking on the edge image to obtain the outer contour image;

3. Preprocessing the outer contour image: first smooth the contour line to obtain a continuous contour line, and use the automatic

The adaptive binarization method binarizes the contour line, and then refines the contour line. finally get a clear continuous

Smooth, single-pixel, binarized outline image;

4. Perform seed filling to obtain the target area surrounded by the outer contour of the image;

5. Calculate the seven invariant moments of the target area to form the shape feature vector of this image;

6. Perform internal normalization processing on the shape feature vector, and store the feature value in the image feature library.

3.5.2 Determination of edge extraction operator

Image edges contain rich information, which is an important attribute for extracting image shape features. Therefore, the edge operator must be clear and accurate.

3.5.3 Common Operators for Edge Extraction

The main calculation method of edge extraction is the convolution method based on the directional derivative mask to obtain the horizontal and vertical gradient images and modulus images, and then extract the maximum value of the modulus according to the gradient direction to obtain the required object edge. It is the detection of the target contour or boundary. Commonly used are Roberts operator, Prewitt operator, Sobel operator and Laplacian operator. In practical applications, because of some practical factors, such as the influence of illumination and random noise, the image is often blurred or isolated edge points appear, which makes edge detection encounter many difficulties. The previous methods have the disadvantage of being sensitive to noise to varying degrees. We need to accurately detect the edge points of the image, which means the following three points:

1. Low error rate, not only less loss of real edges, but also less judgment of non-edges as edges;

2. High positioning accuracy, the detected edge should be on the real edge position;

3. There is a unique response to each edge, and the resulting edge is a single edge.

3.5.4 Canny operator

Canny operator is a kind of edge detection operator with excellent performance, which is widely used in many image processing fields. In essence, it does not simply perform gradient calculations to determine whether a pixel is an edge point. When determining whether a pixel is a current edge point, the influence of other pixels needs to be considered; nor is it simple boundary tracking. When clicking, it needs to be judged according to the current pixel and the previously processed pixels. It transforms the problem of edge detection into the problem of detecting the maximum value of a function. The basic idea is: first select a certain Gauss filter to smooth the processed image, and then use a technique called "non-max suppression" (Non-maxSuppression) to process the smoothed image to obtain The final edge image. Canny proposed three criteria for judging the quality of edge detection operators:

(1) SNR criterion

Try to avoid missed detection and false detection to maximize the output signal-to-noise ratio. The larger the value of the signal-to-noise ratio, the higher the quality of the extracted edge;

(2) Positioning accuracy criteria

The detected edge point position is closest to the actual edge point position, so that the output image positioning accuracy is high;

(3) Single edge response criterion

The response of each edge point is unique. There is a one-to-one correspondence between each actually existing edge point and the detected edge point, and the obtained edge width is a single pixel. Based on the above criteria, use the method of functional derivation to derive an expression composed of the product of edge positioning accuracy and signal-to-noise ratio. This expression is similar to the first-order derivative of the Gauss function, which is the best of the function approximate. The algorithm implementation of the Canny operator mainly includes five parts: image filtering, calculating image gradient, suppressing non-maximum points of gradient, searching the starting point of the boundary, and tracking the boundary.

The Gaussian filter is also used when smoothing the image, and the Gaussian function used is:


v2-50d300fe27a901d0c7e4c26b3151588e_b.jpg


(3-7)














Figure 3-2 Basic flow of the canny operator

1. Use Gaussian filtering to filter the image. The filtering is performed on the x direction first, and then on the y direction.

Line, mainly used to remove noise in the image;

2. Generate a one-dimensional Gaussian distribution function, which is used to generate Gaussian filter coefficients. theoretical Gaussian data

The length of should be infinite, but the actual Gaussian data can only be a finite data length.

According to the knowledge of probability theory, select the data length between [-3σ, 3σ];

3. Calculate the directional derivative, using the original image to calculate the directional derivative of the image pixel;

4. Calculate the gradient, use the calculation result of the directional derivative, and use the second-order norm to calculate the gradient;

5. Suppress the non-maximum gradient points of local pixels. This function is an important part of the Canny operator. Canny

The operator believes that only certain points in the gradient map may become boundary points or the starting point of the boundary;

6. Set the threshold according to the gradient calculation and the result after non-maximum suppression. This function is also an important part of the Canny operator. The setting of the threshold directly involves which pixels may become boundary points. The higher the value of the parameter setting, the fewer the number of detected edge points will be;

7. Use the function to find the starting point of the boundary;

8. According to the execution results of the above steps, start the search from a pixel, and start the search with this pixel

The point is all the border points of a border where the starting point of the border is, and the function adopts a recursive algorithm.

3.6 Experimental results and analysis of edge extraction

3.6.1 Analysis of edge extraction algorithm

Relatively speaking, the image obtained by using the Sobel operator for edge detection is better, because the Sobel operator provides accurate edge direction estimation. However, the edge image obtained by applying the Sobel operator has the problems of discontinuity, low positioning accuracy, sensitivity to noise, and the edge is multi-pixel. The edge extracted by the Canny operator overcomes the above shortcomings, not only can detect the edge well, but also can suppress point noise.

v2-4d29faee236aaf7d298cdfe61894fbf8_b.jpg

3.6.2 Image shape recognition results
















Figure 3-3 Edge extraction results of the original image


Use the canny edge extraction algorithm to extract the edge from the player image.

The basic program code used is as follows:

format long
i=imread('t2.bmp');
imshow(i);
a=rgb2gray(i);
bw=edge(a,'canny');
imshow(bw);



v2-43f9256c0ebfc0505309f84fe318be08_b.jpg






















Figure 3-4 Based on the results of edge extraction and recognition classification in the above figure


The edge extraction result map based on the canny algorithm is classified according to its circularity and moment. The various features of the original image are unchanged, but the shape is marked.

The core program code used by the recognition program is as follows:

a=max(khoangcach{k});
    b=min(khoangcach{k});
    c=dt(k).Area;
    dolech=a-b;
    vuong = c/(4*b^2)
    chunhat=c/(4*b*(a^2-b^2)^0.5);
    tamgiacdeu=(c*3^0.5)/((a+b)^2);
    elip =c/(a*b*pi);
    thoi= (c*( a^2 - b^2 )^0.5) / (2*a^2*b)
    if dolech < 10
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'圆')
    elseif (vuong < 1.05 ) & (vuong > 0.95 )
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'正方形')
    elseif (elip < 1.05 ) & (elip > 0.95 )
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'椭圆')
    elseif (thoi < 1.05 ) & (thoi > 0.95 )
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'菱形')
    elseif ((chunhat <1.05) & (chunhat >0.95))
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'长方形')
    elseif  (tamgiacdeu < 1.05 ) & (tamgiacdeu > 0.95 )
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'三角形')


Where a is the maximum distance from the image center to the edge, and b is the minimum distance from the image center to the edge. If the image is standard, the results calculated by each formula should be 1. This program allows a 5% error, so the range of judgment parameters is between 0.95 and 1.05. Each formula in the program is determined according to the characteristics of the area calculation of various shapes.

The area of ​​an ellipse is

v2-b99694f38723e5a9e8f5e0b325318855_b.jpg

The program first extracts the edge of the image, then calculates these parameters separately, and then compares them with the preset values ​​one by one until the shape of the image is determined.












v2-6485b4f0b247bcb4eb7446969f49f3b0_b.jpg























Figure 3-5 The results of edge extraction and recognition classification based on the sobel algorithm


Extract the edge of the ellipse, and judge that the figure is an ellipse according to the calculated circularity.

Judgment program code is as follows:

a=max(khoangcach{k});
b=min(khoangcach{k});
c=dt(k).Area;
elip =c/(a*b*pi);
elseif (elip < 1.05 ) & (elip > 0.95 )
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'椭圆')





v2-35ca49dd7a14e865cc81f1ea97a34ddc_b.jpg
























Figure 3-6 The results of edge extraction and recognition classification based on sobel algorithm


Extract the edge of the triangle, and judge that the figure is a triangle according to the calculated circularity and moment.

Judgment program code is as follows:

a=max(khoangcach{k});
b=min(khoangcach{k});
c=dt(k).Area;
tamgiacdeu=(c*3^0.5)/((a+b)^2);
elseif  (tamgiacdeu < 1.05 ) & (tamgiacdeu > 0.95 )
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'三角形')


v2-fe08c045fd44040bfde49bfef74c38f2_b.jpg















Extract the edge of the circle, and judge that the figure is a circle according to the calculated circularity and moment.

Judgment program code is as follows:

a=max(khoangcach{k});
b=min(khoangcach{k});
dolech=a-b;
if dolech < 10
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'圆')




v2-5f2f7f18307d77b6349e4d59f77935c6_b.jpg























Figure 3-8 The results of edge extraction and recognition classification based on the sobel algorithm


Extract the edge of the rhombus, and judge that the figure is a rhombus according to the calculated circularity and moment.

Judgment program code is as follows:

a=max(khoangcach{k});
b=min(khoangcach{k});
c=dt(k).Area;
thoi= (c*( a^2 - b^2 )^0.5) / (2*a^2*b)
elseif (thoi < 1.05 ) & (thoi > 0.95 )
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'菱形')



v2-70f7ea6ba9de711ed64636e17b7e4ca6_b.jpg
























Figure 3-9 The results of edge extraction and recognition classification based on the sobel algorithm


Extract the edge of the square, and judge that the figure is a square according to the calculated circularity and moment.

Judgment program code is as follows:

b=min(khoangcach{k});
c=dt(k).Area;
vuong = c/(4*b^2)
elseif (vuong < 1.05 ) & (vuong > 0.95 )
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'正方形')




v2-40d2a7ce93ce1013a31b067887213b13_b.jpg


Figure 3-10 The results of edge extraction and recognition classification based on sobel algorithm


The edge of the rectangle is extracted, and the figure is judged to be a rectangle according to the calculated circularity and moment.

Judgment program code is as follows:

a=max(khoangcach{k});
b=min(khoangcach{k});
c=dt(k).Area;
chunhat=c/(4*b*(a^2-b^2)^0.5);
elseif ((chunhat <1.05) & (chunhat >0.95))
            text(s(k).Centroid(1)-20,s(k).Centroid(2),'长方形')








v2-9302fd05ab82622747abe6f964d2a9a7_b.jpg
























Edge extraction is performed on each of the graphs, and according to the calculated circularity and moment, it is judged what each graph is and output for display.



in conclusion

Compared with other features, the shape feature of the image is more difficult to accurately extract, and it is also difficult to match. It is not a simple task to find the shape feature that conforms to the perceptual characteristics of the human eye. This is because on the one hand the shape of the image is difficult to describe with simple parameters; on the other hand, the current computer processing technology is difficult to accurately process the parameters of shape extraction. In addition, the shape feature of the image often changes due to the size, rotation and translation of the image, so these factors restrict the development of the image retrieval system based on the shape feature. The expression of shape features must be based on the segmentation of objects or regions in the image, which is one of the difficult problems in computer vision and has not been well solved so far. Because the current technology cannot achieve accurate and robust automatic image segmentation.

According to the edge extraction algorithm, this paper extracts the edges of various images, and then judges whether the graphics in the picture are square, triangle, circle, ellipse or rhombus according to the circularity and rectangularity of various shapes of images . From the simulation results, this program basically meets the requirements of the topic.

However, this simulation is mainly based on the shape of the image for recognition. In the future, the image can be further classified and recognized according to the texture and color of the image. The three can be combined, which will greatly improve the accuracy of image recognition. improvement. This can be applied to automatic image recognition and classification, and will be of great use in the field of image intelligent retrieval.

references

[1] Xu Mingyuan, Liu Zengli, "Application of MATLAB Simulation in Signal Processing", Xidian University Press, 2007.11.

[2] Yu Wanbo, "Image Processing Based on MATLAB", Tsinghua University Press, 2008.3.

[3] Bing He, Tian-Yu Ma (2002) VC++ Digital Image Processing Techniques, People Post Pulishing, Beijing.

[4] Feisi Technology Product R&D Center, "MATLAB 7.0 Auxiliary Image Processing", Electronic Industry Press, 2003.1.

[5] Zhang Yujin, "Image Processing and Analysis", Beijing Tsinghua University Press, 2004.7.

[6]Ming-Yang Chern, Yi-Hsiang Lu (2005) Design an integration of parallelHough-transform chips for high-speed line detection. The 11th InternationalConference Digital Object Identifier, vol.2:42-46.

[7] Zhang Zhiyong, "Proficient in MATLAB6.5", Beijing Beihang Electronic Edition, 2002.12.

[8] Sun Jiaguang, Yang Changgui, "Computer Graphics", Tsinghua University Press, 1995.5.

[9]L.G.Roberts, Machine Perception of Three-Dimension Solids, in Optical and Electro-Optimal Information Processing, J.t.Tippett.et al, Ed.Cambridge, MA: MIT Press, 1965, pp.159-197.

[10] Yan Jingwen, "Digital Image Processing MATLAB Edition", National Defense Industry Press, 2007.2.

[11] Chen Yang, Chen Rongjuan, "MATLAB6.X Image Programming and Image Processing", Xidian University Press, 2002.10.

[12]Byeong Rae Lee,Kyungsoo Park:Adaptive Local Binarization Method for Recognition of Vehicle License PIates.IWCIA 2009:646~655.

[13] Zhou Xinlun, Liu Jian, "Digital Image Processing", National Defense Industry Press, 1986.3.

[14] Li Xinzhen, Che Minggang, "Calculation Method", Xi'an Northwestern Polytechnical University Press, 2000.8.

[15] Arno Lowe. MATLAB and SIMULINK. Chemical Reaction Engineering,2009, 10(1002):5-24.

[16] Chen Guiming, Zhang Mingzhao, "Applying MATLAB Language to Process Signals and Digital Images", Science Press, 2000.5.

[17] Cheng Junxin. Research on edge detection method based on gray image: (Master's degree thesis). Taiyuan: Taiyuan University of Technology, 2008.

Guess you like

Origin blog.csdn.net/TuTu998/article/details/120177049