Microlens automatic detection method and system
By preprocessing and rotating the microlens stripe image, combined with differential detection of block and interval regions, the problem of segmentation and localization of microlens defects in stripe background is solved, and automated defect detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN QIANHAI YUZHUO TECH CO LTD
- Filing Date
- 2026-01-16
- Publication Date
- 2026-05-01
AI Technical Summary
In the existing technology, it is difficult to reliably identify defects such as scratches and stains under striped structured light illumination by microlenses, especially when defect segmentation and localization are difficult under conditions of striped background interference and uneven brightness.
By performing preprocessing, rotation correction, segmentation, and differential detection on stripe images, including Gaussian smoothing, histogram equalization, gamma correction, rotation correction, connected component analysis, mask generation, and morphological operations, automatic identification and labeling of defects can be achieved.
It effectively reduces the impact of stripe tilt on detection, improves the separability of defects and the integrity of detection results, and reduces the burden of manual re-inspection.
Smart Images

Figure CN121962073A_ABST
Abstract
Description
An automatic detection method and system for microlenses Technical Field
[0001] This invention relates to the field of microlens detection technology, and in particular to an automatic microlens detection method and system. Background Technology
[0002] Microlenses often present challenges in appearance quality inspection due to their low contrast and difficulty in imaging transparent or semi-transparent defects. Current inspection techniques primarily rely on manual visual inspection. To improve defect visibility in products with low contrast and difficult-to-image transparent or semi-transparent defects, existing technologies employ striped structured light illumination to enhance the visibility of transparent defects, thereby introducing a regular striped background texture into the image of the tested part. However, in industrial online inspection scenarios, images acquired by the inspection system may naturally exhibit a striped block background structure: the image contains areas with obvious stripes and areas without stripes. The latter can appear as hash-like, stripe-free intervals. Striped areas and stripe-free intervals form block areas and interval areas, respectively, and the intervals exhibit a relatively stable geometric pattern within the sample. These imaging characteristics lead to the superposition of defects with striped textures and uneven brightness, further increasing the difficulty of defect segmentation and localization.
[0003] For the detection images with striped background features, especially the striped pattern detection scenario that can be formed by striped structured light, there is still a need for an automatic detection method that can stably identify defects such as scratches and stains under striped interference and uneven brightness conditions. Summary of the Invention
[0004] In view of the above technical problems, the present invention provides an automatic microlens detection method and system. It addresses the problems of insufficient contrast between defects and background, and difficulty in stable segmentation and localization of defects caused by stripe background texture interference, uneven brightness, and stripe direction deviation, which are obtained by microlenses under stripe structure illumination and have stripe background features. By correcting the stripe direction and dividing the image into block regions and interval regions for differential detection, the method achieves automatic identification and marking output of defects.
[0005] Other features and advantages of the invention will become apparent from the following detailed description, or may be learned in part by practice of the invention.
[0006] According to one aspect of the present invention, an automatic microlens detection method is proposed, the method comprising: acquiring a stripe image to be detected, the stripe image being an image of a microlens under stripe structure illumination; preprocessing the stripe image to suppress brightness unevenness and enhance the contrast between the stripe background and defects, obtaining a preprocessed image with a block region as the foreground; determining a rotation angle based on the boundary features of a reference block region in the preprocessed image, and performing rotation correction on the stripe image accordingly, aligning the stripe direction of the stripe background with the image row direction, obtaining a rotated image; segmenting the rotated image, and determining a bounding box for each block region of the rotated image based on identified connected block regions; generating a block mask according to each bounding box, and obtaining a gap mask by complementing the block mask, thereby obtaining a block image and a gap image; in the block image In the image, block defect detection is performed by dividing each block region into multiple sub-segments along the stripe direction. For each sub-segment, the pixel grayscale sequence is extracted row by row, and the median is calculated. The median is used to replace the pixel grayscale of the corresponding row in the sub-segment to generate a block reference image. The block reference image and the block image are subtracted and binarized to obtain block defect candidates. Abnormal regions that do not meet the median replacement requirement are independently binarized and then incorporated into the block defect candidates. In the interval image, interval defect detection is performed by superimposing the interval image with the block mask to highlight abnormal connected components in the interval. Morphological closing operation is performed on the superimposed result to suppress line noise caused by incompletely aligned stripes. Binarization and image inversion are then performed to obtain interval defect candidates. The block defect candidates and the interval defect candidates are spatially superimposed to output a detection result image containing defect markers.
[0007] Furthermore, the preprocessing specifically includes: performing Gaussian smoothing on the striped image to reduce random noise while maintaining the main structure of the striped background; performing histogram equalization on the smoothed image to expand the gray-level distribution and reduce the local brightness difference caused by non-uniform illumination; performing gamma correction on the equalized image to improve the gray-level difference between the defects and the striped background through nonlinear gray-level mapping; performing binarization on the image after gamma correction to form a binary image, and performing image inversion on the binary image so that the block region is represented as foreground pixels and the interval region is represented as background pixels in the preprocessed image.
[0008] Furthermore, determining the rotation angle specifically includes: selecting a reference block region located at a predetermined position in the preprocessed image, wherein the reference block region is a block region located in the middle of the image or satisfying predetermined geometric constraints; extracting a set of contour points from the reference block region; fitting the minimum bounding rectangle surrounding the reference block region based on the set of contour points, and determining the rotation angle by the angle between the side of the minimum bounding rectangle and the image row direction; performing rotational resampling on the striped image using a geometric transformation with the rotation angle as a parameter, so that the stripe direction of the striped background is approximately parallel to the image row direction.
[0009] Furthermore, the acquisition of the block image and the interval image specifically includes: performing connected component analysis on the rotated image to obtain multiple connected block regions; generating an outer bounding box for each block region; when a defect causes the boundary of the outer bounding box to shift, sampling and statistically analyzing the foreground extreme coordinates of the block region on multiple scan rows and multiple scan columns, and using the median of the foreground extreme coordinates as the position of the corresponding boundary to perform robust correction on the outer bounding box, wherein the foreground extreme coordinates include the leftmost foreground pixel coordinate, the rightmost foreground pixel coordinate, and the median of the foreground extreme coordinates on each scan row. The coordinates of the topmost foreground pixel and the bottommost foreground pixel on each scan column; when multiple block regions are arranged in a predetermined array and the inter-block spacing is constant in the sample set, the block mask is generated based on the corrected bounding box and the inter-block spacing; the block mask is applied as a masking matrix to the rotated image to obtain the block image containing only the pixels of the block regions, and the spacing mask is obtained by taking the complement of the block mask, and the spacing mask is applied to the rotated image to obtain the spacing image containing only the pixels of the spacing regions, so as to achieve synchronous separation of the block image and the spacing image.
[0010] Furthermore, when dividing the block region into multiple sub-segments along the stripe direction, the method includes: setting a segment scale parameter in the direction perpendicular to the stripe direction of the block region, and dividing the block region into multiple adjacent sub-segments according to the segment scale parameter; when performing row median replacement on the sub-segments, the method specifically includes: for each image row in the sub-segment, extracting the pixel grayscale sequence of the image row in the sub-segment, calculating the median of the pixel grayscale sequence, and uniformly replacing the grayscale of each pixel in the image row in the sub-segment with the median; after performing row median replacement on each sub-segment, stitching the replacement results corresponding to each sub-segment together according to their spatial positions to form the block reference image.
[0011] Furthermore, performing the independent binarization detection on the abnormal region includes: determining the candidate position of the abnormal region in the block reference image based on grayscale difference or abnormal pixel ratio, wherein the abnormal pixel ratio is obtained by comparing the ratio of the number of pixels in a certain image row that meet the abnormal grayscale condition to the total number of pixels in the sub-segment; when the abnormal pixel ratio exceeds a preset ratio threshold, determining the region corresponding to the candidate position as the abnormal region; performing binarization processing on the abnormal region in the block reference image to extract the connected components of the abnormal region, and incorporating the connected components into the block defect candidate.
[0012] Furthermore, when performing difference and binarization on the block reference image and the block image, the specific steps include: calculating a first difference image obtained by subtracting the block reference image from the block image, and binarizing the first difference image using a block difference threshold to obtain defect pixels with high grayscale difference compared to the background; calculating a second difference image obtained by subtracting the block image from the block reference image, and binarizing the second difference image using the block difference threshold to obtain defect pixels with low grayscale difference compared to the background; taking the union of the binarization results of the first difference image and the binarization results of the second difference image to obtain the block defect candidate that simultaneously covers bright defects and dark defects, wherein the bright defects and the dark defects include at least one of scratches and stains.
[0013] Furthermore, when performing interval defect detection in the interval image, the process specifically includes: performing interval binarization processing on the interval image to obtain an initial interval binary image; superimposing the block mask on the initial interval binary image to form an intermediate result image containing defects and line noise, wherein the line noise is formed in the interval region by the striped background when there is residual deviation in rotation correction; performing a morphological closing operation on the intermediate result image to suppress the line noise and enhance defect connectivity; binarizing the processing result after the closing operation and performing image inversion to obtain the interval defect candidate.
[0014] According to another aspect of the present invention, an automatic microlens detection system is provided, comprising: an acquisition module for acquiring a stripe image to be detected, the stripe image being an image of a microlens under stripe structure illumination; a preprocessing module for preprocessing the stripe image to suppress brightness unevenness and enhance the contrast between the stripe background and defects, obtaining a preprocessed image with a block region as the foreground; a correction module for determining a rotation angle based on the boundary features of a reference block region in the preprocessed image, and performing rotation correction on the stripe image accordingly, aligning the stripe direction of the stripe background with the image row direction, thereby obtaining a rotated image; a segmentation module for segmenting the rotated image, determining a bounding box for each block region of the rotated image based on identified connected block regions; generating a block mask according to each bounding box, and obtaining a gap mask by complementing the block mask, thereby obtaining a block image and a gap image; and a block region defect detection module. The system is used to perform block defect detection in the block image, divide each block region into multiple sub-segments along the stripe direction, extract pixel grayscale sequences row by row for each sub-segment and calculate the median, replace the pixel grayscale of the corresponding row in the sub-segment with the median, and generate a block reference image; perform difference and binarization on the block reference image and the block image to obtain block defect candidates, and perform independent binarization detection on abnormal regions that do not meet the median replacement and then incorporate them into the block defect candidates; the interval region defect detection module is used to perform interval defect detection in the interval image, superimpose the interval image with the block mask to highlight abnormal connected components in the interval, perform morphological closing operation on the superposition result to suppress line noise generated by incompletely aligned stripes, and perform binarization and image inversion to obtain interval defect candidates; the fusion output module is used to spatially superimpose the block defect candidates and the interval defect candidates to output a detection result image containing defect markers.
[0015] The technical solution of this invention has the following beneficial effects: By smoothing, brightness equalizing, contrast enhancing, and foregrounding the striped image into block regions, the boundary features of the reference block region are made more stable, thereby reliably determining the rotation angle and correcting the stripe direction to align with the image row direction, satisfying the premise of "relatively consistent gray levels in the same row" in subsequent row-by-row statistical processing, and reducing the impact of stripe tilt on defect detection; by generating circumscribed bounding boxes based on connected components and constructing block masks and interval masks, the rotated image is separated into block images and interval images, allowing the striped block background and interval regions to enter different processing links, avoiding false detections caused by a single detection strategy simultaneously considering both types of regions; along the stripes in the block image The system segments the image by direction and calculates the median for each segment row to replace the generated block reference image. It then differs from and binarizes the block image, enabling the simultaneous extraction of bright and dark defects. Independent binarization detection is introduced for abnormal regions where median replacement is not applicable, improving the adaptability to stains or large-area anomalies. In the interval image, abnormal connected regions are highlighted by superimposing with the block mask, and morphological closing operations are used to suppress linear noise introduced by rotational residual bias. Binarization and inversion are then used to obtain interval defect candidates, thereby improving the segmentability of defects in interval regions. Finally, the block defect candidates and interval defect candidates are fused and output to achieve unified labeling of defects in the entire image, improving the integrity of the detection results and reducing the burden of manual re-inspection. Attached Figure Description
[0016] Figure 1 is a flowchart of an automatic microlens detection method according to an embodiment of this specification; Figure 2 is a schematic diagram of the block region spacing according to an embodiment of this specification; Figure 3 is a schematic diagram of the bounding box spacing according to an embodiment of this specification; Figure 4 is a schematic diagram of the block mask according to an embodiment of this specification; Figure 5 is a schematic diagram of the block mask applied to a striped image according to an embodiment of this specification; Figure 6 is a schematic diagram of the interval mask according to an embodiment of this specification; Figure 7 is a structural block diagram of an automatic microlens detection system according to an embodiment of this specification; Figure 8 is a terminal device for implementing the automatic microlens detection method according to an embodiment of this specification; Figure 9 is a computer-readable storage medium storing the automatic microlens detection method according to an embodiment of this specification. Detailed Implementation
[0017] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, they are provided to make the invention more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art. The described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a full understanding of embodiments of the invention. However, those skilled in the art will recognize that the technical solutions of the invention may be practiced with one or more of these specific details omitted, or other methods, components, systems, steps, etc., may be employed. In other instances, well-known technical solutions are not shown or described in detail to avoid obscuring various aspects of the invention.
[0018] Furthermore, the accompanying drawings are merely illustrative of the invention. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor systems and / or microcontroller systems.
[0019] This invention provides an automatic microlens detection method. Referring to Figure 1, a flowchart illustrating an embodiment of the automatic microlens detection method provided by this invention is shown. This method can be applied to electronic devices such as personal computers and servers. The method can be executed by a system, which can be implemented by software and / or hardware. Specifically, the method may include the following steps S101-S107: In step S101, a stripe image to be detected is acquired, wherein the stripe image is an image of the microlens under stripe structure illumination.
[0020] The key feature of striped images is the presence of distinct parallel stripes in the background. This type of striped background can be formed by evenly spaced parallel light stripes, making defects more easily visible against the striped background. During acquisition, the image content should typically cover the inspected area and completely contain the stripe distribution, ensuring that the stripes are continuous, regular, and have stable spacing throughout the entire image. This guarantees that subsequent detection can use the stripes as a background reference for comparison and localization.
[0021] Striped images can be acquired in grayscale format, such as using an 8-bit grayscale image. In such images, the striped background features are obvious, and defects can appear as scratches or stains, and both may appear simultaneously in the same image. Furthermore, the striped background is not necessarily uniformly distributed across the entire image; there may be areas without stripes, which structurally alternate with the striped areas. The striped and non-striped areas form a relatively fixed spatial layout, providing a basis for subsequent detection. Therefore, the striped image acquired in S101 should not only reflect the striped background itself but also ensure, as far as possible, that the overall structure of the striped and non-striped areas remains consistent across different samples (e.g., constant interval size, variable striped area size but stable layout pattern), so that subsequent processing can operate stably on the same type of image structure.
[0022] The realization of striped structured illumination can include two cases: self-generation and external light source illumination. First, a display device with light-emitting capability is used as the generation end of the striped structured light. The striped pattern is output on the display device, and then a microlens is placed in the light output path of the display device, so that the striped light passes through or is modulated by the microlens and then collected by the imaging device. In this case, the stripes come from the light output of the display device itself. Second, an external striped light source or projection device is used to apply striped structured illumination to the microlens. For example, uniformly spaced parallel light stripes are projected onto the surface of the microlens or into the transmission path, and then the imaging device collects the striped image.
[0023] In step S102, the striped image is preprocessed to suppress uneven brightness and enhance the contrast between the striped background and the defects, thereby obtaining a preprocessed image with the block area as the foreground.
[0024] Specifically, the preprocessing includes: performing Gaussian smoothing on the striped image to reduce random noise while maintaining the main structure of the striped background; performing histogram equalization on the smoothed image to expand the gray-level distribution and reduce the local brightness difference caused by non-uniform illumination; performing gamma correction on the equalized image to improve the gray-level difference between the defects and the striped background through non-linear gray-level mapping; performing binarization on the image after gamma correction to form a binary image, and performing image inversion on the binary image so that the block region is represented as foreground pixels and the interval region is represented as background pixels in the preprocessed image.
[0025] The purpose of step S102 is to create more stable grayscale conditions for subsequent row-by-row processing. To effectively utilize one-dimensional median filtering, the grayscale of each row in the image needs to be as consistent as possible. Therefore, preprocessing is required to reduce intra-row grayscale fluctuations caused by random noise and non-uniform illumination, and to provide a clearer, more regular structural basis for aligning the stripes horizontally. This preprocessing process sequentially includes Gaussian smoothing, histogram equalization, gamma correction, binarization, and image inversion.
[0026] In practice, Gaussian smoothing is first applied to the striped image to suppress random noise introduced during the imaging process while preserving the main structural morphology of the striped background as much as possible, thus preventing noise from being amplified in subsequent enhancement or thresholding stages. Then, histogram equalization is applied to the smoothed image to reduce local brightness differences caused by uneven brightness distribution, making the gray-level distribution of different areas more balanced, thereby reducing background fluctuations caused by uneven illumination. After completing brightness equalization, gamma correction is performed to enhance contrast. Nonlinear gray-level mapping widens the gray-level difference between the defect and the striped background, making the defect more prominent both visually and computationally, which is convenient for subsequent structure extraction and defect localization.
[0027] After the above enhancements are performed, the gamma-corrected image is binarized to form a binary image. Then, the binary image is inverted, causing the block regions to appear as foreground pixels and the non-block regions as background pixels in the preprocessed image, thus obtaining a preprocessed image with foregrounded block regions. The value of this foregrounding result lies in two aspects: firstly, the separation between the block regions and the background is clearer, facilitating the stable extraction of structural information such as the boundaries and vertices of the reference block regions; secondly, it provides more reliable input for subsequent connected component recognition, bounding box determination, and mask construction.
[0028] In step S103, the rotation angle is determined based on the boundary features of the reference block region in the preprocessed image, and the striped image is rotated and corrected accordingly to align the stripe direction of the striped background with the image row direction, thereby obtaining a rotated image.
[0029] Specifically, determining the rotation angle includes: selecting a reference block region located at a predetermined position in the preprocessed image, wherein the reference block region is a block region located in the middle of the image or satisfying predetermined geometric constraints; extracting a set of contour points from the reference block region; fitting the minimum bounding rectangle surrounding the reference block region based on the set of contour points, and determining the rotation angle by the angle between the side of the minimum bounding rectangle and the image row direction; and performing rotational resampling on the striped image using a geometric transformation with the rotation angle as a parameter, so that the stripe direction of the striped background is approximately parallel to the image row direction.
[0030] Step S103 is used to determine the skewness of the stripe direction and complete the horizontal alignment rotation correction. The rationale is that, in order to effectively use one-dimensional median filtering, the grayscale of each row in the image needs to be as consistent as possible. Therefore, preprocessing and image rotation are needed to horizontally align the stripes in the image, making the stripe direction consistent with the image row direction, thus creating conditions for subsequent row-by-row processing. In specific implementation, the preprocessed result makes the block region more structurally prominent, facilitating the extraction of stable geometric elements for angle estimation from the block region. A reference block region located at a predetermined position is selected, typically a block region in the middle of the image or a block region satisfying predetermined geometric constraints, to reduce the interference of edge clipping, lighting gradients, or local defects on geometric estimation, making the angle estimation more stable.
[0031] In determining the rotation angle, a set of contour points can be extracted based on the reference block region, and boundary features reflecting the overall orientation of the block region can be obtained from the contour point set. The preprocessed block region is in the foreground, and the boundary of the reference block region is more likely to form a closed contour. The contour point set can be obtained by tracing the boundaries of connected regions. Based on this, the minimum bounding rectangle enclosing the reference block region can be fitted to the contour point set. The direction of any principal side of this minimum bounding rectangle represents the overall tilt direction of the block region, and the angle between this principal side direction and the image row direction is calculated as the rotation angle. This approach is consistent with the description of "determining the rotation angle using the vertices of the middle block in the processed image": the rotation angle can be obtained through the vertex / boundary direction of the middle block, allowing the stripes to be rotated to the horizontal direction. To improve robustness, the angle can be selected based on the long side direction of the bounding rectangle or the consistency of multiple boundary directions, avoiding mistaking the short side direction as the stripe direction. When there are slight jagged edges or defects on the boundary, the contour point set can be moderately smoothed or a robust fitting can be used to obtain a more stable bounding rectangle orientation, thereby improving the anti-interference capability of the angle calculation.
[0032] After determining the rotation angle, a geometric transformation is performed on the stripe image using this rotation angle as a parameter to achieve rotational resampling and coordinate alignment, making the stripe direction approximately parallel to the image row direction. During rotational resampling, interpolation can be used to reconstruct the grayscale, and blank areas appearing after rotation can be filled with boundary or background to maintain the consistency of image size and coordinate system, facilitating subsequent steps to perform segmentation and defect localization in the same coordinate system.
[0033] In step S104, the rotated image is segmented, and based on the identified connected block regions, a bounding box is determined for each block region of the rotated image; a block mask is generated according to each bounding box, and the block mask is complemented to obtain a gap mask, thereby obtaining the block image and the gap image.
[0034] Specifically, step S104 includes: performing connected component analysis on the rotated image to obtain multiple connected block regions; generating an outer bounding box for each block region; when a defect causes the boundary of the outer bounding box to shift, sampling and statistically analyzing the foreground extreme coordinates of the block region on multiple scan rows and multiple scan columns, and using the median of the foreground extreme coordinates as the position of the corresponding boundary to perform robust correction on the outer bounding box, wherein the foreground extreme coordinates include the leftmost foreground pixel coordinate and the rightmost foreground pixel coordinate on each scan row, and the topmost foreground pixel coordinate and the bottommost foreground pixel coordinate on each scan column; when multiple block regions are arranged in a predetermined array and the inter-block interval is constant in the sample set, generating the block mask based on the corrected outer bounding box and the inter-block interval; applying the block mask as a masking matrix to the rotated image to obtain the block image containing only the pixels of the block regions, and obtaining the interval mask by taking the complement of the block mask, applying the interval mask to the rotated image to obtain the interval image containing only the pixels of the interval regions, thereby achieving synchronous separation of the block image and the interval image.
[0035] As shown in Figure 2, which displays block numbers and interval widths, and in Figure 3, in part a of Figure 3, red lines and curves represent the boundaries of connecting blocks, with defects marked by blue circles; in part b, green boxes represent the bounding boxes of connecting blocks; and part c shows the mask obtained from the bounding boxes in part b, affected by the circled defects. In the figures, connected block regions can be sequentially labeled with multiple numbers for description and management. The bounding boxes of multiple block regions can be used as masks to segment block regions and interval regions, and block masks can be generated accordingly. For multiple adjacent block regions, for example, several connected block regions can be selected, and the lateral coordinates of the leftmost foreground pixel in each row of these block regions can be obtained. The median of all obtained values is used as the lateral coordinate of the left bounding box of the corresponding block region; and so on, to determine the remaining sides of the bounding box of each block region. Since the proportion of defective pixels in the entire image is lower than a certain threshold of the total number of pixels, this median statistical method can still correctly determine the bounding boxes when defect interference exists.
[0036] As shown in Figure 4, which is a block mask, the block image can be segmented after applying the block mask to the original image, as shown in Figure 5. The circles in Figure 5 include defects in the block.
[0037] Step S104: In this step, the purpose of segmentation is to divide the rotation-corrected detection image into stripe block regions and stripe interval regions, thus creating a prerequisite for subsequent separate processing of the two types of regions. Specifically, using the rotated image as input, firstly, interconnected stripe block regions in the image are identified. This can be understood as aggregating foreground pixels belonging to the same block into a connected component in the rotated image, and extracting the outer boundary contour of each connected component. Based on this, a bounding box that completely encloses each connected block region is calculated, so that each block region corresponds to a bounding box structure. This bounding box is used both to describe the spatial extent of the block region and can be directly used as the geometric basis for mask generation, used to separate block regions and interval regions on the same rotated image.
[0038] When generating block masks, the bounding boxes of each block region can be mapped to binary mask matrices: the pixel positions covered by the bounding boxes are set to valid, and the remaining positions are set to invalid. The mask matrices of multiple block regions are then merged to obtain a block mask covering all block regions. Since defects may appear near the edges of block regions, defective pixels can interfere with boundary extraction and bounding box calculation, causing bounding boxes to shift, have abnormal sizes, or be incompletely covered. This results in the bounding box-based mask being affected by defects and becoming inaccurate. To suppress the influence of defects on the bounding boxes, robust correction can be performed: taking the same connected component as the object, the leftmost and rightmost coordinates of the foreground pixels of the connected component are calculated on multiple scan rows, and the median of these extreme coordinates is used as the position of the corresponding left and right boundaries of the bounding box; similarly, the topmost and bottommost coordinates of the foreground pixels of the connected component are calculated on multiple scan columns, and the median of these extreme coordinates is used as the position of the corresponding top and bottom boundaries of the bounding box. Since defects account for a small proportion of the overall image, median statistics can effectively reduce the bias effect of a few abnormal pixels on boundary localization, thus obtaining a more stable bounding box that better fits the actual block region range. When multiple block regions are arranged in a predetermined array in the image and the inter-block spacing is constant in the sample set, the generation of the mask can be further improved by combining the array structure. The inter-block spacing can be set to Xd1=Xd2 in the horizontal direction and yd1=yd2 in the vertical direction. Using the corrected bounding box as array anchor points, the spacing position between adjacent block regions and the overall layout boundary are estimated according to the constant spacing relationship, thereby generating a more complete and regular block mask, so that the block regions and the spacing regions are clearly divided in space.
[0039] After obtaining the block mask, the interval mask can be obtained by taking the complement of the block mask. Then, the block mask and the interval mask are applied to the rotating image respectively, for example, by performing masking preservation and masking zeroing according to pixel position. The rotating image is segmented to obtain a block image containing only block region pixels and an interval image containing only interval region pixels, so as to achieve synchronous separation and output of the two types of images.
[0040] As shown in Figure 6, Figure 6 illustrates the spacing mask.
[0041] In step S105, block defect detection is performed on the block image. Each block region is divided into multiple sub-segments along the stripe direction. For each sub-segment, the pixel grayscale sequence is extracted row by row and the median is calculated. The median is used to replace the pixel grayscale of the corresponding row in the sub-segment to generate a block reference image. The block reference image and the block image are differentially divided and binarized to obtain block defect candidates. For abnormal regions that do not meet the median replacement, independent binarization detection is performed and then incorporated into the block defect candidates.
[0042] In block defect detection within a block image, a reference block image is first constructed that has a similar grayscale level to the original block image but differs in defect location. Then, difference and binarization are used to highlight the defect from the striped background. Since the block image has a background structure that changes periodically along the stripe direction, filtering along the stripe direction makes it easier to suppress local abrupt changes caused by defects while preserving the main stripe structure. Therefore, the common two-dimensional median filtering is extended to one-dimensional median filtering, processing the grayscale sequence row by row: first, the median of the grayscale values of all elements in the one-dimensional sequence is calculated, and then this median is used to replace all elements in the sequence, resulting in a smoothed sequence. Significantly deviating noise or outliers can be located by comparing the result with the original sequence. This processing is used to generate the basic units of the reference block image, ensuring that the reference block image maintains a similar grayscale appearance to the original block image at non-defect locations, while creating a difference at defect locations that can be amplified by difference.
[0043] Specifically, step S105, which divides the block region into multiple sub-segments along the stripe direction, includes: setting a segment scale parameter in the direction perpendicular to the stripe direction of the block region, and dividing the block region into multiple adjacent sub-segments according to the segment scale parameter.
[0044] When performing row-median replacement on the sub-segment, the specific steps include: for each image row in the sub-segment, extracting the pixel grayscale sequence of the image row in the sub-segment, calculating the median of the pixel grayscale sequence, and uniformly replacing the grayscale of each pixel in the image row in the sub-segment with the median; after performing row-median replacement on each sub-segment, stitching the replacement results corresponding to each sub-segment together according to their spatial positions to form the block reference image.
[0045] To account for the gradual changes in the background at different locations and reduce the impact of large-scale grayscale drift on median calculation, the block image is divided into multiple adjacent sub-segments along the stripe direction. The width of each sub-segment is limited by a segment scale parameter. Then, a row-by-row one-dimensional median replacement is performed within each sub-segment: for any image row, the pixel grayscale sequence within the sub-segment is extracted, the median is calculated, and the pixel grayscale values within that sub-segment are uniformly replaced with the median. After each sub-segment is completed, the replacement results for each sub-segment are spliced together according to their spatial location to obtain the block reference image. This maintains the main structure of the striped background within the sub-segment scale while smoothing out local anomalies such as scratches and small stains in the reference image, thus achieving background modeling and removal of defects.
[0046] Furthermore, performing the independent binarization detection on the abnormal region includes: determining the candidate position of the abnormal region in the block reference image based on grayscale difference or abnormal pixel ratio, wherein the abnormal pixel ratio is obtained by comparing the ratio of the number of pixels in a certain image row that meet the abnormal grayscale condition to the total number of pixels in the sub-segment; when the abnormal pixel ratio exceeds a preset ratio threshold, determining the region corresponding to the candidate position as the abnormal region; performing binarization processing on the abnormal region in the block reference image to extract the connected components of the abnormal region, and incorporating the connected components into the block defect candidate.
[0047] After obtaining the block reference image, candidate block defects are extracted through image differencing and binarization. Since defects may appear as positive protrusions or negative depressions in the differencing results, two types of difference images need to be calculated: one subtracting the block reference image from the original block image, and the other subtracting the original block image from the block reference image. Binarizing each difference image using a block difference threshold yields the corresponding bright and dark anomaly regions, which are then merged to cover defect types of different polarities. In the example, by subtracting two images in opposite directions and binarizing them separately, white and black defects can be identified, thus allowing candidate block defects to simultaneously cover defects such as scratches and stains that exhibit different directional variations in grayscale.
[0048] The process of differentially dividing and binarizing the block reference image and the block image specifically includes: calculating a first difference image obtained by subtracting the block reference image from the block image, and binarizing the first difference image using a block difference threshold to obtain defect pixels with high grayscale difference compared to the background; calculating a second difference image obtained by subtracting the block image from the block reference image, and binarizing the second difference image using the block difference threshold to obtain defect pixels with low grayscale difference compared to the background; and taking the union of the binarization results of the first difference image and the second difference image to obtain the block defect candidate that simultaneously covers bright defects and dark defects, wherein the bright defects and the dark defects include at least one of scratches and stains.
[0049] It's worth noting that one-dimensional median replacement may fail for large areas of dirt: when the proportion of dirt pixels in a row is high within the sub-segment width, the median of that row will be dominated by the dirt, causing the entire row to be replaced with the dirt's grayscale, and the defect cannot be eliminated from the reference image. Therefore, it's more reasonable to treat these regions that do not meet the median replacement assumption as anomalous regions and process them separately: Anomalous region candidates can be first identified based on grayscale differences or the proportion of anomalous pixels, and then independent binarization detection can be performed on the anomalous regions in the original block image to directly obtain the connected components of large-area dirt, which can then be incorporated into the block defect candidate.
[0050] In step S106, interval defect detection is performed on the interval image, the interval image is superimposed with the block mask to highlight abnormal connected regions in the interval, morphological closing operation is performed on the superposition result to suppress line noise caused by incompletely aligned stripes, and binarization and image inversion are performed to obtain interval defect candidates.
[0051] When performing interval defect detection in the interval image, the process specifically includes: performing interval binarization processing on the interval image to obtain an initial interval binary image; superimposing the block mask on the initial interval binary image to form an intermediate result image containing defects and line noise, wherein the line noise is formed in the interval region by the striped background when there is residual deviation in rotation correction; performing a morphological closing operation on the intermediate result image to suppress the line noise and enhance defect connectivity; binarizing the processing result after the closing operation and performing image inversion to obtain the interval defect candidate.
[0052] Step S106 is used to complete the defect detection process in the interval image. In practice, the interval segmentation result, that is, the segmented interval image, is first obtained. Then, a block mask is introduced and added to the segmented interval image to identify abnormal positions in the interval region and form an intermediate result image containing defects and noise. This intermediate result image corresponds to the state with defects and noise and can be used as input for subsequent noise suppression and defect extraction.
[0053] In this intermediate image, the linear noise originates from stripe alignment errors: since image rotation correction may not ensure that every stripe is perfectly horizontal, linear noise may appear in the gaps. Therefore, morphological closing operations need to be performed on the intermediate image to remove some noise and improve the connectivity of the defect areas. After the closing operation, the processed result is binarized and inverted to generate a cleaner binary image, making the defects in the gaps more prominent and reducing noise, thus obtaining gap defect candidates.
[0054] After the interval defect candidate is completed, the candidate result is used to overlay with the detection result of the block region to obtain the defect detection output of the entire image.
[0055] In step S107, the block defect candidate and the interval defect candidate are spatially superimposed to output a detection result image containing defect markers.
[0056] Step S107 combines the block defect candidates obtained from the block region detection link with the interval defect candidates obtained from the interval region detection link into the final detection output of the entire image. In implementation, it is first ensured that the two types of candidate results are in the same spatial coordinate system: block defect candidates typically correspond to the binary defect results of the block image, and interval defect candidates typically correspond to the binary defect results of the interval image. Since both the block image and the interval image are derived from rotated and corrected images and separated by masks, the two types of candidates can be backfilled or aligned in the coordinates of the rotated and corrected image using their respective masks, so that each candidate defect pixel is mapped to its actual position in the rotated and corrected image, thus forming a defect marker layer of the same size and coordinates. After alignment, the two types of defect marker layers are spatially superimposed to obtain the overall image defect result. Superposition can be achieved by pixel-level summation followed by thresholding, or by using a binary union method, ensuring that the position of any candidate as a defect foreground is preserved in the output, thereby obtaining a complete defect distribution map covering both the block and interval regions. After completing the block and interval defect detection, the result images are superimposed to obtain the overall image defect detection result.
[0057] In terms of output format, the detection result image can be either a direct overlay of defect markers onto the rotated and corrected image, or the defect markers can be visualized and drawn onto the image for manual review. For example, the defective connected components can be outlined, or the defect locations can be circled or labeled with prominent markers, thus forming a detection result image containing defect markers. This synthetic output is used to complete defect recognition tasks at the whole-image level and can simultaneously present the marking effects of defects such as scratches and stains.
[0058] In one implementation, the segment scale parameter, block difference threshold, and interval binarization threshold are determined as follows: A verification sample set containing defect annotations is constructed; a candidate segment scale parameter set, a candidate block difference threshold set, and a candidate interval binarization threshold set are set; with the candidate block difference threshold fixed, the candidate segment scale parameter set is traversed, and the defect detection process described in claim 1 is executed to obtain corresponding evaluation results, thereby determining the segment scale parameter that optimizes the evaluation result; with the segment scale parameter fixed, the candidate block difference threshold set is traversed and the defect detection process is executed to determine the block difference threshold that optimizes the evaluation result; with the segment scale parameter and the block difference threshold fixed, the candidate interval binarization threshold set is traversed and the defect detection process is executed to determine the interval binarization threshold that optimizes the evaluation result. The evaluation results include at least the false negative rate and the false positive rate. The false negative rate is the ratio of the number of times a defect exists but is not detected to the total number of times a defect exists. The false positive rate is the ratio of the number of times a defect is not detected but is mistakenly identified to the total number of times there is no defect. A comprehensive index can be further calculated, which is the sum of the squares of the false negative rate and the false positive rate, and the square root of the sum. The candidate parameter combination that optimizes the comprehensive index is selected as the segment scale parameter, the block difference threshold, and the interval binarization threshold. The above parameter determination method, which fixes one threshold, iterates through the other threshold, and uses the square root of the sum of squares of the false negative rate / false positive rate as the optimization objective, can be used to determine the segment scale parameter and the threshold parameter.
[0059] Furthermore, when outputting the detection result image or the set of defect regions, connected component analysis is performed on the block defect candidates and the interval defect candidates to obtain one or more defect connected regions, and a defect bounding box is generated for each defect connected region; the defect bounding box is superimposed and marked in the detection result image to indicate the defect location. The detection result can be presented by marking the defect regions with bounding boxes.
[0060] Based on the same idea, as shown in Figure 7, an automatic microlens detection system is provided, comprising: an acquisition module 201 for acquiring a stripe image to be detected, wherein the stripe image is an image of a microlens under stripe structure illumination; a preprocessing module 202 for preprocessing the stripe image to suppress brightness unevenness and enhance the contrast between the stripe background and defects, obtaining a preprocessed image with block regions as the foreground; a correction module 203 for determining a rotation angle based on the boundary features of a reference block region in the preprocessed image, and performing rotation correction on the stripe image accordingly, aligning the stripe direction of the stripe background with the image row direction, thereby obtaining a rotated image; a segmentation module 204 for segmenting the rotated image, determining bounding boxes for each block region of the rotated image based on identified connected block regions; generating block masks based on each bounding box, and obtaining interval masks by complementing the block masks, thereby obtaining block images and interval images; and detecting defects in block regions. The detection module 205 is used to perform block defect detection in the block image, divide each block region into multiple sub-segments along the stripe direction, extract the pixel grayscale sequence row by row for each sub-segment and calculate the median, replace the pixel grayscale of the corresponding row in the sub-segment with the median, and generate a block reference image; perform difference and binarization on the block reference image and the block image to obtain block defect candidates, and perform independent binarization detection on abnormal regions that do not meet the median replacement and then incorporate them into the block defect candidates; the interval region defect detection module 206 is used to perform interval defect detection in the interval image, superimpose the interval image with the block mask to highlight abnormal connected components in the interval, perform morphological closing operation on the superposition result to suppress line noise generated by incompletely aligned stripes, and perform binarization and image inversion to obtain interval defect candidates; the fusion output module 207 is used to spatially superimpose the block defect candidates and the interval defect candidates to output a detection result image containing defect markers.
[0061] This system smooths, equalizes brightness, enhances contrast, and foregrounds block regions in the striped image, making the boundary features of the reference block region more stable. This allows for reliable determination of the rotation angle and correction of the stripe direction to align with the image row direction, satisfying the prerequisite of "relatively consistent gray levels within the same row" in subsequent row-by-row statistical processing, and reducing the impact of stripe tilt on defect detection. By generating circumscribed bounding boxes based on connected components and constructing block masks and interval masks, the rotated image is separated into block images and interval images, allowing the striped block background and interval regions to enter different processing paths, avoiding false detections caused by a single detection strategy simultaneously considering both types of regions. The block image is segmented along the stripe direction, and each segment is processed... The median of each segment is calculated row by row to replace the generated block reference image. Then, the median is differiated from and binarized with the block image, which can simultaneously extract bright and dark defects. Independent binarization detection is introduced for abnormal areas where median replacement is not applicable, which improves the adaptability to stains or large-area anomalies. In the interval image, abnormal connected regions are highlighted by superimposing with the block mask, and morphological closing operation is used to suppress linear noise introduced by rotation residual deviation. Then, interval defect candidates are obtained by binarization and inversion, thereby improving the segmentability of defects in the interval region. Finally, the block defect candidates and interval defect candidates are fused and output to achieve unified labeling of defects in the whole image, improve the integrity of the detection results and reduce the burden of manual re-inspection.
[0062] The specific details of each module / unit in the above system have been described in detail in the implementation method section. For any undisclosed details, please refer to the implementation method section, and therefore will not be repeated here.
[0063] Based on the same idea, this specification also provides an automatic microlens detection device, as shown in Figure 8.
[0064] The automatic microlens detection device can be the terminal device or server provided in the above embodiments.
[0065] The automatic microlens detection device can vary considerably depending on its configuration or performance. It may include one or more processors 301, a memory 302, and a bus. The memory 302 may store one or more application programs or data. The memory 302 may include readable media in the form of volatile memory cells, such as random access memory (RAM) and / or cache memory cells, i.e., plug-in external hard drives, smart media cards (SMC), secure digital cards (SD cards), flash cards, etc., and may further include read-only memory cells. The application programs stored in the memory 302 may include one or more program modules (not shown in the figures). Such program modules include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Furthermore, the processor 301 may be configured to communicate with the memory 302 and execute a series of computer-executable instructions stored in the memory 302 on the automatic microlens detection device. The microlens automatic detection device may also include one or more power supplies 303, one or more wired or wireless network interfaces 304, one or more I / O interfaces (input / output interfaces) 305, and one or more external devices 306 (e.g., keyboards) for communication. It may also communicate with one or more devices that enable user interaction with the device, and / or with any device that enables the device to communicate with one or more other computing devices (e.g., routers, network switches, etc.). This communication can be performed through I / O interfaces 305. Furthermore, the device can also communicate with one or more networks (e.g., local area networks (LANs)) via wired or wireless interfaces 304.
[0066] Figure 8 only shows an automated microlens inspection device with components. Those skilled in the art will understand that the structure shown in Figure 8 does not constitute a limitation on the automated microlens inspection device, and may include fewer or more components than shown, or combine certain components, or have different component arrangements.
[0067] Specifically, in this embodiment, the automatic microlens detection device includes a memory and one or more programs. One or more programs are stored in the memory, and each program may include one or more modules. Each module may include a series of computer-executable instructions for the automatic microlens detection device, configured to be executed by one or more processors. The program includes the following computer-executable instructions: acquiring a stripe image to be detected, wherein the stripe image is an image of a microlens under stripe structure illumination; preprocessing the stripe image to suppress brightness unevenness and enhance the contrast between the stripe background and the defect, obtaining a preprocessed image with a block region as the foreground; determining a rotation angle based on the boundary features of a reference block region in the preprocessed image, and accordingly performing rotation correction on the stripe image to align the stripe direction of the stripe background with the image row direction, obtaining a rotated image; segmenting the rotated image, based on the identified connected block regions, into segments... The bounding boxes of the rotated image block regions are determined; block masks are generated based on the bounding boxes, and the block masks are complemented to obtain interval masks, thereby obtaining block images and interval images; block defect detection is performed in the block images, each block region is divided into multiple sub-segments along the stripe direction, the pixel grayscale sequence of each sub-segment is extracted row by row and the median is calculated, and the median is used to replace the pixel grayscale of the corresponding row in the sub-segment to generate a block reference image; the block reference image and the block image are differencing and binarized to obtain block defect candidates, and abnormal regions that do not meet the median replacement are independently binarized and then incorporated into the block defect candidates; interval defect detection is performed in the interval images, the interval images are superimposed with the block masks to highlight abnormal connected components in the intervals, morphological closing operations are performed on the superposition results to suppress line noise caused by incompletely aligned stripes, and binarization and image inversion are performed to obtain interval defect candidates; the block defect candidates and the interval defect candidates are spatially superimposed to output a detection result image containing defect markers.
[0068] Based on the same idea, exemplary embodiments of the present invention also provide a computer-readable storage medium storing a program product capable of implementing the methods described above. In some possible embodiments, various aspects of the present invention can also be implemented as a program product including program code, which, when the program product is run on a terminal device, causes the terminal device to perform the steps of the various exemplary embodiments of the present invention described in the "Exemplary Methods" section above.
[0069] Referring to Figure 9, a program 400 for implementing the above-described method according to an exemplary embodiment of the present invention is described. This program may employ a portable compact disc read-only memory (CD-ROM) and include program code, and may run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, the readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, system, or device.
[0070] The program product may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or any combination thereof. More specific examples (a non-exhaustive list) of readable storage media include: electrical connections with one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0071] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable signal medium may also be any readable medium other than a readable storage medium, capable of sending, propagating, or transmitting programs for use by or in conjunction with an instruction execution system, system, or device.
[0072] Program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, CSS, and HTML, as well as conventional procedural programming languages such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0073] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions of the embodiments of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, portable hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, terminal system, or network device, etc.) to execute the method according to the exemplary embodiments of the present invention.
[0074] Furthermore, the above figures are merely illustrative representations of the processes included in the method according to exemplary embodiments of the present invention, and are not intended to be limiting. It is readily understood that the processes shown in the above figures do not indicate or limit the temporal order of these processes. Additionally, it is readily understood that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0075] It should be noted that although several modules or units of the device for performing actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to exemplary embodiments of the present invention, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0076] Other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein. The specification and embodiments are to be considered exemplary only, and the true scope and spirit of the invention are indicated by the claims.
[0077] It should be understood that the present invention is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.
Claims
1. An automatic detection method for microlenses, characterized in that, The method includes: acquiring a stripe image to be detected, wherein the stripe image is an image under stripe structure illumination applied by a microlens; preprocessing the stripe image to suppress brightness unevenness and enhance the contrast between the stripe background and defects, obtaining a preprocessed image with block regions as the foreground; determining a rotation angle based on the boundary features of a reference block region in the preprocessed image, and performing rotation correction on the stripe image accordingly, aligning the stripe direction of the stripe background with the image row direction, to obtain a rotated image; segmenting the rotated image, and determining bounding boxes for the block regions of each rotated image based on the identified connected block regions; generating block masks based on each bounding box, and obtaining interval masks by complementing the block masks, thereby obtaining block images and interval images; performing block defect detection in the block images, and dividing each The block region is divided into multiple sub-segments along the stripe direction. For each sub-segment, the pixel grayscale sequence is extracted row by row and the median is calculated. The median is used to replace the pixel grayscale of the corresponding row in the sub-segment to generate a block reference image. The block reference image and the block image are differencing and binarized to obtain block defect candidates. Abnormal regions that do not meet the median replacement requirement are independently binarized and detected before being incorporated into the block defect candidates. Interval defect detection is performed in the interval image. The interval image is superimposed on the block mask to highlight abnormal connected components in the interval. Morphological closing operation is performed on the superposition result to suppress line noise caused by incompletely aligned stripes. Binarization and image inversion are then performed to obtain interval defect candidates. The block defect candidates and the interval defect candidates are spatially superimposed to output a detection result image containing defect markers.
2. The automatic microlens detection method according to claim 1, characterized in that, The preprocessing specifically includes: performing Gaussian smoothing on the striped image to reduce random noise while maintaining the main structure of the striped background; performing histogram equalization on the smoothed image to expand the gray-level distribution and reduce the local brightness difference caused by non-uniform illumination; performing gamma correction on the equalized image to improve the gray-level difference between the defects and the striped background through non-linear gray-level mapping; performing binarization on the image after gamma correction to form a binary image, and performing image inversion on the binary image so that the block region is represented as foreground pixels and the interval region is represented as background pixels in the preprocessed image.
3. The automatic microlens detection method according to claim 1, characterized in that, Determining the rotation angle specifically includes: selecting a reference block region located at a predetermined position in the preprocessed image, wherein the reference block region is a block region located in the middle of the image or satisfying predetermined geometric constraints; extracting a set of contour points from the reference block region; fitting the minimum bounding rectangle surrounding the reference block region based on the set of contour points, and determining the rotation angle by the angle between the side of the minimum bounding rectangle and the image row direction; performing rotational resampling on the striped image using a geometric transformation with the rotation angle as a parameter, so that the stripe direction of the striped background is approximately parallel to the image row direction.
4. The automatic microlens detection method according to claim 1, characterized in that, The acquisition of the block image and the interval image specifically includes: performing connected component analysis on the rotated image to obtain multiple connected block regions; generating an outer bounding box for each block region; when a defect causes the boundary of the outer bounding box to shift, sampling and statistically analyzing the foreground extreme coordinates of the block region on multiple scan rows and multiple scan columns, and using the median of the foreground extreme coordinates as the position of the corresponding boundary to perform robust correction on the outer bounding box, wherein the foreground extreme coordinates include the leftmost foreground pixel coordinate, the rightmost foreground pixel coordinate, and the coordinates of each scan row. The coordinates of the topmost foreground pixel and the bottommost foreground pixel are described. When multiple block regions are arranged in a predetermined array and the inter-block spacing is constant in the sample set, the block mask is generated based on the corrected bounding box and the inter-block spacing. The block mask is applied as a masking matrix to the rotated image to obtain the block image containing only the pixels of the block regions. The spacing mask is obtained by taking the complement of the block mask. The spacing mask is applied to the rotated image to obtain the spacing image containing only the pixels of the spacing regions, so as to achieve synchronous separation of the block image and the spacing image.
5. The automatic microlens detection method according to claim 1, characterized in that, When dividing a block region into multiple sub-segments along the stripe direction, the method includes: setting a segment scale parameter in the direction perpendicular to the stripe direction of the block region, and dividing the block region into multiple adjacent sub-segments according to the segment scale parameter; when performing row median replacement on the sub-segments, the method specifically includes: for each image row in the sub-segment, extracting the pixel grayscale sequence of the image row in the sub-segment, calculating the median of the pixel grayscale sequence, and uniformly replacing the grayscale of each pixel in the image row in the sub-segment with the median; after performing row median replacement on each sub-segment, stitching the replacement results corresponding to each sub-segment together according to their spatial positions to form the block reference image.
6. The automatic microlens detection method according to claim 1, characterized in that, Performing independent binarization detection on the abnormal region includes: determining candidate positions of the abnormal region in the block reference image based on grayscale differences or the proportion of abnormal pixels, wherein the proportion of abnormal pixels is obtained by comparing the ratio of the number of pixels in a certain image row that meet the abnormal grayscale condition to the total number of pixels in the sub-segment; when the proportion of abnormal pixels exceeds a preset proportion threshold, determining the region corresponding to the candidate position as the abnormal region; performing binarization processing on the abnormal region in the block reference image to extract the connected components of the abnormal region, and incorporating the connected components into the block defect candidate.
7. The automatic microlens detection method according to claim 1, characterized in that, The process of differentially dividing and binarizing the block reference image and the block image specifically includes: calculating a first difference image obtained by subtracting the block reference image from the block image, and binarizing the first difference image using a block difference threshold to obtain defect pixels with high grayscale difference compared to the background; calculating a second difference image obtained by subtracting the block image from the block reference image, and binarizing the second difference image using the block difference threshold to obtain defect pixels with low grayscale difference compared to the background; and taking the union of the binarization results of the first difference image and the second difference image to obtain the block defect candidate that simultaneously covers bright defects and dark defects, wherein the bright defects and the dark defects include at least one of scratches and stains.
8. The automatic detection method for microlenses according to claim 1, characterized in that, When performing interval defect detection in the interval image, the process specifically includes: performing interval binarization processing on the interval image to obtain an initial interval binary image; superimposing the block mask on the initial interval binary image to form an intermediate result image containing defects and line noise, wherein the line noise is formed in the interval region by the striped background when there is residual deviation in rotation correction; performing a morphological closing operation on the intermediate result image to suppress the line noise and enhance defect connectivity; binarizing the processing result after the closing operation and performing image inversion to obtain the interval defect candidate.
9. An automatic microlens detection system, characterized in that, include: The acquisition module is used to acquire the stripe image to be detected, wherein the stripe image is an image under stripe structure illumination applied to the microlens; The preprocessing module is used to preprocess the striped image to suppress brightness unevenness and enhance the contrast between the striped background and defects, so as to obtain a preprocessed image with the block area as the foreground. The correction module is used to determine the rotation angle based on the boundary features of the reference block region in the preprocessed image, and to perform rotation correction on the striped image accordingly, so that the stripe direction of the striped background is aligned with the image row direction, thereby obtaining a rotated image. The segmentation module is used to segment the rotated image, determine the bounding box of each block region of the rotated image based on the identified connected block regions, generate a block mask according to each bounding box, and obtain a gap mask by complementing the block mask, thereby obtaining the block image and the gap image. A block region defect detection module is used to perform block defect detection in the block image. Each block region is divided into multiple sub-segments along the stripe direction. For each sub-segment, a pixel grayscale sequence is extracted row by row and the median is calculated. The median is used to replace the pixel grayscale of the corresponding row in the sub-segment to generate a block reference image. The block reference image and the block image are differentially divided and binarized to obtain block defect candidates. For abnormal regions that do not meet the median replacement requirement, independent binarization detection is performed and then incorporated into the block defect candidates. The interval region defect detection module is used to detect interval defects in the interval image, superimpose the interval image with the block mask to highlight abnormal connected regions in the interval, perform morphological closing operation on the superposition result to suppress line noise caused by incompletely aligned stripes, and perform binarization and image inversion to obtain interval defect candidates. The fusion output module is used to spatially superimpose the block defect candidate and the interval defect candidate to output a detection result image containing defect markers.