A method for image contour extraction based on reference region binarization results
By using the reference area-based binarization processing and the Moore-Neighbor tracking algorithm in image processing, the problems of background light changes and environmental interference in image contour extraction are solved, and a simple and efficient contour extraction effect is achieved.
Patent Information
- Application Number
- CN202210744151.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-27
- Publication Date
- 2025-05-16
- Estimated Expiration
- 2042-06-27
AI Technical Summary
The prior art is difficult to effectively reduce background light changes and the surrounding environment in image contour extraction, resulting in failure of contour extraction.
The image contour extraction method based on the binarization result of reference area is adopted, and the entire image is grayscaled and the reference area binarization is performed. The global threshold is determined using the Otsu method, and the contour is extracted by the Moore-Neighbor tracking algorithm.
It realizes simple, direct and efficient extraction of image contours, reduces the impact of background light changes and environmental interference, and is suitable for target contour extraction of different shape features and sizes.
Smart Images

Figure CN115187790B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of computer automated processing of visual images, and in particular to an image contour extraction method based on a reference region binarization result. Background Art
[0002] In technical applications involving image processing and recognition, the recognition of the image subject and the extraction of the subject's contour are very important pre-processing links. Color image signals can be processed as an array matrix containing three channels of R, G, and B. After grayscale processing of the color image, it can be further simplified into a two-dimensional matrix. Usually, there is a large color difference between the image subject and the background. By setting a threshold, the recognition and contour extraction of the image subject area can be achieved. Similarly, machine learning methods can also be used to achieve the recognition and contour extraction of the image subject after learning a large amount of contour information consistent with the type of image to be identified.
[0003] At present, there are two main methods for related technical research in this field. On the one hand, a specific calculation method is used to obtain feature values and realize the recognition of image contours, such as: Sobel operator, GVF snake model, threshold segmentation, Gabor filter, etc. The Sobel operator obtains the gradient information by convolution with the image to obtain the contour, and the GVF snake model calculates the gradient vector flow, which has a large amount of calculation; while the threshold segmentation method, when extracting the image contour, defaults to identifying the object with higher brightness as the subject, and the rest is considered to be the background. If the brightness and color of the subject target and the background change, it is easy for the background to be identified as the subject, resulting in the problem of contour extraction failure. Another type of method uses machine learning algorithms, such as: structural forest, GAN network, adversarial network, K-means clustering, etc. This type of method has a good effect on the recognition of specific types of image contours, but it requires the establishment of data sets and network training. The program is relatively complicated and the trained network has poor versatility, which is suitable for the processing of specific types of images. Therefore, a simple and efficient contour extraction method is urgently needed. Summary of the invention
[0004] The present application provides an image contour extraction method based on the reference area binarization result, and its technical purpose is to effectively reduce the impact of background light changes and surrounding environment interference on contour extraction, making contour extraction simple and efficient.
[0005] The above technical objectives of this application are achieved through the following technical solutions:
[0006] A method for extracting image contours based on a reference region binarization result, comprising:
[0007] S1: grayscale the entire image to obtain a grayscale image;
[0008] S2: Determine the position (x, y) and size (w, h) of the reference area in the grayscale image;
[0009] S3: when binarizing the reference area, a global threshold is determined by the Otsu method, a pixel matrix of the reference area after binarization is calculated according to the global threshold, and an average value of all elements in the pixel matrix is calculated;
[0010] S4: Determine a binarization matrix of the entire image according to the average value;
[0011] S5: extracting the contour of the subject target to be identified in the binary matrix by using the Moore-Neighbor tracking algorithm.
[0012] The beneficial effects of the present application are as follows: the image contour extraction method based on the reference area binarization result described in the present application is simple and direct to implement, has low computational cost, and has low hardware requirements. For a visual image containing a single target subject, its contour can be quickly extracted, and it can also be used to remove the background in a plane image. The reference area is customized by the user according to the shape and size of the target subject of the extracted contour, and can be applied to target contour extraction scenarios with different shape features and sizes. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 This is a flow chart of the image contour extraction method described in this application;
[0014] Figure 2 It is a schematic diagram of a specific embodiment. DETAILED DESCRIPTION
[0015] The technical solution of the present application will be described in detail below with reference to the accompanying drawings.
[0016] like Figure 1 As shown, the image contour extraction method based on the reference area binarization result described in this application specifically includes:
[0017] S1: grayscale the entire image to obtain a grayscale image.
[0018] S2: Determine the position (x, y) and size (w, h) of the reference area in the grayscale image.
[0019] S3: When binarizing the reference area, a global threshold is determined by the Otsu method, a pixel matrix of the binarized reference area is calculated according to the global threshold, and an average value of all elements in the pixel matrix is calculated.
[0020] S4: Determine a binarization matrix of the entire image according to the average value.
[0021] S5: extracting the contour of the subject target to be identified in the binary matrix by using the Moore-Neighbor tracking algorithm.
[0022] Figure 2 is a schematic diagram of a specific embodiment, such as Figure 2 As shown in (b), the entire image is grayed, and the graying method includes: converting the RGB colors of the color image into gray values in a weighted summation manner, and the value of the i-th row and j-th column of the gray value matrix is expressed as a gray value I(i,j)=0.299*R+0.587*G+0.114*B; wherein R, G, and B represent the values of the pixel point in the i-th row and j-th column of the color image in the red, green, and blue color channels, respectively.
[0023] If the image to be identified is a grayscale image, this step can be skipped.
[0024] Figure 2 In (c), the position (x, y) and size (w, h) of the reference area in the grayscale image are determined. The position (x, y) of the reference area indicates the position of the center point of the known subject target to be identified in the grayscale image. The reference area is a rectangular area, and w and h represent the width and height of the rectangular area, respectively. It is determined according to the shape characteristics and size of the subject target to be identified. In general, a square area with w=h can be taken as the reference area, and the area of the reference area should be smaller than the area of the subject target to be identified.
[0025] Figure 2 (d) represents the calculation method of the pixel matrix, specifically: if the gray value I(i,j)>=W_ROI, then bw_ROI(i,j)=1; otherwise, bw_ROI(i,j)=0; wherein W_ROI represents the global threshold, and bw_ROI(i,j) represents the value of the i-th row and j-th column in the pixel matrix.
[0026] Calculating the average value of all elements in the pixel matrix includes: Calculate the average value Nmean_ROI, where Nmean_ROI is a value that is rounded to a near integer; wherein m and n represent the number of rows and columns of pixels in the reference area, respectively.
[0027] Figure 2(e) indicates that the entire image is binarized, and the global threshold value of the binarization of the entire image is determined by the Otsu method, and then the binarized pixel matrix bw_temp is calculated. If Nmean_ROI = 1, the binarization matrix is represented by bw = bw_temp; otherwise, bw = ~bw_temp; where bw represents the binarization matrix; bw_temp represents the pixel matrix; ~bw_temp means that each element in bw_temp is inverted, that is, 0 becomes 1, and 1 becomes 0.
[0028] Figure 2 (f) in the figure indicates that the contours of all objects in the binary matrix are calculated by the Moore-Neighbor tracking algorithm, and the contour with the maximum pixel point in the obtained contour and located near the reference area is the contour of the main target to be identified.
[0029] The above are exemplary embodiments of the present application, and the protection scope of the present application is defined by the claims and their equivalents.
Claims
1. A method for extracting image contours based on the binarization result of a reference region, characterized in that: include: S1: grayscale the entire image to obtain a grayscale image; S2: Determine the position (x, y) and size (w, h) of the reference area in the grayscale image; S3: when binarizing the reference area, a global threshold is determined by the Otsu method, a pixel matrix of the reference area after binarization is calculated according to the global threshold, and an average value of all elements in the pixel matrix is calculated; S4: Determine a binarization matrix of the entire image according to the average value; S5: extracting the contour of the subject target to be identified in the binary matrix by using the Moore-Neighbor tracking algorithm.
2. The image contour extraction method according to claim 1, characterized in that: In step S1, the grayscale processing method includes: converting the RGB three colors of the color image into grayscale values in a weighted summation manner, and the value of the i-th row and j-th column of the grayscale value matrix is expressed as a grayscale value I(i,j)=0.299*R+0.587*G+0.114*B; wherein R, G, and B respectively represent the values of the pixel point in the i-th row and j-th column of the color image in the red, green, and blue color channels.
3. The image contour extraction method according to claim 1, characterized in that: In step S2, the position (x, y) of the reference area represents the position of the center point of the known subject target to be identified in the grayscale image, the reference area is a rectangular area, w and h represent the width and height of the rectangular area respectively; the area of the reference area is smaller than the area of the subject target to be identified.
4. The image contour extraction method according to claim 1, characterized in that: In step S3, the calculation method of the pixel matrix is expressed as follows: if the gray value I(i,j)>=W_ROI, then bw_ROI(i,j)=1; otherwise, bw_ROI(i,j)=0; wherein W_ROI represents the global threshold, and bw_ROI(i,j) represents the value of the i-th row and j-th column in the pixel matrix; Calculating the average value of all elements in the pixel matrix includes: Calculate the average value Nmean_ROI, where Nmean_ROI is an integer value; wherein m and n represent the number of rows and columns of pixels in the reference area, respectively.
5. The image contour extraction method according to claim 4, characterized in that: In the step S4, if Nmean_ROI=1, the binary matrix is expressed as bw=bw_temp; otherwise, bw=~bw_temp; wherein bw represents the binary matrix; bw_temp represents the pixel matrix; ~bw_temp represents inverting each element in bw_temp.
6. The image contour extraction method according to claim 4, characterized in that: The step S5 comprises: calculating the contours of all objects in the binary matrix by using the Moore-Neighbor tracking algorithm, and the contour with the maximum pixel point in the obtained contour and located near the reference area is the contour of the main target to be identified.
Citation Information
Patent Citations
Image binarization method and device
CN101042735A
Image binarization method based on accumulative edge point visual gray range histogram
CN102496020A