Self-adaptive image region-of-interest extraction method
Through the adaptive image area of interest extraction method, the region of interest is accurately extracted using threshold segmentation and clustering processing, which solves the problems of waste of resources and insufficient accuracy in the prior art, and achieves efficient area extraction and anti-interference capabilities.
Patent Information
- Application Number
- CN202510536960.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-27
- Publication Date
- 2025-08-08
AI Technical Summary
The prior art has problems such as wasting computing resources and increasing storage space in the extraction of the region of interest of images, and being sensitive to position deviation and noise, and insufficient accuracy.
Adaptive image area of interest extraction method is adopted, and the region of interest is accurately extracted through threshold segmentation, clustering processing, connectivity domain analysis and aggregation degree judgment, non-aggregation areas are deleted, and computing resource consumption and storage space are reduced.
It realizes more accurate extraction of areas of interest, reduces computing resource consumption and storage space, has adaptability and anti-interference capabilities, and has fast processing speed.
Smart Images

Figure CN120451499A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to an adaptive method for extracting regions of interest in images. Background Art
[0002] In recent years, visual inspection technology has been widely used in various industrial fields. During the visual inspection process, in order to reduce computing resources and storage space, it is usually necessary to first effectively extract the region of interest (ROI) in the image and then calculate the features in the region of interest.
[0003] There are two main methods for extracting regions of interest (ROI):
[0004] One method is to manually select the valid area of the image and take a screenshot. This method is labor-intensive, has poor accuracy, and poor adaptability. When the placement of the object being inspected or the object itself changes, manual re-annotation is required. Moreover, in batch inspection scenarios, due to the deviation in repeated positioning accuracy, the position of the batch of workpieces in the image will be offset. In order to ensure that the annotated screenshot frame is applicable to the entire image of the object to be inspected, a larger rectangular selection frame is usually set to ensure that the selection frame has a margin to cover the batch of workpieces to be inspected. This will result in the extracted ROI area being too large, resulting in a waste of computing resources and an increase in storage space.
[0005] Another method is to directly use the global threshold segmentation method to directly extract the part of the image that is larger than a given threshold as the valid area. The problem is that if there are adjacent noise points and outliers in the image that are relatively far away, the extracted valid area will be too large, resulting in a waste of computing resources and an increase in storage space. Summary of the Invention
[0006] To address the above technical issues, the present invention provides an adaptive method for extracting regions of interest (ROIs) from images. This method extracts more accurate and smaller ROIs, effectively reducing computing resource consumption and storage space usage. It also features strong adaptability, high anti-interference capabilities, and fast processing speed.
[0007] The technical solution is as follows:
[0008] An adaptive method for extracting regions of interest in images, comprising the following steps:
[0009] Step 1: Perform threshold segmentation on the image to obtain a binary image;
[0010] Step 2: Clustering the foreground points in the binary image to form multiple categories, and the category with the largest number of foreground points is recorded as the main category;
[0011] Only the foreground points in the main category are retained and other foreground points are deleted;
[0012] In the image, find connected areas based on foreground points;
[0013] Step 3: traverse all foreground points in each connected domain, determine the degree of aggregation between the currently traversed foreground point and its surrounding foreground points based on the relative density between the currently traversed foreground point and its surrounding foreground points, and then mark the foreground point as a clustered point or a non-clustered point based on the degree of aggregation; the relative density is: a value obtained by substituting the pixel coordinates of the surrounding foreground points and the currently traversed foreground point into a two-dimensional Gaussian function, and then summing the function values; or a value obtained by substituting the distances between the surrounding foreground points and the currently traversed foreground point into a negative exponential function with the natural constant e as the base, and then summing the function values;
[0014] If the number of marked cluster points is greater than the preset number, the current connected domain is recorded as a cluster area, otherwise, it is recorded as a non-cluster area;
[0015] Step 4: record the clustered area as the region of interest, delete the non-clustered area, and complete the region of interest extraction.
[0016] Furthermore, in step 3, the method of marking the foreground point as a gathering point / non-gathering point is as follows:
[0017] Find other foreground points in the neighborhood of the currently traversed foreground point, and obtain the relative density between the other found foreground points and the currently traversed foreground point;
[0018] If the relative density is greater than the threshold value I, the degree of aggregation between the foreground point and its surrounding foreground points meets the requirement, and the foreground point is marked as an aggregation point; otherwise, the foreground point is marked as a non-aggregation point.
[0019] Preferably, the distance is any one of Euclidean distance, Manhattan distance, and Chebyshev distance.
[0020] Furthermore, the neighborhood of the currently traversed foreground point is recorded as p×p, where p is a preset value ranging from 10 to 30 pixels.
[0021] Alternatively, p can be calculated using the following steps:
[0022] ① Get the boundaries of each connected domain and record the longest boundary as the main boundary;
[0023] ② Traverse all foreground points on the main boundary and take each traversed foreground point as the center point K i ; i = 1, 2...n, n represents the total number of foreground points on the main boundary;
[0024] For each center point K i , both foreground points around the main boundary are fitted with a circle and the radius R is recorded.i ;
[0025] ③ Set the radius R i Sort from small to large, and record the ath radius value as the neighborhood length p, or take the average of the first b% of radius values and record it as the neighborhood length p;
[0026] Among them, a ranges from 2 to 8, and b ranges from 2 to 5.
[0027] Preferably, the threshold I is set to (0.1-0.3)×p.
[0028] In order to improve the processing speed, preferably, in step three, the traversal order of each foreground point in a single connected domain is: first traverse each foreground point located on the boundary of the connected domain, and when the number of clustered points obtained by marking is greater than the preset number, stop traversing; otherwise, continue to traverse the inside of the connected domain in sequence.
[0029] Furthermore, the method of continuing to traverse the connected domain is as follows:
[0030] 1) Obtain the boundaries of each connected domain and record the longest boundary as the main boundary;
[0031] 2) Traverse all foreground points on the main boundary and take each traversed foreground point as the center point K i ; i = 1, 2...n, n represents the total number of foreground points on the main boundary;
[0032] For each center point K i , fit a circle around the two foreground points on the main boundary and record the coordinates of the center point O i ;
[0033] 3) Remember the center point K i To the center point O i The direction between them is direction I and the center point O i The direction from the center point S to the center point S is direction II; the coordinates of the center point S are (X 均 , Y 均 ), X 均 Represents the mean X-axis coordinate of all foreground points on the main boundary, Y 均 Represents the mean Y-axis coordinate of all foreground points on the main boundary; if the cross product result between direction I and direction II is greater than 0, then continue to traverse the foreground points inside the connected domain along direction I; otherwise, continue to traverse the foreground points inside the connected domain along the opposite direction of direction I.
[0034] Furthermore, the preset number is 3 to 8.
[0035] Furthermore, the method for finding the connected domain is any one of the four-neighborhood labeling method, the eight-neighborhood labeling method, and the Two-Pass algorithm.
[0036] Furthermore, before performing threshold segmentation in step 1, the image is first subjected to denoising and overexposed point filtering;
[0037] In step 2, the clustering method is a spectral clustering method, a hierarchical clustering method or a k-means clustering method.
[0038] Compared with traditional manual labeling and global threshold segmentation, this method has the following advantages:
[0039] (1) Accurate extraction of regions: This method first filters out outliers through clustering, and then removes overexposed points and noise points based on the degree of aggregation between foreground points, making the extracted effective region more accurate and the size of the extracted region of interest smaller, effectively reducing the consumption of computing resources and storage space.
[0040] Compared with the global segmentation method, the effect of segmenting the region of interest in complex scenes such as those with many and unevenly distributed noise points, uneven lighting, poor contrast, overexposed or dark areas is more significant.
[0041] At the same time, this method can also achieve precise positioning for workpieces with large changes in contour curvature, many curves, and irregular lines.
[0042] (2) Strong adaptability: When used in batch workpiece inspection scenarios, even if the position deviation of the workpiece to be inspected is large each time, this method can still adaptively eliminate the noise area and accurately extract the effective area. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 is a grayscale image of the workpiece in a specific implementation manner;
[0044] Figure 2 This is a binary image of the workpiece in a specific implementation manner;
[0045] Figure 3 In a specific embodiment, only the images after the foreground points in the main category are retained;
[0046] Figure 4 This is a schematic diagram of the region of interest that is ultimately retained in a specific implementation manner. DETAILED DESCRIPTION
[0047] The technical solution of the present invention is described in detail below with reference to the accompanying drawings and specific embodiments.
[0048] An adaptive method for extracting regions of interest in images, comprising the following steps:
[0049] Step 1: Image ( Figure 1 ) to perform threshold segmentation and obtain a binary image ( Figure 2 );
[0050] Step 2: Clustering the foreground points in the binary image to form multiple categories, and the category with the largest number of foreground points is recorded as the main category;
[0051] Only keep the foreground points in the main category and delete the other foreground points ( Figure 3 );
[0052] In the image, find connected areas based on foreground points;
[0053] The method for finding connected domains can be selected from the four-neighborhood / eight-neighborhood marking method and the Two-Pass algorithm;
[0054] Step 3: traverse the foreground points in each connected domain, determine the degree of aggregation between the currently traversed foreground point and its surrounding foreground points based on the relative density between the currently traversed foreground point and its surrounding foreground points, and then mark the foreground point as a clustered point or a non-clustered point based on the degree of aggregation; the relative density is: a value obtained by substituting the pixel coordinates of the surrounding foreground points and the currently traversed foreground point into a two-dimensional Gaussian function, and then accumulating the function values; or a value obtained by substituting the distances between the surrounding foreground points and the currently traversed foreground point into a negative exponential function with the natural constant e as the base, and then accumulating the function values;
[0055] If the number of marked cluster points is greater than the preset number, the current connected domain is recorded as a cluster area, otherwise, it is recorded as a non-cluster area;
[0056] The preset number ranges from 3 to 8; in this embodiment, the value is 3;
[0057] Step 4: Record the clustered area as the region of interest and delete the non-clustered area ( Figure 4 ), complete the extraction of the region of interest.
[0058] Specifically, the method of marking the foreground point as a gathering point / non-gathering point is as follows:
[0059] Find other foreground points in the neighborhood of the currently traversed foreground point, and calculate the relative density between the other found foreground points and the currently traversed foreground point;
[0060] If the relative density is greater than the threshold value I, the degree of aggregation between the foreground point and its surrounding foreground points meets the requirement, and the foreground point is marked as an aggregation point; otherwise, the foreground point is marked as a non-aggregation point.
[0061] In specific implementation, the relative density can be obtained by using method A or method B:
[0062] Method A: Substitute the pixel coordinates of the other foreground points (surrounding foreground points) and the currently traversed foreground point into the two-dimensional Gaussian function, and record the sum of the function values as the relative density d. The formula is as follows:
[0063]
[0064] Among them, σ is a preset constant, (x q ,y q ) The pixel coordinates of the qth other foreground point in the neighborhood, q = 1, 2...Q, where Q represents the total number of other foreground points in the neighborhood; (x j ,y j ) is the center point H j The pixel coordinates of
[0065] In this embodiment, In specific implementation, it can also be set to other values based on experience, such as
[0066] Method B:
[0067] Calculate the distance (pixel distance) between the other foreground points found (surrounding foreground points) and the currently traversed foreground point; where the distance can be any of the Euclidean distance, Manhattan distance, and Chebyshev distance;
[0068] Substitute the distance into the negative exponential function with the natural constant e as the base, and then accumulate all the function values obtained. The accumulated value is recorded as the relative density d. The formula is as follows: Formula 1. Substitute the Euclidean distance into the negative exponential function with the natural constant e as the base to obtain the relative density d:
[0069]
[0070] Formula 2: Substitute the Manhattan distance into the negative exponential function with the natural constant e as the base to obtain the relative density d:
[0071]
[0072] Formula 3: Substitute the Chebyshev distance into the negative exponential function with the natural constant e as the base to obtain the relative density d:
[0073]
[0074] Among them, (x q ,y q ) The pixel coordinates of the qth other foreground point in the neighborhood, q = 1, 2...Q, where Q represents the total number of other foreground points in the neighborhood; (x j ,y j ) is the center point H jThe pixel coordinates of .
[0075] More specifically, the neighborhood of the currently traversed foreground point is denoted as p×p, where p is a preset value ranging from 10 to 30 pixels.
[0076] Alternatively, in order to make the relative density evaluation area more reasonable and to filter out noise points more accurately, p is calculated using the following steps:
[0077] ① Get the boundaries of each connected domain and record the longest boundary as the main boundary;
[0078] ② Traverse all foreground points on the main boundary and take each traversed foreground point as the center point K i ; i = 1, 2...n, n represents the total number of foreground points on the main boundary;
[0079] For each center point K i , the center point K is taken on the main boundary i The two foreground points around the circle are fitted together, and the radius R is recorded. i ;
[0080] ③ Set the radius R i Sort from small to large, and record the ath radius value as the neighborhood length p, or take the average of the first b% of radius values and record it as the neighborhood length p;
[0081] Among them, a ranges from 2 to 8, and b ranges from 2 to 5.
[0082] Correspondingly, the threshold I is set to (0.1-0.3)×p.
[0083] Among them, take the center point K on the main boundary i The way the two surrounding foreground points fit the circle together is:
[0084] At the center point K i The left and right sides are respectively searched for the center point K i The foreground points are separated by t points, and the foreground points and the center point K are used to find the foreground points. i Jointly fit circles; where t takes values of 1 to 3.
[0085] For example, the foreground points on the main boundary are K1, K2, K3, K4, K5, K6, K7, and K8, respectively. Take t as 1 for example. Then:
[0086] When the center point K i For K3, a circle is fitted using foreground points K1, K5 and K3.
[0087] In order to improve the extraction speed, in step 3, the traversal order of each foreground point in a single connected domain is as follows: first traverse each foreground point located on the boundary of the connected domain. When the number of clustered points obtained by marking is greater than the preset number, stop traversing. Otherwise, continue traversing in sequence towards the inside of the connected domain.
[0088] Among them, the method of continuing to traverse the connected domain in sequence is as follows:
[0089] 1) Obtain the boundaries of each connected domain and record the longest boundary as the main boundary;
[0090] 2) Traverse all foreground points on the main boundary and take each traversed foreground point as the center point K i ; i = 1, 2...n, n represents the total number of foreground points on the main boundary;
[0091] For each center point K i , the center point K is taken on the main boundary i The two surrounding foreground points are fitted into a circle and the coordinates of the center point O are recorded. i ;
[0092] 3) Remember the center point K i To the center point O i The direction between them is direction I and the center point O i The direction from the center point S to the center point S is direction II; the coordinates of the center point S are (X 均 , Y 均 ), X 均 Represents the mean X-axis coordinate of all foreground points on the main boundary, Y 均 Represents the mean Y-axis coordinate of all foreground points on the main boundary; if the cross product result between direction I and direction II is greater than 0, then continue to traverse the foreground points inside the connected domain along direction I; otherwise, continue to traverse the foreground points inside the connected domain along the opposite direction of direction I.
[0093] In order to further improve the image quality, before threshold segmentation in step 1, the image is first subjected to denoising and overexposed point filtering;
[0094] The present invention does not limit the clustering method in step 2. In specific implementation, spectral clustering, hierarchical clustering or k-means clustering can be used. In this embodiment, k-means clustering is used, where k is 2 to 5.
[0095] This method can adaptively remove noise areas, making the extracted effective areas more accurate; compared with the global threshold segmentation method, it is more effective in segmenting regions of interest in complex scenes with many and unevenly distributed noise points, uneven lighting, poor contrast, overexposed or dark areas.
[0096] The foregoing descriptions of specific exemplary embodiments of the present invention have been presented for purposes of illustration and description. The foregoing descriptions are not intended to be exhaustive or to limit the invention to the precise forms disclosed, and it is apparent that many variations and modifications are possible in light of the foregoing teachings. The exemplary embodiments have been chosen and described in order to explain the specific principles of the invention and their practical application, thereby enabling others skilled in the art to make and utilize the various exemplary embodiments of the invention and various alternatives and modifications thereof. The scope of the invention is intended to be defined by the appended claims and their equivalents.
Claims
1. An adaptive method for extracting regions of interest in images, characterized in that: The following steps are involved: Step 1: Perform threshold segmentation on the image to obtain a binary image; Step 2: Clustering the foreground points in the binary image to form multiple categories, and the category with the largest number of foreground points is recorded as the main category; Only the foreground points in the main category are retained and other foreground points are deleted; In the image, find connected areas based on foreground points; Step 3: Traverse all foreground points in each connected domain, determine the degree of clustering between the currently traversed foreground point and its surrounding foreground points based on their relative density, and then mark the foreground point as a clustered point or a non-clustered point based on the clustering degree. The relative density is obtained by substituting the pixel coordinates of the surrounding foreground points and the currently traversed foreground point into a two-dimensional Gaussian function and then accumulating the function values; or by substituting the distances between the surrounding foreground points and the currently traversed foreground point into a negative exponential function with the natural constant e as the base and then accumulating the function values. If the number of marked cluster points is greater than the preset number, the current connected domain is recorded as a cluster area, otherwise, it is recorded as a non-cluster area; Step 4: record the clustered area as the region of interest, delete the non-clustered area, and complete the region of interest extraction.
2. The adaptive image region of interest extraction method according to claim 1, wherein: In step 3, the method of marking the foreground point as a gathering point or a non-gathering point is as follows: Find other foreground points in the neighborhood of the currently traversed foreground point, and obtain the relative density between the other found foreground points and the currently traversed foreground point; If the relative density is greater than the threshold value I, the degree of aggregation between the foreground point and its surrounding foreground points meets the requirement, and the foreground point is marked as an aggregation point; otherwise, the foreground point is marked as a non-aggregation point.
3. The adaptive image region of interest extraction method according to claim 1, wherein: The distance is any one of Euclidean distance, Manhattan distance, and Chebyshev distance.
4. The adaptive image region of interest extraction method according to claim 2, wherein: The neighborhood of the currently traversed foreground point is recorded as p×p, where p is a preset value ranging from 10 to 30 pixels. Alternatively, p can be calculated using the following steps: ① Get the boundaries of each connected domain and record the longest boundary as the main boundary; ② Traverse all foreground points on the main boundary and take each traversed foreground point as the center point K i ; i = 1, 2...n, n represents the total number of foreground points on the main boundary; For each center point K i , both foreground points around the main boundary are fitted with a circle and the radius R is recorded. i ; ③ Set the radius R i Sort from small to large, and record the ath radius value as the neighborhood length p, or take the average of the first b% of radius values and record it as the neighborhood length p; Among them, a ranges from 2 to 8, and b ranges from 2 to 5.
5. The adaptive image region of interest extraction method according to claim 4, characterized in that: The threshold I is set to (0.1 to 0.3) × p.
6. The adaptive image region of interest extraction method according to claim 1 or 2, characterized in that: In step 3, the order of traversing each foreground point in a single connected domain is as follows: first traverse each foreground point located on the boundary of the connected domain. When the number of clustered points obtained by marking is greater than the preset number, stop traversing. Otherwise, continue traversing into the connected domain in sequence.
7. The adaptive image region of interest extraction method according to claim 6, wherein: The way to continue traversing the connected domain is as follows: 1) Obtain the boundaries of each connected domain and record the longest boundary as the main boundary; 2) Traverse all foreground points on the main boundary and take each traversed foreground point as the center point K i ; i = 1, 2...n, n represents the total number of foreground points on the main boundary; For each center point K i , fit a circle around the two foreground points on the main boundary and record the coordinates of the center point O i ; 3) Remember the center point K i To the center point O i The direction between them is direction I and the center point O i The direction from the center point S to the center point S is direction II; the coordinates of the center point S are (X 均 , Y 均 ), X 均 Represents the mean X-axis coordinate of all foreground points on the main boundary, Y 均 Represents the mean Y-axis coordinate of all foreground points on the main boundary; if the cross product result between direction I and direction II is greater than 0, then continue to traverse the foreground points inside the connected domain along direction I; otherwise, continue to traverse the foreground points inside the connected domain along the opposite direction of direction I.
8. The adaptive image region of interest extraction method according to claim 1, wherein: The preset number ranges from 3 to 8.
9. The adaptive image region of interest extraction method according to claim 1, wherein: The method for finding the connected domain is any one of the four-neighborhood labeling method, the eight-neighborhood labeling method, and the Two-Pass algorithm.
10. The adaptive image region of interest extraction method according to claim 1, wherein: Before performing threshold segmentation in step 1, the image is first subjected to denoising and overexposed point filtering; In step 2, the clustering method is a spectral clustering method, a hierarchical clustering method or a k-means clustering method.