Tobacco leaf image defect classification method, device, equipment, medium and program product
By extracting and expanding candidate abnormal regions from tobacco leaf images and combining them with image patch fusion processing, the problem that existing defect classification networks cannot effectively utilize prior information about anomalies is solved, thus improving the accuracy of defect classification.
Patent Information
- Application Number
- CN202611366636.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-04
- Publication Date
- 2026-11-24
AI Technical Summary
In existing technologies, anomaly heatmaps are only used as a basis for locating anomaly areas, which prevents the defect classification network from effectively utilizing prior information about anomalies and neighborhood context information, thus reducing the ability to distinguish defect categories.
By acquiring the abnormal heatmap of the image to be detected, candidate abnormal regions are extracted and expanded to obtain the first expanded region. The image block to be detected and the abnormal heatmap block are fused along the channel dimension and input into the defect classification network for defect category determination.
It improves the accuracy of defect classification, makes full use of image appearance and anomaly information, and reduces the loss of contextual information caused by tight boundary cropping.
Smart Images

Figure CN123160949A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image analysis and machine vision inspection technology, and in particular to a method, apparatus, equipment, medium, and program product for classifying defects in tobacco leaf images. Background Technology
[0002] In industrial manufacturing, warehousing, and automated production processes, real-time visual inspection of product appearance quality is required to identify mold, cracks, scratches, contamination, foreign objects, corrosion, and other surface anomalies. Industrial anomaly detection technology achieves accurate identification of product surface anomalies by constructing a feature distribution model of defect-free samples. Its core is to transform the detection problem into a measure of feature deviation and use anomaly heatmaps for judgment. Anomaly heatmaps can intuitively reflect the location and distribution of defect areas, providing a visual interpretation of the detection results. However, in existing methods, anomaly heatmaps are typically only used as a basis for locating anomaly areas. Based on this location information, anomaly areas are then cropped for defect classification. This results in the defect classification network only utilizing local appearance information and failing to explicitly obtain prior information such as the location and intensity of anomalies generated by the anomaly detection model. Furthermore, directly cropping anomaly areas based solely on location information may reduce the ability to classify defects due to a lack of contextual information such as surrounding texture, edge transitions, or organizational structure. Therefore, how to effectively utilize anomaly prior information and neighborhood contextual information is a key problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0003] This invention provides a method, apparatus, device, medium, and program product for classifying defects in tobacco leaf images, which solves the problem of interference from large areas of normal background on defect classification. It can reduce the loss of contextual information caused by tight boundary cropping, and can also make full use of image appearance information and abnormal information to improve the accuracy of defect classification.
[0004] According to one aspect of the present invention, a method for classifying defects in tobacco leaf images is provided, the method comprising: An image to be detected is acquired, and the image to be detected is processed using an anomaly detection network to obtain an anomaly heatmap corresponding to the image to be detected. The image to be detected is a photograph of the industrial product to be detected, and the anomaly heatmap corresponding to the image to be detected is used to characterize the degree of anomaly at each spatial location. Candidate abnormal regions are extracted from the abnormal heatmap corresponding to the image to be detected, and the location information of the candidate abnormal regions is obtained, wherein the location information of the candidate abnormal regions includes the region coordinates of the candidate abnormal regions in the coordinate system of the image to be detected. The candidate anomaly region is expanded to obtain a first expanded region. The first expanded region includes the candidate anomaly region and the neighborhood context region of the candidate anomaly region. The first expanded region is obtained by expanding the region boundary context based on the candidate anomaly region. Using the location information of the first extended region, the image to be detected and the corresponding abnormal heat map are cropped to obtain the image block to be detected and the abnormal heat map block. The location information of the first extended region includes the region coordinates of the first extended region in the coordinate system of the image to be detected. The image block to be detected and the abnormal thermal image block are fused along the channel dimension to obtain a fused tensor; The fusion tensor is input into the defect classification network to obtain the corresponding defect category of the candidate anomaly region, and the parameter information of the candidate anomaly region and the defect category are output. The parameter information of the candidate anomaly region includes the location information of the candidate anomaly region and the area ratio information of the candidate anomaly region in the image to be detected. The anomaly detection network and the defect classification network are independent of each other.
[0005] According to another aspect of the present invention, a tobacco leaf image defect classification device is provided, the device comprising: The image acquisition module is used to acquire the image to be detected, process the image to be detected using an anomaly detection network, and obtain an anomaly heatmap corresponding to the image to be detected. The image to be detected is a photograph of the industrial product to be detected, and the anomaly heatmap corresponding to the image to be detected is used to characterize the degree of anomaly at each spatial location. The coordinate acquisition module is used to extract candidate abnormal regions from the abnormal heatmap corresponding to the image to be detected, and to acquire the location information of the candidate abnormal regions, wherein the location information of the candidate abnormal regions includes the region coordinates of the candidate abnormal regions in the coordinate system of the image to be detected. A region expansion module is used to expand the candidate anomaly region to obtain a first expanded region. The first expanded region includes the candidate anomaly region and the neighborhood context region of the candidate anomaly region. The first expanded region is obtained by expanding the region boundary context based on the candidate anomaly region. The image block cropping module is used to crop the image to be detected and the abnormal heat map corresponding to the image to be detected using the spatial coordinates of the position information of the first extended region to obtain the image block to be detected and the abnormal heat map. The position information of the first extended region includes the region coordinates of the first extended region in the coordinate system of the image to be detected. The tensor fusion module is used to fuse the image block to be detected and the abnormal thermal image block along the channel dimension to obtain a fused tensor; The defect classification module is used to input the fused tensor into the defect classification network to obtain the corresponding defect category of the candidate anomaly region, and output the parameter information of the candidate anomaly region and the defect category; the parameter information of the candidate anomaly region includes the location information of the candidate anomaly region and the area ratio information of the candidate anomaly region in the image to be detected, and the anomaly detection network and the defect classification network are independent of each other.
[0006] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, which enables the at least one processor to perform the tobacco leaf image defect classification method according to any embodiment of the present invention.
[0007] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the tobacco leaf image defect classification method according to any embodiment of the present invention.
[0008] According to another aspect of the present invention, a computer program product is provided, the computer program product comprising a computer program that, when executed by a processor, implements the tobacco leaf image defect classification method according to any embodiment of the present invention.
[0009] The technical solution of this invention utilizes a relatively independent anomaly detection network to obtain the location information and intensity of the anomaly region, facilitating the localization of the anomaly region. It introduces contextual features into candidate anomaly regions and crops the extended region, reducing information loss caused by tight boundary cropping while also reducing interference from large areas of normal background. It fuses the image patch to be detected with the anomalous thermal image patch for defect classification, fully combining image appearance features and prior information about anomalies to improve the accuracy of defect classification.
[0010] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0011] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is a flowchart of a tobacco leaf image defect classification method provided in Embodiment 1 of this application; Figure 2 This is a flowchart of a tobacco leaf image defect classification method according to Embodiment 2 of this application; Figure 3 This is a schematic diagram of the structure of a tobacco leaf image defect classification device according to Embodiment 3 of this application; Figure 4 This is a schematic diagram of the structure of an electronic device that implements the tobacco leaf image defect classification method provided in Embodiment 4 of this application. Detailed Implementation
[0013] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0014] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0015] Example 1 Figure 1This is a flowchart of a tobacco leaf image defect classification method provided by an embodiment of the present invention. This embodiment is applicable to industrial product quality inspection and defect classification scenarios. The method can be executed by a tobacco leaf image defect classification device, which can be implemented in software and / or hardware, optionally through electronic devices, such as mobile terminals, personal computers, or servers. Figure 1 As shown, the method includes: S110. Obtain the image to be detected, process the image to be detected using an anomaly detection network, and obtain an anomaly heatmap corresponding to the image to be detected.
[0016] The image to be inspected is a photograph of the industrial product to be inspected. The image to be inspected can refer to a digital image of the product's appearance obtained using an industrial camera under specific lighting and shooting conditions, used to present visual information such as the texture, structure, and various defects on the product surface. For example, the camera assembly inside the sealed acquisition box can generate a photograph of tobacco leaves laid flat to be inspected, preserving complete details.
[0017] The anomaly heatmap corresponding to the image to be detected is used to characterize the degree of anomaly at each spatial location. The anomaly heatmap can be understood as mapping the continuous scores of anomaly detection output to a visual representation of color gradients, where the color of each pixel corresponds to the degree of anomaly at that pixel. For example, the anomaly evaluation score of each pixel in the image to be detected is mapped to the color value corresponding to that score. Areas with anomaly evaluation scores higher than 0.5 are displayed in red in the anomaly heatmap, and areas with anomaly evaluation scores lower than 0.5 are displayed in blue, resulting in a visual anomaly heatmap that clearly identifies the location and severity of defects.
[0018] The anomaly detection network includes an industrial anomaly detection network capable of outputting pixel-level or region-level anomaly evaluation scores and generating anomaly heatmaps. During the training phase, the anomaly detection network learns the feature distribution patterns of defect-free image samples; during the inference phase, it calculates the deviation between the feature distribution of the image to be detected and that of defect-free image samples, and outputs anomaly evaluation scores or anomaly heatmaps.
[0019] For example, in the field of tobacco leaf inspection, the anomaly detection network can be YOLOv8 or an improved version of YOLOv8, which can efficiently identify known foreign objects and appearance defects, while unsupervised anomaly detection networks such as CFlow can be introduced for unknown types of defects and anomalies.
[0020] Acquiring the image to be inspected can include receiving data transmitted in real time from an imaging device or reading a stored image file to obtain target image data suitable for defect analysis. For example, in the crop appearance inspection process, images collected on-site or pre-saved are directly read to obtain the target image for defect analysis.
[0021] The process of using an anomaly detection network to process the image to be detected may include first mapping the image to be detected to a feature space, comparing the feature distribution of the image to be detected with the feature distribution of defect-free image samples learned during the training phase pixel by pixel, and calculating the feature deviation of each pixel as an anomaly evaluation score; then arranging the anomaly evaluation scores according to their corresponding spatial positions in the image to be detected, and superimposing them back into the spatial coordinate system of the image to be detected in a color mapping manner to obtain an anomaly heatmap corresponding to the image to be detected.
[0022] For example, an anomaly detection network is used to calculate anomaly evaluation scores pixel by pixel in the image of the tobacco leaf to be inspected. The scores are then arranged according to their corresponding coordinate positions in the image, and the anomaly evaluation scores are mapped to color gradients to obtain an anomaly heatmap. In this heatmap, red highlighted areas can represent the location of foreign objects or mold, while blue areas can correspond to the surface of defect-free tobacco leaves.
[0023] In this embodiment of the application, the defect area is accurately located by the detection method based on the anomaly heat map, and the degree of anomaly is reflected intuitively. This can enhance the interpretability of the detection results and help improve the efficiency and accuracy of defect detection in industrial quality control.
[0024] S120. Extract candidate abnormal regions from the abnormal heatmap corresponding to the image to be detected, and obtain the location information of the candidate abnormal regions.
[0025] The location information of the candidate anomaly region includes its coordinates in the coordinate system of the image to be detected. The region coordinates characterize the spatial position and extent of the anomaly region in the image coordinate system, enabling defect localization. The region coordinates can be expressed as corner coordinates or center coordinates, and may also include the width and height of the bounding rectangle of the candidate anomaly region, thus fully reconstructing the enclosing range of the candidate anomaly region.
[0026] For example, in tobacco leaf appearance inspection, the center coordinates and the width and height of the circumscribed rectangle can be used as region coordinate parameters to record the position and coverage size of the abnormal lesion area on the image to be inspected, thus completing the lesion location.
[0027] Candidate anomaly regions can be the range of suspicious pixels in the anomaly heatmap whose anomaly evaluation scores exceed a preset segmentation threshold. These candidate anomaly regions can represent potential locations where the local feature distribution of the image to be detected deviates from the feature distribution of defect-free image samples learned by the anomaly detection network. Subsequently, defect location extraction and range determination can be performed based on these candidate anomaly regions, providing a basis for anomaly segmentation and defect quantification. For example, in the tobacco leaf appearance inspection scenario, all pixels with anomaly evaluation scores higher than a preset segmentation threshold constitute candidate anomaly regions. These candidate anomaly regions collect pixels corresponding to actual tobacco leaf lesions and damage, while also including pseudo-anomaly pixels caused by light interference from leaf folds.
[0028] The process of extracting candidate abnormal regions from the abnormal heatmap corresponding to the image to be detected may include using a pre-set segmentation threshold as a judgment threshold, traversing each pixel in the abnormal heatmap that carries an abnormal evaluation score, comparing the abnormal evaluation score of each pixel with the preset segmentation threshold, retaining pixels whose abnormal evaluation scores exceed the preset segmentation threshold, and obtaining a pixel set composed of defective pixels to complete the extraction of candidate abnormal regions.
[0029] For example, during the tobacco leaf appearance inspection process, a pre-set segmentation threshold is used as the judgment threshold to traverse the abnormal heat map pixels. Pixels with abnormal evaluation scores exceeding the pre-set segmentation threshold are filtered and retained to obtain the pixel set corresponding to tobacco leaf lesions, thus completing the extraction of abnormal areas of tobacco leaf lesions.
[0030] Obtaining the location information of the candidate abnormal region may include traversing the image coordinates of all pixels within the candidate abnormal region, searching for the maximum and minimum values of the horizontal and vertical coordinates of all pixels, determining the coordinates of a corner point of the bounding rectangle of the candidate abnormal region based on the minimum horizontal and vertical coordinate values, determining the coordinates of the opposite corner point of the bounding rectangle of the candidate abnormal region based on the maximum horizontal and vertical coordinate values, or combining all pixel coordinates to obtain the center coordinates of the candidate abnormal region, and simultaneously calculating the difference between the horizontal and vertical coordinates to obtain the width and height of the bounding rectangle of the candidate abnormal region.
[0031] For example, when detecting tobacco leaf lesions, the image coordinates of each pixel in the abnormal lesion area are traversed, the minimum and maximum values of the horizontal and vertical coordinates of all pixels are found, the center coordinates of the abnormal lesion area are calculated based on the coordinates of all pixels, and the width and height of the bounding rectangle of the abnormal lesion area are calculated by the difference between the horizontal and vertical coordinates.
[0032] In this embodiment, extracting candidate abnormal regions can separate defect-related pixels from a large number of pixels in the abnormal heatmap, filter out interfering pixels, and reduce the amount of data that needs to be processed subsequently; calculating the location information of candidate abnormal regions can transform the abstract set of pixels into quantifiable location and size information, which can clarify the specific location and actual size of the defect in the image to be detected.
[0033] S130. The candidate anomaly region is expanded to obtain a first expanded region. The first expanded region includes the candidate anomaly region and the neighborhood context region of the candidate anomaly region. The first expanded region is obtained by expanding the context of the region boundary based on the candidate anomaly region.
[0034] The first extended region can be a surrounding adjacent region obtained by expanding the candidate anomaly region outwards. This first extended region does not completely belong to the actual defect body, but it is spatially closely connected to the candidate anomaly region. For example, the candidate anomaly region is a dark spot with a size of 20×20 pixels. The first extended region is obtained by expanding outwards by 5 pixels on each side. The first extended region includes part of the edge of the actual dark spot and the surrounding normal background pixels.
[0035] The neighborhood context region can be a pixel range that is directly connected to the candidate anomaly region in space. This neighborhood context region includes part of the defect edge and adjacent defect-free background pixels, and is used to cooperate with the candidate anomaly region to complete feature comparison and boundary verification. For example, the candidate anomaly region is a lesion on a tobacco leaf, and the neighborhood context region is the leaf surface range covered by the lesion outline offset outward by 3-8 pixels, which includes both the edge tissue of the lesion transitioning to the healthy leaf surface and the leaf surface of the tobacco leaf without lesions.
[0036] Context expansion can include a process that uses a candidate anomaly region as a reference and shifts it outward by a predetermined distance along the outline of the candidate anomaly region to generate a larger detection area. This context expansion operation can preserve the main body of the candidate anomaly region while retaining the transition edges connected to the candidate anomaly region and the adjacent background. This context expansion operation can solve the problem of missing reference information in candidate anomaly regions. For example, when a brown spot candidate anomaly region of a tobacco leaf is identified, it is expanded outward proportionally by 15% of the width of the brown spot candidate anomaly region itself, preserving the main brown spot region while covering the adjacent mesophyll tissue.
[0037] In this embodiment, by extending the context of candidate abnormal regions, the texture, edge transition and organizational structure information around the defect can be preserved while highlighting the core abnormal region. This can reduce the information loss caused by boundary clipping, achieve defect boundary correction, and improve the reliability of defect category discrimination.
[0038] S140. Using the location information of the first extended region, the image to be detected and the abnormal heat map corresponding to the image to be detected are cropped to obtain the image block to be detected and the abnormal heat map block. The location information of the first extended region includes the region coordinates of the first extended region in the coordinate system of the image to be detected.
[0039] The location information of the first extended region can be a set of location parameters calculated based on the coordinate boundaries of the candidate anomaly region. The horizontal and vertical coordinates of the candidate anomaly region are offset and adjusted according to a pre-set extension ratio or extension distance, updating the region coordinates of the first extended region without changing the coordinates of the candidate anomaly region. The region coordinates of the first extended region can have various representations, including the center coordinates of the first extended region combined with the length and width dimensions of the bounding rectangle of the first extended region, or a sequence of pixel points representing the outline of the candidate anomaly region.
[0040] The image block to be detected can refer to a local sub-image selected and cropped from the image to be detected based on the location information of the first extended region. This local sub-image filters and retains local scenes containing suspected abnormal defects, eliminating a large number of defect-free background areas for subsequent defect judgment and classification and defect feature analysis. This reduces the amount of computation on invalid image data and improves the model's processing efficiency.
[0041] For example, in a tobacco leaf defect classification task, there is a local area with red spot disease in the image to be detected. The local sub-image covering the spot and a small amount of tobacco leaf tissue around it is obtained from the image to be detected based on the coordinates of the local area. This sub-image is used as the image block to be detected.
[0042] The abnormal heat map block can refer to a local image unit selected and cropped from the abnormal heat map based on the location information of the first extended region. This local image unit is independent of the image to be detected, and the content of the local image unit is the pixel image of the abnormal heat map itself, corresponding to the same spatial location of the image block to be detected in the image to be detected.
[0043] For example, the red spot disease lesions on tobacco leaves occupy a fixed area in the abnormal heat map. This area is extracted separately from the abnormal heat map to obtain an abnormal heat map image block. This abnormal heat map image block corresponds one-to-one with the spatial position of the red spot disease lesions on the tobacco leaf image, but the actual appearance of the leaf cannot be seen.
[0044] The process of cropping the image block to be detected and the abnormal thermal image block based on the location information of the first extended region may include image processing operations that separate corresponding spatial ranges of local images from the image to be detected and the abnormal thermal image, respectively, using the region range defined by the region coordinates of the first extended region as the boundary. For example, a 4000×3000 pixel image of a tobacco leaf to be detected has a lesion area. The upper left corner coordinates of the bounding rectangle of the lesion area are (610, 720) and the lower right corner coordinates are (750, 860). According to these coordinates, the corresponding regions are cropped from the image to be detected and the corresponding abnormal thermal image of the tobacco leaf to be detected, respectively, to obtain a 140×140 pixel image block to be detected and an abnormal thermal image block.
[0045] In this embodiment, cropping a local image based on the coordinate information of the first extended region can discard a large number of irrelevant background areas, filter and retain the local images corresponding to the anomalies, reduce the amount of data for subsequent processing, avoid interference from irrelevant content on subsequent defect category identification, and reduce the image size to reduce computational overhead and improve processing speed.
[0046] S150. The image block to be detected and the abnormal thermal image block are fused along the channel dimension to obtain a fused tensor.
[0047] In this context, the channel dimension can be a data dimension in image data that is independent of the width and height spatial dimensions. It is used to carry multiple sets of independent information at the same spatial location, enabling parallel storage of different types of data. For example, the image to be detected uses the channel dimension to store the original pixel information obtained from image imaging, while the anomaly heatmap uses the channel dimension to store the anomaly measurement information calculated by the anomaly detection algorithm. The channel dimension can be used to distinguish the types of data information stored in the image to be detected and the anomaly heatmap, respectively.
[0048] The fusion tensor can be understood as an integrated tensor obtained by taking the tensor of the image patch to be detected and the tensor of the abnormal thermal image patch as input. This fusion tensor simultaneously carries the visual information of the image patch to be detected and the confidence weight information of the abnormal thermal image patch. For example, the tensor size of the image patch to be detected is [3, 256, 256], used to store RGB pixel information, and the tensor size of the abnormal thermal image patch is [1, 256, 256], used to store the defect confidence of each pixel. The tensor size after fusing the tensors of the image patch to be detected and the abnormal thermal image patch is [4, 256, 256]. This fused tensor simultaneously contains the pixel data of the image patch to be detected and the confidence data of the abnormal thermal image patch, and can be input into subsequent networks to complete defect category judgment.
[0049] The process of fusing the image block to be detected and the abnormal thermal image block along the channel dimension can include integrating information along the channel dimension for two semantically different original tensors, keeping the width and height spatial dimensions of the two semantically different original tensors unchanged, stacking the pixel data of the image block to be detected and the confidence data of the abnormal thermal image block as different channels of the fusion tensor, and retaining the data of the two semantically different original tensors at the same spatial position one by one, thus bringing together the image visual information and the thermal map confidence information into the fusion tensor.
[0050] For example, the tensor of the image block to be detected has 3 channels and a width and height of 256×256, while the tensor of the abnormal thermal image block has 1 channel and a width and height of 256×256. After stacking along the channel dimension, the width and height remain unchanged at 256×256, and the number of channels of the fused tensor becomes 4. The first 3 channels of the fused tensor store the pixel data of the image block to be detected, and the fourth channel of the fused tensor stores the confidence data of the abnormal thermal image block.
[0051] In this embodiment, by performing a fusion operation between the image block to be detected and the abnormal thermal image block, pixel-level strong coupling between the visual information of the image block to be detected and the confidence information of the abnormal thermal image block can be achieved. The appearance features and defect probability information at the same spatial location are integrated into the same fusion tensor, making full use of the abnormal prior information of the abnormal thermal image block and improving the accuracy of subsequent defect classification.
[0052] S160. Input the fusion tensor into the defect classification network to obtain the corresponding defect category of the candidate anomaly region, and output the parameter information of the candidate anomaly region and the defect category; the parameter information of the candidate anomaly region includes the location information of the candidate anomaly region and the area ratio information of the candidate anomaly region in the image to be detected, and the anomaly detection network and the defect classification network are independent of each other.
[0053] The defect classification network can be understood as a deep learning model for industrial inspection scenarios. It extracts texture grayscale morphological features and anomaly confidence data for different defect types by inputting a fusion tensor of the image patch to be inspected and an abnormal thermal image patch, thus completing the defect category determination and automatically identifying and classifying defects in various products, outputting the defect category results.
[0054] The defect classification network includes at least one of ResNet, EfficientNet, ConvNeXt, or VisionTransformer.
[0055] For example, the fusion tensor of the image patch to be detected and the abnormal thermal image patch of the tobacco leaf to be detected is used as input. The defect features in the fusion tensor are learned and judged by the EfficientNet defect classification network, and the result is the judgment of whether the tobacco leaf to be detected has defects.
[0056] Among them, defect categories can refer to different defect classifications based on the abnormal appearance of tobacco leaves, used to distinguish various types of quality damage to tobacco leaves. For example, insect damage, lesions, mold, cracks, scratches, contamination, foreign matter, and corrosion appearing in the image of the tobacco leaf to be inspected belong to different defect categories.
[0057] The parameter information of the candidate anomaly region refers to quantitative parameters characterizing the location and coverage of defects within the image to be detected. This parameter information is generated based on the pixel coordinate system of the image to be detected and includes coordinate information and area proportion. The area proportion is the ratio of the total number of pixels in the candidate anomaly region to the total number of pixels in the image to be detected, used to quantitatively reflect the relative size of the anomaly.
[0058] For example, the coordinate information of the candidate abnormal region is expressed by the center coordinates combined with the height and width. The center coordinates are (420, 190), the width of the candidate abnormal region is 140, the height of the candidate abnormal region is 140, the actual number of pixels in the candidate abnormal region is 8200, and the total number of pixels in the image to be detected is 19600. Therefore, the area ratio is 42%, and the defect degree of this abnormal situation is judged to be relatively serious.
[0059] For example, the input is the fusion tensor of the image patch to be detected and the abnormal thermal image patch. The ResNet network is used to extract the leaf texture, color, morphology features and confidence information features. The feature operation and mapping are completed through a fully connected layer, and the defect category corresponding to the image patch to be detected is output, such as insect-damaged leaves, diseased leaves, and scorched leaves. At the same time, the coordinate information and area ratio of the candidate abnormal region corresponding to the image patch to be detected are also output, so as to realize the automatic identification and classification of tobacco leaf appearance defects.
[0060] In this embodiment, the fusion tensor containing heatmap confidence prior information is fed into the defect classification network for feature extraction. This can uncover the correlation between image visual information and prior information, improve the accuracy of various defect classifications in tobacco leaves, obtain defect attribution information and parameter information of abnormal areas, and provide a reliable basis for subsequent tobacco leaf quality assessment and grading.
[0061] This application provides a method for classifying defects in tobacco leaf images. The method involves acquiring an image to be inspected, processing the image using an anomaly detection network to obtain an anomaly heatmap corresponding to the image, where the image to be inspected is a photograph of an industrial product, and the anomaly heatmap characterizes the degree of anomaly at various spatial locations. Candidate anomaly regions are extracted from the anomaly heatmap, and the location information of these candidate anomaly regions, including their coordinates within the coordinate system of the image to be inspected, is obtained. The candidate anomaly regions are then expanded to obtain a first expanded region, which includes the candidate anomaly region and its neighborhood context region. The first expanded region is based on the candidate anomaly region. The process involves: 1) Contextual expansion of the region boundary; 2) Using the location information of the first expanded region, cropping the image to be detected and the corresponding anomaly heatmap to obtain an image block to be detected and an anomaly heatmap block. The location information of the first expanded region includes the region coordinates of the first expanded region in the coordinate system of the image to be detected; 3) Fusing the image block to be detected and the anomaly heatmap block along the channel dimension to obtain a fusion tensor; 4) Inputting the fusion tensor into a defect classification network to obtain the corresponding defect category of the candidate anomaly region, and outputting the parameter information of the candidate anomaly region and the defect category; 5) The parameter information of the candidate anomaly region includes the location information of the candidate anomaly region and the area ratio information of the candidate anomaly region in the image to be detected. The anomaly detection network and the defect classification network are independent of each other. This technical solution obtains contextual information by expanding candidate abnormal regions, and simultaneously crops and merges the abnormal expanded regions in the image to be detected and the abnormal heat map for defect classification. By adopting relatively independent anomaly detection network and defect classification network, a data-level collaborative mechanism between anomaly detection and defect classification can be realized, which can maintain a strict spatial correspondence between the image block to be detected and the abnormal heat map block, thereby improving the defect category discrimination ability.
[0062] Example 2 Figure 2 This is a flowchart of a tobacco leaf image defect classification method according to Embodiment 2 of this application. This embodiment is an optimization based on the above embodiment; solutions not described in detail in this embodiment are found in the above embodiment. Figure 2 As shown, the method in this embodiment of the application specifically includes the following steps: S210. Acquire the image to be detected, process the image to be detected using an anomaly detection network, and obtain an anomaly heatmap corresponding to the image to be detected. The image to be detected is a photograph of the industrial product to be detected, and the anomaly heatmap corresponding to the image to be detected is used to characterize the degree of anomaly at each spatial location.
[0063] S220. Threshold segmentation is performed on the anomaly evaluation scores in the anomaly heatmap corresponding to the image to be detected, and connected component analysis is performed on the pixel regions that exceed the threshold to obtain the results of each connected component analysis; the region coordinates of the candidate anomaly region in the coordinate system of the image to be detected are determined according to the results of each connected component analysis.
[0064] The anomaly evaluation score refers to the quantized value output pixel by pixel of the image to be detected. This quantized value is calculated based on the degree of deviation of local image features from preset standard features. The greater the deviation between local image features and preset standard features, the higher the output anomaly evaluation score; the smaller the deviation, the lower the output anomaly evaluation score. The anomaly evaluation score is constrained within a fixed range. The upper limit of the range represents the maximum degree of deviation of local features from preset standard features, and the lower limit represents a perfect match between local features and preset standard features.
[0065] For example, the anomaly evaluation score is set to a range of 0 to 1. If the deviation between the first local image feature and the preset standard feature in the image to be detected is large, the anomaly evaluation score of the pixel corresponding to the first local image feature is 0.91; if the deviation between the second local image feature and the preset standard feature is small, the anomaly evaluation score of the pixel corresponding to the second local image feature is 0.08.
[0066] The connected component analysis can include classifying all pixels in the abnormal heatmap with an abnormal evaluation score higher than the preset segmentation threshold as foreground and pixels with an abnormal evaluation score lower than the preset segmentation threshold as background, thus obtaining a binary image corresponding to the abnormal heatmap. Then, based on the pixel adjacency relationship, all foreground pixels in the binary image are traversed, and foreground pixels that are adjacent to each other in the binary image are combined into an independent connected region. Foreground pixels that are not connected to each other are divided into different regions, and statistical information such as the area and center coordinates of each independent connected region are output.
[0067] For example, with a preset segmentation threshold of 0.7, pixels with anomaly scores greater than 0.7 in the anomaly heatmap are marked as foreground, and pixels with anomaly scores less than or equal to 0.7 in the anomaly heatmap are marked as background, generating a binary image. The binary image is traversed, and connectivity is determined using 8-adjacency. Two independent connected regions are segmented from the binary image, and the area of the first independent connected region is calculated to be 126 pixels with center coordinates (142, 96), and the area of the second independent connected region is calculated to be 41 pixels with center coordinates (318, 207).
[0068] S230. Using the center position of the candidate abnormal region as a reference, expand the width and height of the candidate abnormal region according to a preset expansion coefficient; the preset expansion coefficient is greater than 1.
[0069] The center position of the candidate anomaly region can refer to the geometric center of the bounding rectangle of the candidate anomaly region, which is determined by the coordinates of the midpoint of the bounding rectangle in the horizontal and vertical directions. This center position depends on the boundary range of the bounding rectangle and is independent of the specific distribution of pixels within the candidate anomaly region.
[0070] For example, the candidate anomaly region contains 154 foreground pixels. The bounding rectangle of this candidate anomaly region is extracted. The x-coordinate range of the bounding rectangle is 189-265, and the y-coordinate range is 98-172. The arithmetic mean of the maximum and minimum x-coordinates of the bounding rectangle is taken to obtain the center x-value, and the arithmetic mean of the maximum and minimum y-coordinates of the bounding rectangle is taken to obtain the center y-value. The calculated center coordinates of the candidate anomaly region are (227, 135).
[0071] Specifically, when the size of the extended region for the candidate abnormal region exceeds the effective range of the image to be detected, the extended portion is cropped to within the boundary of the image to be detected.
[0072] For example, in the coordinate system of the image to be detected, the effective horizontal coordinates range from 0 to 100. The horizontal coordinate of the left boundary of the first extended region is -5, which falls outside the image to be detected; the horizontal coordinate of the left boundary of the first extended region is forcibly modified to the minimum horizontal coordinate of the image to be detected, 0, while the boundaries of the first extended region that have not crossed the boundary retain their original values.
[0073] In response to the difference in pixel resolution between the abnormal heatmap corresponding to the image to be detected and the image to be detected, the location information of the first extended region is mapped to the abnormal heatmap corresponding to the image to be detected based on the spatial scale mapping relationship between the abnormal heatmap corresponding to the image to be detected and the image to be detected, so that the cropped image block to be detected and the abnormal heatmap block correspond to the same spatial region.
[0074] If the resolution of the anomaly heatmap output by the anomaly detection network is lower than that of the image to be detected, two equivalent methods can be used to maintain spatial alignment between the image block to be detected and the anomaly heatmap block: First, the anomaly heatmap can be upsampled to the resolution of the image to be detected using an interpolation method, and then synchronously cropped using the first extended region; second, based on the proportional relationship between the size of the image to be detected and the size of the anomaly heatmap, the first extended region can be mapped to the coordinate system of the anomaly heatmap to crop out the anomaly heatmap block, and then the size of the anomaly heatmap block can be adjusted to be the same as that of the image block to be detected.
[0075] For example, an anomaly detection network is used to process a 640×480 pixel image to obtain an anomaly heatmap with a pixel size of 160×120. Based on the pixel width and height of the image to be detected and the anomaly heatmap, a horizontal scaling ratio of 4 and a vertical scaling ratio of 4 are calculated. The coordinates of the first extended region on the image to be detected are divided by these horizontal and vertical scaling ratios, respectively, completing the transformation mapping from the coordinate space of the image to the coordinate space of the anomaly heatmap. This ensures that the image block to be detected cropped from the first extended region corresponds to the same spatial region as the anomaly heatmap block.
[0076] Among them, the candidate anomaly region is ,in The center coordinates of this candidate anomaly region. The width of the candidate anomaly region. The height of the candidate anomaly region; the preset expansion coefficient is... and The center coordinates of the first expanded region are maintained. The width and height of the first expanded region remain unchanged, and are updated as follows: and .
[0077] For example, the original width of the bounding rectangle of the candidate anomaly region is 40 pixels, the original height is 30 pixels, and the expansion factor is preset to 1.2. Taking the center position of the bounding rectangle of the candidate anomaly region as the reference, 4 pixels are added to the left and right sides respectively, and 3 pixels are added to the top and bottom sides respectively, resulting in a first expanded region with an expanded width of 48 pixels and a height of 36 pixels.
[0078] S240. Using the location information of the first extended region, the image to be detected and the abnormal heat map corresponding to the image to be detected are cropped to obtain the image block to be detected and the abnormal heat map block. The location information of the first extended region includes the region coordinates of the first extended region in the coordinate system of the image to be detected.
[0079] S250. When the image block to be detected is an RGB three-channel image, the normalized abnormal thermal image block is used as an additional channel and spliced with the RGB three-channel data corresponding to the image block to be detected along the channel dimension to form a four-channel fusion tensor.
[0080] The normalized abnormal thermal image block can be understood as a normalization operation performed by calculating the maximum, minimum, or average value of all pixels in the abnormal thermal image block. For example, the values of all pixels in the abnormal thermal image block are obtained, and the maximum and minimum values corresponding to the pixels in the abnormal thermal image block are calculated. Alternatively, the average value of the pixels in the abnormal thermal image block can be calculated. Then, each pixel in the abnormal thermal image block is normalized using this maximum, minimum, or average value to obtain the normalized abnormal thermal image block.
[0081] For example, the three RGB channels of the image patch to be detected are concatenated with one channel of the normalized anomalous heatmap image patch along the channel dimension to form a four-channel fusion tensor. This fusion tensor is then input into the ResNet50 defect classification network for feature extraction, enabling the ResNet50 defect classification network to simultaneously utilize the local appearance of the image to be detected and the prior information of the anomalous heatmap during subsequent convolutional processing and high-level semantic feature learning.
[0082] S260. Input the fusion tensor into the defect classification network to obtain the corresponding defect category of the candidate anomaly region, and output the parameter information of the candidate anomaly region and the defect category; the parameter information of the candidate anomaly region includes the location information of the candidate anomaly region and the area ratio information of the candidate anomaly region in the image to be detected, and the anomaly detection network and the defect classification network are independent of each other.
[0083] The abnormal location and intensity information represented by the abnormal heatmap corresponding to the image to be detected in the fusion tensor, together with the texture, color and edge information in the image to be detected, participate in the defect category determination during the feature extraction process of the defect classification network.
[0084] For example, the features of the tobacco leaf image patch to be detected carry information such as surface texture, grayscale changes, and edge details, reflecting the true appearance of the image patch. The features of the abnormal thermal image patch carry the location coordinates of the defect area and the degree of anomaly confidence. The fusion tensor contains the features of the image patch to be detected and the features of the abnormal thermal image patch, integrating appearance detail information and defect saliency indication information. The defect classification network relies on the multi-source information in this fusion tensor to complete the defect category discrimination.
[0085] When the number of input channels of the defect classification network is inconsistent with the number of channels of the fusion tensor, a channel adaptation transformation can be performed on the channel dimension of the fusion tensor to match the number of input channels of the defect classification network. For example, a 1×1 convolutional layer can be added to the defect classification network before feature extraction from the fusion tensor. The convolutional operation of this layer maps the channel dimension of the fusion tensor. When the number of channels of the fusion tensor is greater than the number of input channels of the defect classification network, channel dimensionality reduction is achieved; when the number of channels of the fusion tensor is less than the number of input channels of the defect classification network, channel dimensionality increase is achieved, so that the number of output channels of this convolutional layer matches the number of input channels of the defect classification network.
[0086] When the abnormal heatmap corresponding to the image to be detected contains multiple independent abnormal connected regions, candidate abnormal regions corresponding to each abnormal connected region are obtained respectively, and each candidate abnormal region is expanded to obtain the first expanded region corresponding to each candidate abnormal region. Based on each first expanded region, the image block to be detected and the abnormal heatmap image block corresponding to each first expanded region are cropped. The image blocks to be detected and the abnormal heatmap image blocks of each group are fused and input into the defect classification network to obtain the defect category, location information and area ratio of each candidate abnormal region in the image to be detected.
[0087] For example, when the image of a tobacco leaf to be detected contains multiple mutually separated anomalous connected components, candidate anomalous regions are generated for each connected component, and context expansion is performed on each candidate anomalous region to obtain multiple first expanded regions. For each expanded region, image blocks to be detected and anomalous thermal image blocks are simultaneously cropped from the image to be detected and the anomalous thermal image map. The images to be detected and anomalous thermal image blocks of each group are fused and input into the defect classification network, thereby obtaining the category, location coordinates, and area proportion of multiple defects on the image to be detected.
[0088] This application provides a method for classifying defects in tobacco leaf images. The method involves acquiring an image to be inspected, processing the image using an anomaly detection network to obtain an anomaly heatmap corresponding to the image, where the image is a photograph of an industrial product to be inspected, and the anomaly heatmap representing the degree of anomaly at various spatial locations. Thresholding is performed on the anomaly evaluation scores in the anomaly heatmap, and connected component analysis is performed on pixel regions exceeding the threshold to obtain the analysis results. Based on the analysis results, the coordinates of candidate anomaly regions in the coordinate system of the image to be inspected are determined. Using the center position of the candidate anomaly region as a reference, the width and height of the candidate anomaly region are expanded according to a preset expansion coefficient greater than 1. The location information of the first expanded region is used to classify... The image to be detected and the corresponding anomaly heatmap are cropped to obtain an image block to be detected and an anomaly heatmap. The location information of the first extended region includes the region coordinates of the first extended region in the coordinate system of the image to be detected. When the image block to be detected is an RGB three-channel image, the normalized anomaly heatmap is used as an additional channel and concatenated with the corresponding RGB three-channel data of the image block to be detected along the channel dimension to form a four-channel fusion tensor. The fusion tensor is input into the defect classification network to obtain the corresponding defect category of the candidate anomaly region, and the parameter information of the candidate anomaly region and the defect category are output. The parameter information of the candidate anomaly region includes the location information of the candidate anomaly region and the area ratio information of the candidate anomaly region in the image to be detected. The anomaly detection network and the defect classification network are independent of each other. This technical solution, by extending the context based on the center position of the candidate anomaly region, can prevent the loss of contextual information such as texture, edge transition or organizational structure around the defect. Based on the extended region, it synchronously crops out the spatially corresponding image block to be detected and the anomalous thermal image block, so that the appearance information of each extended region can be matched with the prior of the anomaly intensity, and a stable coupling relationship can be established, which can achieve accurate identification of the defect category.
[0089] Example 3 Figure 3 This is a schematic diagram of a tobacco leaf image defect classification device according to Embodiment 3 of this application. This embodiment is applicable to industrial product quality inspection and defect classification scenarios. The tobacco leaf image defect classification device can be implemented in software and / or hardware, optionally through electronic devices such as mobile terminals, personal computers, or servers. Figure 3 As shown, the device includes: The image acquisition module 310 is used to acquire an image to be detected, process the image to be detected using an anomaly detection network, and obtain an anomaly heatmap corresponding to the image to be detected. The image to be detected is a photograph of an industrial product to be detected, and the anomaly heatmap corresponding to the image to be detected is used to characterize the degree of anomaly at each spatial location. The coordinate acquisition module 320 is used to extract candidate abnormal regions from the abnormal heatmap corresponding to the image to be detected, and to acquire the location information of the candidate abnormal regions, wherein the location information of the candidate abnormal regions includes the region coordinates of the candidate abnormal regions in the coordinate system of the image to be detected. The region expansion module 330 is used to expand the candidate anomaly region to obtain a first expanded region. The first expanded region includes the candidate anomaly region and the neighborhood context region of the candidate anomaly region. The first expanded region is obtained by expanding the region boundary context based on the candidate anomaly region. The image block cropping module 340 is used to crop the image to be detected and the abnormal heat map corresponding to the image to be detected using the spatial coordinates of the position information of the first extended region to obtain the image block to be detected and the abnormal heat map. The position information of the first extended region includes the region coordinates of the first extended region in the coordinate system of the image to be detected. Tensor fusion module 350 is used to fuse the image block to be detected and the abnormal thermal image block along the channel dimension to obtain a fused tensor; The defect classification module 360 is used to input the fused tensor into the defect classification network to obtain the corresponding defect category of the candidate anomaly region, and output the parameter information of the candidate anomaly region and the defect category; the parameter information of the candidate anomaly region includes the location information of the candidate anomaly region and the area ratio information of the candidate anomaly region in the image to be detected, and the anomaly detection network and the defect classification network are independent of each other.
[0090] In this embodiment of the application, the coordinate acquisition module 320 includes: Threshold segmentation is performed on the anomaly evaluation scores in the anomaly heatmap corresponding to the image to be detected, and connected component analysis is performed on the pixel regions that exceed the threshold to obtain the analysis results of each connected component. The coordinates of the candidate abnormal region in the coordinate system of the image to be detected are determined based on the analysis results of each connected component.
[0091] In this embodiment of the application, the region expansion module 330 includes: Based on the center position of the candidate anomaly region, the width and height of the candidate anomaly region are expanded according to a preset expansion coefficient; the preset expansion coefficient is greater than 1. When the size of the extended region for the candidate abnormal region exceeds the effective range of the image to be detected, the extended portion will be cropped to within the boundary of the image to be detected.
[0092] In this embodiment of the application, the image patch cropping module 340 further includes: In response to the difference in pixel resolution between the abnormal heatmap corresponding to the image to be detected and the image to be detected, the location information of the first extended region is mapped to the abnormal heatmap corresponding to the image to be detected based on the spatial scale mapping relationship between the abnormal heatmap corresponding to the image to be detected and the image to be detected, and the cropped image block to be detected corresponds to the same spatial region as the abnormal heatmap block.
[0093] In this embodiment of the application, the tensor fusion module 350 includes: When the image block to be detected is an RGB three-channel image, the normalized abnormal thermal image block is used as an additional channel and spliced with the RGB three-channel data corresponding to the image block to be detected along the channel dimension to form a four-channel fusion tensor.
[0094] In this embodiment of the application, the defect classification module 360 includes: The abnormal location and intensity information represented by the abnormal heatmap corresponding to the image to be detected in the fusion tensor, together with the texture, color and edge information in the image to be detected, participate in the defect category determination during the feature extraction process of the defect classification network.
[0095] In this embodiment of the application, the defect classification module 360 includes: The anomaly detection network includes an industrial anomaly detection network capable of outputting pixel-level or region-level anomaly evaluation scores and forming anomaly heatmaps; the defect classification network includes at least one of ResNet, EfficientNet, ConvNeXt, or VisionTransformer.
[0096] The tobacco leaf image defect classification device provided in this embodiment of the invention can execute the tobacco leaf image defect classification method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method.
[0097] Example 4 Figure 4 This is a schematic diagram of the structure of an electronic device that implements the tobacco leaf image defect classification method provided in Embodiment 4 of this application, as shown below. Figure 4The diagram illustrates a schematic representation of an electronic device 10 that can be used to implement embodiments of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0098] like Figure 4 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., which is communicatively connected to the at least one processor 11. The memory stores a computer program that can be executed by the at least one processor 11, and the computer program is executed by the at least one processor 11 to enable the at least one processor 11 to perform the method provided by the present invention.
[0099] The processor 11 can perform various appropriate actions and processes based on a computer program stored in the read-only memory (ROM) 12 or a computer program loaded from the storage unit 18 into the random access memory (RAM) 13. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0100] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0101] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as the methods provided in this invention.
[0102] In some embodiments, the methods provided herein may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the methods described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to execute the methods by any other suitable means (e.g., by means of firmware).
[0103] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard parts (ASSPs), systems-on-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0104] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0105] In the context of this invention, a computer-readable storage medium stores computer instructions that are used to cause a processor to execute and implement the method provided by this invention.
[0106] The present invention also provides a computer program product comprising a computer program that, when executed by a processor, implements the method provided according to embodiments of the present invention. A computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. The computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, the computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0107] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0108] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0109] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0110] This invention also provides a computer program product, including a computer program that, when executed by a processor, can implement the methods provided in any embodiment of this application.
[0111] In the implementation of the computer program product, computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof. Programming languages include object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0112] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0113] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A method for classifying defects in tobacco leaf images, characterized in that, include: An image to be detected is acquired, and the image to be detected is processed using an anomaly detection network to obtain an anomaly heatmap corresponding to the image to be detected. The image to be detected is a photograph of the industrial product to be detected, and the anomaly heatmap corresponding to the image to be detected is used to characterize the degree of anomaly at each spatial location. Candidate abnormal regions are extracted from the abnormal heatmap corresponding to the image to be detected, and the location information of the candidate abnormal regions is obtained, wherein the location information of the candidate abnormal regions includes the region coordinates of the candidate abnormal regions in the coordinate system of the image to be detected. The candidate anomaly region is expanded to obtain a first expanded region. The first expanded region includes the candidate anomaly region and the neighborhood context region of the candidate anomaly region. The first expanded region is obtained by expanding the region boundary context based on the candidate anomaly region. Using the location information of the first extended region, the image to be detected and the corresponding abnormal heat map are cropped to obtain the image block to be detected and the abnormal heat map block. The location information of the first extended region includes the region coordinates of the first extended region in the coordinate system of the image to be detected. The image block to be detected and the abnormal thermal image block are fused along the channel dimension to obtain a fused tensor; The fusion tensor is input into the defect classification network to obtain the corresponding defect category of the candidate anomaly region, and the parameter information of the candidate anomaly region and the defect category are output. The parameter information of the candidate anomaly region includes the location information of the candidate anomaly region and the area ratio information of the candidate anomaly region in the image to be detected. The anomaly detection network and the defect classification network are independent of each other.
2. The method according to claim 1, characterized in that, Extracting candidate abnormal regions from the abnormal heatmap corresponding to the image to be detected, and obtaining the location information of the candidate abnormal regions, includes: Threshold segmentation is performed on the anomaly evaluation scores in the anomaly heatmap corresponding to the image to be detected, and connected component analysis is performed on the pixel regions that exceed the threshold to obtain the analysis results of each connected component. The coordinates of the candidate abnormal region in the coordinate system of the image to be detected are determined based on the analysis results of each connected component.
3. The method according to claim 1, characterized in that, Expanding the candidate anomaly region includes: Based on the center position of the candidate anomaly region, the width and height of the candidate anomaly region are expanded according to a preset expansion coefficient; the preset expansion coefficient is greater than 1. When the size of the extended region for the candidate abnormal region exceeds the effective range of the image to be detected, the extended portion will be cropped to within the boundary of the image to be detected.
4. The method according to claim 1, characterized in that, When cropping the abnormal heatmap corresponding to the image to be detected and the image to be detected using the location information of the first extended region, the method further includes: In response to the difference in pixel resolution between the abnormal heatmap corresponding to the image to be detected and the image to be detected, the location information of the first extended region is mapped to the abnormal heatmap corresponding to the image to be detected based on the spatial scale mapping relationship between the abnormal heatmap corresponding to the image to be detected and the image to be detected, and the cropped image block to be detected corresponds to the same spatial region as the abnormal heatmap block.
5. The method according to claim 1, characterized in that, The process of fusing the image block to be detected with the abnormal thermal image block along the channel dimension includes: When the image block to be detected is an RGB three-channel image, the normalized abnormal thermal image block is used as an additional channel and spliced with the RGB three-channel data corresponding to the image block to be detected along the channel dimension to form a four-channel fusion tensor.
6. The method according to claim 1, characterized in that, The abnormal location and intensity information represented by the abnormal heatmap corresponding to the image to be detected in the fusion tensor, together with the texture, color and edge information in the image to be detected, participate in the defect category determination during the feature extraction process of the defect classification network.
7. The method according to claim 1, characterized in that, The anomaly detection network includes an industrial anomaly detection network capable of outputting pixel-level or region-level anomaly evaluation scores and forming anomaly heatmaps; the defect classification network includes at least one of ResNet, EfficientNet, ConvNeXt, or Vision Transformer.
8. A tobacco leaf image defect classification device, characterized in that, The device includes: The image acquisition module is used to acquire the image to be detected, process the image to be detected using an anomaly detection network, and obtain an anomaly heatmap corresponding to the image to be detected. The image to be detected is a photograph of the industrial product to be detected, and the anomaly heatmap corresponding to the image to be detected is used to characterize the degree of anomaly at each spatial location. The coordinate acquisition module is used to extract candidate abnormal regions from the abnormal heatmap corresponding to the image to be detected, and to acquire the location information of the candidate abnormal regions, wherein the location information of the candidate abnormal regions includes the region coordinates of the candidate abnormal regions in the coordinate system of the image to be detected. A region expansion module is used to expand the candidate anomaly region to obtain a first expanded region. The first expanded region includes the candidate anomaly region and the neighborhood context region of the candidate anomaly region. The first expanded region is obtained by expanding the region boundary context based on the candidate anomaly region. The image block cropping module is used to crop the image to be detected and the abnormal heat map corresponding to the image to be detected using the spatial coordinates of the position information of the first extended region to obtain the image block to be detected and the abnormal heat map. The position information of the first extended region includes the region coordinates of the first extended region in the coordinate system of the image to be detected. The tensor fusion module is used to fuse the image block to be detected and the abnormal thermal image block along the channel dimension to obtain a fused tensor; The defect classification module is used to input the fused tensor into the defect classification network to obtain the corresponding defect category of the candidate anomaly region, and output the parameter information of the candidate anomaly region and the defect category; the parameter information of the candidate anomaly region includes the location information of the candidate anomaly region and the area ratio information of the candidate anomaly region in the image to be detected, and the anomaly detection network and the defect classification network are independent of each other.
9. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that are used to cause a processor to execute the method described in any one of claims 1-7.
11. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the method described in any one of claims 1-7.
