Lens region segmentation and classification method in industrial visual quality inspection
Through polar coordinate analysis and a two-stage segmentation strategy, combined with radial projection and decision tree classifiers, the problem of automated segmentation and classification of lenses with complex optical designs is solved, accurate segmentation and classification of lens areas are achieved, and efficient and reliable industrial visual quality inspection is supported.
Patent Information
- Application Number
- CN202510785066.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-12
- Publication Date
- 2025-09-16
AI Technical Summary
When processing multi-ring structure images produced by complex optical designs and directional lighting of lenses, existing technologies have difficulty in accurately extracting texture area boundaries and cannot automatically classify them. Manual labeling methods are inefficient and inaccurate, and cannot meet the accuracy requirements of industrial quality inspection.
Polar coordinate analysis and a two-stage segmentation strategy are used, combined with radial projection and median filtering. The annular structure characteristics of the image are obtained through polar coordinate transformation, and the decision tree classifier is used for regional classification to achieve automated and accurate segmentation and classification of lens areas.
It achieves automated, precise segmentation and classification of lens areas, improves segmentation accuracy and robustness, supports subsequent differentiated detection, and meets industrial quality inspection needs.
Smart Images

Figure CN120655663A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of machine vision and image processing, and in particular to a method for segmenting and classifying lens regions in industrial visual quality inspection. Background Art
[0002] As precision optical components, the camera lenses of electronic devices (such as mobile phones and monitors) need to be designed to achieve high-quality optical imaging paths in an extremely limited space.
[0003] To achieve this, the lenses themselves often have a complex, multi-layered design with uneven, curved surfaces.
[0004] In industrial visual inspection processes, a lens is often illuminated with a directional light source (such as an annular light or coaxial light) to highlight surface features. However, due to the complex, non-planar optical surface structure of the lens, directional light causes light to reflect and refract differently in different areas. This results in the image captured by the camera appearing as multiple ring-like structures with alternating light and dark, each with distinct characteristics (this can be understood as a halo, or scattering).
[0005] The existing technology has the following difficulties and limitations when processing images with multi-ring structures and diverse visual features, which are generated by the complex optical design of lenses and directional lighting:
[0006] 1. Limitations of conventional automated segmentation algorithms:
[0007] Edge-based or threshold-based algorithms have difficulty accurately extracting the boundaries of textured areas (such as "frosted areas") and are unable to automatically classify the segmented areas;
[0008] This hinders the subsequent automatic execution of targeted detection strategies based on area types;
[0009] 2. Inherent defects of manual labeling methods:
[0010] While manual labeling is flexible, it suffers from imprecise boundary definition and poor consistency, failing to meet the precision requirements of industrial quality inspection. Furthermore, it is inefficient and costly, making it unsuitable for automated mass production.
[0011] In summary, existing technologies are insufficient in accurately segmenting and automatically classifying such complex lens regions. Therefore, a technical solution that can automatically perform precise region segmentation and type recognition is urgently needed to support reliable and efficient differentiated industrial visual quality inspection. Summary of the Invention
[0012] The main purpose of this invention is to propose a method for lens area segmentation and classification in industrial visual quality inspection, aiming to achieve the following technical effects:
[0013] 1. Automated processing: Provide a fully automated method to replace inefficient and inaccurate manual labeling;
[0014] 2. Improve segmentation accuracy: Overcoming the limitations of conventional automated algorithms, it can accurately segment the boundaries of various annular areas on the lens surface caused by optical effects, including texture areas;
[0015] 3. Achieve regional classification: not only complete segmentation, but also accurately and automatically classify according to the visual characteristics of the region (such as pure color, frosted, bright ring, etc.);
[0016] 4. Support subsequent inspection: Provide reliable and accurate region segmentation and classification basis for subsequent differentiated industrial visual quality inspection processes based on different region types.
[0017] To achieve the above objectives, the present invention proposes a method for lens area segmentation and classification in industrial visual quality inspection, comprising:
[0018] Polar coordinate analysis and two-stage segmentation strategy are used and feature classification is integrated.
[0019] The steps include:
[0020] S1: Image acquisition and lens positioning:
[0021] Obtain the front image I(x, y) of the lens and accurately determine the coordinates of the center of the lens area (x0, y0);
[0022] S2. Polar coordinate transformation:
[0023] S21: transform the lens area image centered at (x0, y0) from the Cartesian coordinate system (x, y) to the polar coordinate system,
[0024] S22: Get polar coordinate image I p (r, θ); where r is the radius and θ is the angle, and the annular structure characteristics of the image are obtained through transformation;
[0025] S3: Radial projection and rough boundary estimation:
[0026] Calculate the radial projection one-dimensional vector P(r),
[0027] S3 is performed by rotating the polar coordinate image I along the angle θ direction. p The pixel values of (r, θ) are summarized;
[0028] The obtained one-dimensional vector P(r) is subjected to median filtering to remove noise, and the filtered vector P is obtained. filtered (r);
[0029] After filtering, Pfiltered (r) setting one or more thresholds T,
[0030] By comparing P filtered The (r) value and the threshold are used to identify the rough radial position (radius value) of the boundary between different annular regions. k}Complete rough segmentation;
[0031] S4: Combined with rough boundary information {r k},
[0032] Using an accurate edge detection algorithm in Cartesian coordinates k} Find and locate the precise boundary point set between the annular areas near the edge detection; fit the boundary point coordinate set obtained by edge detection into an accurate boundary circle through fitting method;
[0033] Each circle is defined by its center (a j , b j ) and radius R j definition;
[0034] Rough positioning helps improve the efficiency and robustness of edge finding, while fitting circles ensures the regularity of boundaries;
[0035] S5: Regional feature extraction and classification:
[0036] According to the precise circular boundary obtained by fitting, the lens area is divided into multiple independent annular sub-areas A j ;
[0037] Calculate each area A j Grayscale features and texture features. Based on the above features, a decision tree classifier is used to classify the area into bright ring area, frosted area, pure color area, lamp bead reflection area, etc.
[0038] S6: Generate segmentation result data containing precise circular boundary parameters and corresponding region category labels, and perform detection using conventional detection algorithms for different rules. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 This is the overall flow chart;
[0040] Figure 2 This is the flow chart of boundary detection and positioning;
[0041] Figure 3 This is the flow chart of feature extraction and region classification;
[0042] Figure 4 Schematic diagram of a specific detection embodiment. DETAILED DESCRIPTION
[0043] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0044] It should be noted that if the embodiments of the present invention involve directional indications (such as up, down, left, right, front, back, top, bottom, inside, outside, vertical, horizontal, longitudinal, counterclockwise, clockwise, circumferential, radial, axial...), then the directional indications are only used to explain the relative position relationship, movement status, etc. between the components in a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indications will also change accordingly.
[0045] In addition, if there are descriptions involving "first" or "second" in the embodiments of the present invention, the descriptions of "first" or "second" are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" or "second" may explicitly or implicitly include at least one of such features. In addition, the technical solutions between the various embodiments can be combined with each other, but this must be based on the fact that ordinary technicians in this field can implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0046] like Figures 1 to 4 As shown, a lens area segmentation and classification method for industrial visual quality inspection includes:
[0047] Polar coordinate analysis and two-stage segmentation strategy are used and feature classification is integrated.
[0048] The steps include:
[0049] S1: Image acquisition and lens positioning:
[0050] Obtain the front image I(x, y) of the lens and accurately determine the coordinates of the center of the lens area (x0, y0);
[0051] S2. Polar coordinate transformation:
[0052] S21: transform the lens area image centered at (x0, y0) from the Cartesian coordinate system (x, y) to the polar coordinate system,
[0053] S22: Get polar coordinate image L p (r, θ); where r is the radius and θ is the angle, and the annular structure characteristics of the image are obtained through transformation;
[0054] S3: Radial projection and rough boundary estimation:
[0055] Calculate the radial projection one-dimensional vector P(r),
[0056] S3 is performed by rotating the polar coordinate image L along the angle θ direction. p The pixel values of (r, θ) are summarized;
[0057] The obtained one-dimensional vector P(r) is subjected to median filtering to remove noise, and the filtered vector P is obtained. filtered (r);
[0058] After filtering, P filtered (r) setting one or more thresholds T,
[0059] By comparing P filtered The (r) value and the threshold are used to identify the rough radial position (radius value) of the boundary between different annular regions. k}Complete rough segmentation;
[0060] S4: Combined with rough boundary information {r k},
[0061] Using an accurate edge detection algorithm in Cartesian coordinates k} Find and locate the precise boundary point set between the annular areas near the edge detection; fit the boundary point coordinate set obtained by edge detection into an accurate boundary circle through fitting method;
[0062] Each circle is defined by its center (a j , b j ) and radius R j definition;
[0063] Rough positioning helps improve the efficiency and robustness of edge finding, while fitting circles ensures the regularity of boundaries;
[0064] S5: Regional feature extraction and classification:
[0065] According to the precise circular boundary obtained by fitting, the lens area is divided into multiple independent annular sub-areas A j ;
[0066] Calculate each area A j Grayscale features and texture features. Based on the above features, a decision tree classifier is used to classify the area into bright ring area, frosted area, pure color area, lamp bead reflection area, etc.
[0067] S6: Generate segmentation result data containing precise circular boundary parameters and corresponding region category labels, and perform detection using conventional detection algorithms for different rules.
[0068] Compared with the existing technology, the present invention brings the following significant advantages and beneficial effects through its unique technical solution combining polar coordinate analysis, two-stage segmentation and feature classification:
[0069] 1. Achieved automated and accurate region segmentation: This invention replaces the inefficient and inconsistent manual labeling method;
[0070] By utilizing polar coordinate transformation and radial projection analysis, combined with a coarse-to-fine two-stage boundary localization strategy, this method can effectively process the annular structures generated by the complex optical surface of the lens and accurately segment the boundaries of different regions, overcoming the limitations of conventional automated algorithms in accurately extracting boundaries. Fitting boundary points into circles ensures the regularity of the results, meeting the requirements of industrial applications.
[0071] 2. Automatic region classification capability: The present invention not only segments regions but also automatically identifies the category of each segmented region by extracting visual features such as grayscale and texture and using a decision tree classifier;
[0072] This solves the key problem that conventional segmentation algorithms cannot provide regional attribute information;
[0073] 3. Improved processing robustness: The radial projection calculation itself has a certain smoothing and suppressing effect on local image noise; the use of median filtering further enhances the resistance to noise;
[0074] The two-stage segmentation strategy also makes the method more adaptable to illumination changes and individual differences.
[0075] 4. Laying the foundation for differentiated detection: The core contribution of this invention is that the accurate segmentation results it outputs with category labels provide the necessary prerequisites for subsequent industrial visual quality inspection processes;
[0076] Based on the regional category information provided by the present invention, the detection system can automatically select the most suitable conventional detection algorithm for different areas and set corresponding detection parameters or thresholds, thereby achieving efficient and reliable differentiated detection and significantly improving the performance and accuracy of the overall quality inspection system.
[0077] Specifically, the above steps are subdivided and divided into multiple specific steps, including steps 1-
[0078] Step 1: Image acquisition and lens area positioning, including:
[0079] Use an industrial camera with a specified light source (multiple light sources, each with different lamp bead dimensions, one of which is used as an example) to obtain a front grayscale image I(x, y) of the lens assembly.
[0080] Use the Canny edge detection algorithm to perform edge detection, and manually select the circular edge contour of the detection product to obtain its center coordinates (x0, y0);
[0081] And create a shape-based template T accordingly basic , for use during testing.
[0082] Specifically, step 2: polar coordinate transformation, includes:
[0083] Taking the determined center (x0, y0) as the origin, transform the Cartesian coordinate image I(x, y) to the polar coordinate image I p (r, θ). For each polar coordinate grid point (r, θ), its corresponding Cartesian coordinate is:
[0084] x=x0+rcos(θ);
[0085] y=y0+r sin(θ);
[0086] Since the calculated (x, y) usually falls between the pixel grid points of the original image I (i.e., non-integer coordinates), we use bilinear interpolation to estimate the pixel value at that location;
[0087] Bilinear interpolation uses the four nearest integer polar coordinate image pixels around (x,y):
[0088] Q 11 =(x1, y1), Q 12 =(x1, y2), Q 21 =(x2, y1), Q 22 = grayscale value I(Q ij ) to calculate, where:
[0089] x1=|x|,y1=|y|;
[0090] x2=x1+1,y2=y1+1;
[0091] The interpolation calculation formula is as follows:
[0092] I interpolated (x,y)=I(Q 11 (x2-x)(y2-y)+I(Q 21 )(x-x1)(y2-y)+I(Q 12 )( x 2-x)(y-y1)+I(Q 22 )(x-x1)(y-y1);
[0093] The pixel value I calculated by bilinear interpolation interpolated(x, y) is assigned to the polar coordinate image pixel currently being processed:
[0094] I p (r, θ) = I interpolated (x, y);
[0095] After completing the traversal and interpolation calculation of all target polar coordinate points (r, θ),
[0096] Get the complete polar coordinate image I generated using bilinear interpolation p (r, θ).
[0097] Specifically, step 3: radial projection and rough boundary estimation includes:
[0098] Step 31: Calculate radial projection: Calculate the one-dimensional radial projection vector P(r). Here we mainly use the average grayscale projection, which is calculated by calculating the average grayscale of the pixel values at all angles θ on the circumference for each discrete radius value r:
[0099]
[0100] Among them, N r is the number of angular sampling points used for calculation at radius r;
[0101] Step 32: Filtering: Apply a one-dimensional median filter to the obtained one-dimensional vector P(r) to effectively remove the impulse noise. Assume that the window size of the filter is W m , then the filtered vector P filtered (r) is calculated as follows:
[0102]
[0103] That is, among all the P(j) values in the window centered at r, take the median as P filtered The value of (r).
[0104] Step 33: Rough boundary estimation: From the filtered P filtered (r) The peak-valley detection method is used to robustly extract feature points representing the region boundaries;
[0105] Find P filtered Local extreme point of (r);
[0106] The first and second order derivatives are calculated;
[0107] Let the first-order derivative be P′(r),
[0108] The second-order derivative is P″(r):
[0109]
[0110] P″(r)≈P filtered (r+1)-2P filtered (r)+P filtered (r-1).
[0111] Extreme points (potential boundaries r k ) usually appears near the zero crossing point of the first-order derivative (i.e., P′(r k )≈0 or P′(r) changes its sign at rk). Collect the radius positions of all detected local extreme points to form a rough boundary radius set r k The second-order derivative can be used to determine peaks and valleys, but this part is not used in this invention.
[0112] Specifically, step 4: precise boundary positioning and fitting includes:
[0113] Step 41: Guided edge detection: using a rough boundary radius r k Guide Canny edge detection;
[0114] For each r k , define a circular search area ROI in the Cartesian coordinate system k :
[0115]
[0116] Where δr is the preset search radius in ROI k Execute Canny edge detection algorithm internally;
[0117] According to P filtered (r k ) and the value of |P′(r k The size of )| is used to adaptively set the low threshold T of the Canny operator. low and high threshold T high , which can be expressed as:
[0118] T high =c1·P filtered (r k )+c2;
[0119] T low =α·T high ;
[0120] Where c1 and c2 are constants. c1 controls the sensitivity of the threshold to brightness changes, and c2 is a base threshold. α is the ratio of the lower threshold to the upper threshold, typically between 0.4 and 0.7 (satisfying 0 < α < 1).
[0121] Specifically, step 42: edge point extraction and screening:
[0122] Extract the edge of the ROI from the Canny edge detection algorithm k inner edge points;
[0123] The Canny algorithm can effectively remove short edges or pseudo edges generated by noise and obtain a set of continuous edge points E representing the annular boundary. k ={(x i ,y i )}. This step can be expressed as:
[0124] E k =Filter(Canny(I|ROI k , T low , T high ));
[0125] Step 43: Accurate circle fitting: For each edge point set E k Use the least squares method to fit the circle and get the center of the exact circle (a k , b k ) and radius R k :
[0126]
[0127] According to the fitting results, the center of the circle (a k , b k ) and radius R k , then the optimal circular boundary C k for:
[0128]
[0129] Specifically, step 5: regional feature extraction includes:
[0130] Step 51: Region definition: A series of precise circular boundaries C1, C2, ..., C obtained by fitting in step 4 N The circular boundary has a radius R k Sort from smallest to largest,
[0131] The lens image is divided into N independent sub-areas A1, A2, ..., A N ;
[0132] The innermost sub-area A1 is directly formed by the first circular boundary C1 with the smallest radius (center (a1, b1), radius R1).
[0133] Include all pixels inside the circle boundary:
[0134]
[0135] For the subsequent annular sub-area A j (where j = 2, 3, ..., N),
[0136] It is formed by the j-1th circle boundary C j-1 (center(a j-1 , b j-1 ), radius R j-1 ) and the j-th circle boundary C j (center(a j , b j ), radius R j )
[0137] This area contains all the j Inside and on circle C j-1 External points:
[0138]
[0139] Specifically, step 52: feature extraction: for each annular sub-region A j Calculate an eigenvector f j ;
[0140] Step 53: Grayscale feature: Calculate the average grayscale μ of the pixels in the area j and grayscale standard deviation σ j ;
[0141]
[0142] Where |A j | is area A j The number of pixels;
[0143] Step 54: Texture features: Calculate rotation-invariant uniform local binary patterns (Local Binary Patterns-LBP):
[0144] For region A j Each pixel (x c ,y c ):
[0145] Calculate the basic LBP value: for area A j Each pixel (x c ,y c ), first calculate its basic LBP P,R Consider the P neighboring pixels I(x p ,y p )(p=0-(P-1)) on a circle with a radius of R; compare the grayscale of the neighboring pixel with that of the center pixel I(x c ,yc ):
[0146] b p =s(I(x p ,y p )-I(x c ,y c )) for p=0,1,...,P-1;
[0147] Among them, s(z)=1 if z≥0, s(z)=0 if z<0;
[0148] Get a P-bit binary sequence (b0, b1, ..., b P-1 );
[0149] The corresponding decimal LBP value is:
[0150]
[0151] Step 55: Determine the uniform pattern: Calculate the binary sequence (b0, b1, ..., b P-1 ) in 0 / 1 or 1 / 0 transition times U:
[0152]
[0153] If U≤2, the LBP mode is a uniform mode;
[0154] Otherwise, it is a non-uniform pattern;
[0155] Calculate rotation-invariant uniform LBP values
[0156] If the pattern is uniform (U≤2);
[0157] For the uniform mode, The value is the number of 1s in its P-bit binary representation:
[0158]
[0159] If the pattern is non-uniform (U>2);
[0160] All non-uniform patterns are grouped into a separate special category. The value of this category is set to be larger than the values of all uniform patterns. For example, for P=8, the values of uniform patterns are 0 to 8 (a total of 9), and the value of non-uniform patterns can be set to 9.
[0161]
[0162] Calculate LBP histogram: Statistical area A jCalculated from all pixels within The distribution of mode values, the normalized LBP histogram H LBP,j , whose dimension is P+2.
[0163]
[0164] Calculate LBP histogram entropy: LBP histogram H LBP,j The entropy of the region is taken as the single texture feature value E LBP,j .
[0165]
[0166] Where 0 log2 0=0.
[0167] Specifically, feature vector construction and normalization include:
[0168] Combine the calculated grayscale features and LBP histogram entropy into region A j The original eigenvector f j :f j =[μ j ,σ j ,E LBP,j ];
[0169] Normalization: the original feature vector f j Perform Z-score standardization to obtain the normalized feature vector f′ j ;
[0170]
[0171] Where dim=1, 2, 3 correspond to μ respectively. j , σ j , E LBP,j , and are the mean and standard deviation of the feature over the entire training set.
[0172] Specifically, step 6: region classification based on decision tree includes:
[0173] Each sub-region A extracted and normalized according to step 5 j The eigenvector f′ j =[μ′ j ,σ′ j ,E′ LBP,j ];
[0174] Each area A jClassify into one of the predefined categories, including: pure color area, frosted area, bright ring area, lamp bead reflection area (and other areas with image features and different detection methods).
[0175] Step 61: Decision tree model training includes:
[0176] Prepare training set: A pre-labeled training dataset is required where f′ i is the feature vector extracted and normalized from the i-th training sample region, L i ∈{pure color area, frosted area, bright ring area, lamp bead reflection area,...} is the corresponding true category label;
[0177] Step 62: Build a Decision Tree Model: Using the Training Dataset and normalized features f′ i To build a decision tree model; using the CART algorithm, the decision tree structure is constructed by recursively selecting the optimal features and the optimal splitting threshold;
[0178] A trained decision tree model T is obtained, wherein the leaf nodes thereof contain expanded category labels, wherein the category labels include a pure color area, a frosted area, a bright ring area, and a lamp bead reflection area;
[0179] Step 63: Classification prediction:
[0180] For each area A to be classified j and its normalized eigenvector f′ j :
[0181] f′ j Use the trained decision tree to classify and get the result label L j ;
[0182] L j =DecisionTreeClassify(f′ j , T);
[0183] Step 7: Results integration and testing process, including:
[0184] Step 71: Output structured data: The final output of the method of the present invention is a structured data set, which contains all the key information obtained by analyzing the input lens image. j (j=1 to N), the output data includes:
[0185] Step 72: Region identification: a unique identifier j;
[0186] Step 73: Boundary information: define the precise circular boundary parameters of the area;
[0187] Step 74: Region category label: category L predicted by the decision tree classifier j .
[0188] The region information with precise boundaries and category labels output by this invention is the key to achieving intelligent and differentiated defect detection. After receiving this structured data, the subsequent defect detection system performs the following operations:
[0189] 1. Region positioning: Use boundary information to accurately locate each region A on the image j .
[0190] 2. Strategy selection: According to the regional category label L j , select the conventional detection algorithm that is most suitable for detecting surface defects in this type of area from the preset algorithm library.
[0191] 3. Parameter configuration: Configure the optimized parameters for the selected detection algorithm for the region category.
[0192] 4. Perform detection: in area A j The selected detection algorithm is executed within.
[0193] The above description is only a preferred embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structural transformation made by using the contents of the present invention specification and drawings under the inventive concept of the present invention, or directly / indirectly applied in other related technical fields, is included in the patent protection scope of the present invention.
Claims
1. A method for lens area segmentation and classification in industrial visual quality inspection, characterized in that: include, Polar coordinate analysis and two-stage segmentation strategy are used and feature classification is integrated. The steps include: S1: Image acquisition and lens positioning: Obtain the front image I(x, y) of the lens and accurately determine the coordinates of the center of the lens area (x0, y0); S2. Polar coordinate transformation: S21: transform the lens area image centered at (x0, y0) from the Cartesian coordinate system (x, y) to the polar coordinate system, S22: Get polar coordinate image I p (r, θ); where r is the radius and θ is the angle, and the annular structure characteristics of the image are obtained through transformation; S3: Radial projection and rough boundary estimation: Calculate the radial projection one-dimensional vector P(r), S3 is performed by rotating the polar coordinate image I along the angle θ direction. p The pixel values of (r, θ) are summarized; The obtained one-dimensional vector P(r) is subjected to median filtering to remove noise, and the filtered vector P is obtained. filtered (r); After filtering, P filtered (r) setting one or more thresholds T, By comparing P filtered The (r) value and the threshold are used to identify the rough radial position (radius value) of the boundary between different annular regions. k }Complete rough segmentation; S4: Combined with rough boundary information {r k }, Using an accurate edge detection algorithm in Cartesian coordinates k } Find and locate the precise boundary point set between the annular areas near the edge detection; fit the boundary point coordinate set obtained by edge detection into an accurate boundary circle through fitting method; Each circle is defined by its center (a j , b j ) and radius R j definition; Rough positioning helps improve the efficiency and robustness of edge finding, while fitting circles ensures the regularity of boundaries; S5: Regional feature extraction and classification: According to the precise circular boundary obtained by fitting, the lens area is divided into multiple independent annular sub-areas A j ; Calculate each area A j Grayscale features and texture features. Based on the above features, a decision tree classifier is used to classify the area into bright ring area, frosted area, pure color area, lamp bead reflection area, etc. S6: Generate segmentation result data containing precise circular boundary parameters and corresponding region category labels, and perform detection using conventional detection algorithms for different rules.
2. The method for lens region segmentation and classification in industrial visual quality inspection according to claim 1, wherein: Step 1: Image acquisition and lens area positioning, including: Use an industrial camera with a specified light source to obtain a front grayscale image I(x, y) of the lens assembly; Use the Canny edge detection algorithm to perform edge detection, and manually select the circular edge contour of the detection product to obtain its center coordinates (x0, y0); And create a shape-based template T accordingly basic , for use during testing.
3. The method for lens region segmentation and classification in industrial visual quality inspection according to claim 2, wherein: Step 2: Polar coordinate transformation, including: Taking the determined center (x0, y0) as the origin, transform the Cartesian coordinate image I(x, y) to the polar coordinate image I p (r,θ); for each polar coordinate grid point (r,θ), its corresponding Cartesian coordinate is: x=x0+rcos(θ); y=y0+rsin(θ); Since the calculated (x, y) usually falls between the pixel grid points of the original image I (i.e., non-integer coordinates), we use bilinear interpolation to estimate the pixel value at that location; Bilinear interpolation uses the four nearest integer polar coordinate image pixels around (x,y): Q 11 =(x1, y1), Q 12 =(x1, y2), Q 21 =(x2, y1), Q 22 = grayscale value I(Q ij ) to calculate, where: x1=|x|,y1=|y|; x2=x1+1,y2=y1+1; The interpolation calculation formula is as follows: I interpolated (x,y)=I(Q 11 )(x2-x)(y2-y)+I(Q 21 )(x-x1)(y2-y)+I(Q 12 )(x2-x)(y-y1)+I(Q 22 )x-x1)(y-y1); The pixel value I calculated by bilinear interpolation interpolated (x, y) is assigned to the polar coordinate image pixel currently being processed: I p (r,θ)=I interpolated (x,y); After completing the traversal and interpolation calculation of all target polar coordinate points (r,θ), Get the complete polar coordinate image I generated using bilinear interpolation p (r, θ).
4. The method for lens region segmentation and classification in industrial visual quality inspection according to claim 3, wherein: Step 3: Radial projection and rough boundary estimation, including: Step 31: Calculate radial projection: Calculate the one-dimensional radial projection vector P(r). Here we mainly use the average grayscale projection, which is calculated by calculating the average grayscale of the pixel values at all angles θ on the circumference for each discrete radius value r: Among them, N r is the number of angular sampling points used for calculation at radius r; Step 32: Filtering: Apply a one-dimensional median filter to the obtained one-dimensional vector P(r) to effectively remove the impulse noise; let the filter window size be W m , then the filtered vector P filtered (r) is calculated as follows: That is, among all the P(j) values in the window centered at r, take the median as P filtered The value of (r); Step 33: Rough boundary estimation: From the filtered P filtered (r) The peak-valley detection method is used to robustly extract feature points representing the region boundaries; Find P filtered Local extreme point of (r); The first and second order derivatives are calculated; Let the first-order derivative be P′(r), The second-order derivative is P″(r): P″(r)≈P filtered (r+1)-2P filtered (r)+P filtered (r-1)。 5. The method for lens region segmentation and classification in industrial visual quality inspection according to claim 4, wherein: Step 4: Accurate boundary positioning and fitting, including: Step 41: Guided edge detection: using a rough boundary radius r k Guide Canny edge detection; For each r k , define a circular search area ROI in the Cartesian coordinate system k : Where δr is the preset search radius in ROI k Execute the Canny edge detection algorithm internally; According to P filtered (rk) and the value of |P′(r k The size of )| is used to adaptively set the low threshold T of the Canny operator. low and high threshold T high , which can be expressed as: T high =c1·P filtered (r k )+c2; T low =α·T high ; Among them, c1 and c2 are constants. c1 controls the sensitivity of the threshold to changes in brightness, and c2 is a basic threshold. α is the proportional coefficient between the low threshold and the high threshold, which is usually between 0.4 and 0.7, satisfying 0<α<1.
6. The method for lens region segmentation and classification in industrial visual quality inspection according to claim 5, wherein: Step 42: Edge point extraction and screening: Extract the edge of the ROI from the Canny edge detection algorithm k inner edge points; The Canny algorithm can effectively remove short edges or pseudo edges generated by noise and obtain a set of continuous edge points E representing the annular boundary. k ={(x i ,y i )}; This step can be expressed as: Step 43: Accurate circle fitting: For each edge point set E k Use the least squares method to fit the circle and get the center of the exact circle (a k , b k ) and radius R k : According to the fitting results, the center of the circle (a k , b k ) and radius R k , then the optimal circular boundary C k for:
7. The method for lens region segmentation and classification in industrial visual quality inspection according to claim 6, wherein: Step 5: Regional feature extraction, including: Step 51: Region definition: A series of precise circular boundaries C1, C2, ..., C obtained by fitting in step 4 N The circular boundary has a radius R k Sort from smallest to largest, The lens image is divided into N independent sub-areas A1, A2, ..., A N ; The innermost sub-area A1 is directly formed by the first circular boundary C1 with the smallest radius (center (a1, b1), radius R1). Include all pixels inside the circle boundary: For the subsequent annular sub-area A j (where j = 2, 3, ..., N), It is formed by the j-1th circle boundary C j-1 (center(a j-1 , b j-1 ), radius R j-1 ) and the j-th circle boundary C j (center(a j , b j ), radius R j ) This area contains all the j Inside and on circle C j-1 External points:
8. The method for lens region segmentation and classification in industrial visual quality inspection according to claim 7, wherein: Step 52: Feature extraction: For each annular sub-region A j Calculate an eigenvector f j ; Step 53: Grayscale Features: Calculate the average grayscale μ of the pixels in the area j and grayscale standard deviation σ j ; Where |A j | is area A j The number of pixels; Step 54: Texture features: Calculate rotation-invariant uniform local binary patterns (Local Binary Patterns-LBP): For region A j Each pixel (x c ,y c ): Calculate the basic LBP value: for area A j Each pixel (x c ,y c ), first calculate its basic LBP P,R Value; Consider the P neighboring pixels I(x p ,y p )=(p=0-(P-1)) on a circle with a radius of R; compare the grayscale of the neighborhood and the center pixel I(x c ,y c ): b p =s(I(x p ,y p )-I(x c ,y c ))for p=0,1,...,P-1; Where s(z)=1if z≥0, s(z)=0if z<0; Get a P-bit binary sequence (b0, b1, ..., b P-1 ); The corresponding decimal LBP value is: Step 55: Determine the uniform pattern: Calculate the binary sequence (b0, b1, ..., b P-1 ) in 0 / 1 or 1 / 0 transition times U: If U≤2, the LBP mode is a uniform mode; Otherwise, it is a non-uniform pattern; Calculate rotation-invariant uniform LBP values If the pattern is uniform (U≤2); For the uniform mode, The value is the number of 1s in its P-bit binary representation: If the pattern is non-uniform (U>2); grouping all non-uniform patterns into a separate special category; The value of this category is set to be larger than the value of all uniform modes.
9. The method for lens region segmentation and classification in industrial visual quality inspection according to claim 8, wherein: Feature vector construction and normalization, including: Combine the calculated grayscale features and LBP histogram entropy into region A j The original eigenvector f j : f j =[μ j ,s j ,E LBP,j ]; Normalization: the original feature vector f j Perform Z-score standardization to obtain the normalized feature vector f′ j ; Where dim=1, 2, 3 correspond to μ respectively. j , σ j , E LBP,j , and are the mean and standard deviation of the feature over the entire training set.
10. The method for lens region segmentation and classification in industrial visual quality inspection according to claim 9, wherein: Step 6: Region classification based on decision tree, including: Each sub-region A extracted and normalized according to step 5 j The eigenvector f′ j =[μ′ j ,σ′ j , E′ LBP,j ]; Each area A j Classification into one of the predefined categories, including: solid color area, frosted area, bright ring area, and lamp bead reflection area; Step 61: Decision tree model training includes: Prepare training set: A pre-labeled training dataset is required where f′ i is the feature vector extracted and normalized from the i-th training sample region, L i ∈{pure color area, frosted area, bright ring area, lamp bead reflection area,...} is the corresponding true category label; Step 62: Build a Decision Tree Model: Using the Training Dataset and normalized features f′ i To build a decision tree model; using the CART algorithm, the decision tree structure is constructed by recursively selecting the optimal features and the optimal splitting threshold: A trained decision tree model T is obtained, wherein the leaf nodes thereof contain expanded category labels, wherein the category labels include a pure color area, a frosted area, a bright ring area, and a lamp bead reflection area; Step 63: Classification prediction: For each area A to be classified j and its normalized eigenvector f′ j : f′ j Use the trained decision tree to classify and get the result label L j ; L j =DecisionTreeClassify(f′ j ,T); Step 7: Results integration and testing process, including: Step 71: Output structured data: The final output of the method of the present invention is a structured data set, which contains all the key information obtained by analyzing the input lens image; for each detected sub-area A j (j=1 to N), the output data includes: Step 72: Region identification: a unique identifier j; Step 73: Boundary information: define the precise circular boundary parameters of the area; Step 74: Region category label: category L predicted by the decision tree classifier j .