Surface defect detection method for organic siraitia grosvenorii raw material
By combining linear polarized ultraviolet imaging and transmission imaging with near-infrared reflection and thermal response analysis, the problem of fuzz interference in the detection of surface defects of monk fruit was solved, enabling accurate detection of defects such as mold, cracks, rot and insect holes, thus improving the accuracy and reliability of detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUILIN SANLENG BIOTECH CO LTD
- Filing Date
- 2026-01-30
- Publication Date
- 2026-04-21
AI Technical Summary
Existing surface defect detection technologies for monk fruit are unable to effectively distinguish between fuzzy interference and genuine defects, leading to missed detections and misjudgments. In particular, it is difficult to distinguish between wrinkled grooves and cracks, sugar spots and rot in the fruit shell based on grayscale characteristics.
By employing linearly polarized ultraviolet imaging combined with transmission imaging and gradient edge analysis, and by suppressing fuzz interference, the defect region is extracted using the depolarization scattering characteristics of mold. Furthermore, multi-angle oblique light image analysis is performed using near-infrared reflection and thermal response parameters to achieve accurate detection of various types of defects.
It significantly reduces the false detection rate, improves the consistency and robustness of test results, can stably distinguish between mold and normal tissue, accurately identify minute cracks, and accurately differentiate defects such as sugar spots, rot and wormholes.
Smart Images

Figure CN121899138A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of defect detection technology, specifically a method for detecting surface defects in organic monk fruit raw materials. Background Technology
[0002] In the post-harvest processing and grading of monk fruit, surface defect detection is a crucial step. Currently, this detection mainly relies on manual visual screening or conventional machine vision technology.
[0003] However, the unique biological morphology and physical characteristics of monk fruit pose significant challenges to existing automated detection technologies. First, the dense, high-density hairs on the surface of monk fruit produce strong diffuse reflection and visual noise under conventional visible light imaging, severely masking early mold growth or minor defects on the peel, leading to missed detections. Second, the dried peel of monk fruit naturally exhibits irregular wrinkles, grooves, and discoloration. These characteristics of high-quality products are geometrically similar to cracks and, in terms of grayscale features, highly overlap with internal rot or insect damage. Existing image processing technologies, mostly based on two-dimensional grayscale or color features, struggle to physically distinguish between "grooves" and "cracks," or "sugar spots" and "rot," easily resulting in a high misjudgment rate, misreporting good products as substandard or mixing diseased fruit into the finished product.
[0004] Furthermore, existing single-spectral detection methods (such as ordinary ultraviolet fluorescence or near-infrared spectroscopy) often neglect the crystalline optical properties of the mogrosides and the scattering medium properties of the fruit shell, lacking targeted decoupling methods for defects of different depths and materials. Therefore, there is an urgent need for a detection method that can physically suppress mogroside interference and accurately distinguish between natural features and real defects.
[0005] Therefore, a method for detecting surface defects in organic monk fruit raw materials is proposed. Summary of the Invention
[0006] The purpose of this invention is to provide a method for detecting surface defects in organic monk fruit raw materials. This method uses linearly polarized ultraviolet imaging to suppress fuzz interference and extract moldy areas, and combines transmission imaging and gradient edge analysis to identify cracks. For dark spot areas, near-infrared and thermal response parameters are fused to distinguish sugar spots, rot, and suspected insect holes. Furthermore, based on multi-angle oblique light images, shallow depressions or deep holes are determined, thus achieving accurate detection of multiple types of defects.
[0007] To achieve the above objectives, the present invention provides the following technical solution: A method for detecting surface defects in organic monk fruit raw materials, comprising: The surface of the monk fruit was irradiated with a linearly polarized ultraviolet light source. The polarization retention characteristics of the fuzz and the depolarization scattering characteristics of the mold were used to obtain an image after suppressing the interference of the fuzz. The local texture entropy was calculated by sliding window, and the low-entropy region was extracted to generate a mold mask. The part after excluding the mold mask region was defined as the defect region of interest. Transmission imaging is performed on the region of interest of the defect, gradient edge detection is performed, and the region that exceeds the preset gradient magnitude threshold and the edge width is less than the preset number of pixels is used as the crack generation crack mask, and the set of coordinates of undetermined dark spots with gentle gradient is extracted. For the set of coordinates of undetermined dark spots, near-infrared reflectance images are collected to obtain near-infrared gray values, and thermal response images are collected to obtain temperature rise values. Based on the near-infrared gray values and temperature rise values, ratio parameters are obtained to distinguish between good quality sugar spots and defective rotten areas, and the coordinates of suspected insect holes with ratio parameters in the middle range are extracted. For suspected insect eye coordinates, image sequences are acquired; the maximum value of the grayscale value of the same pixel at different illumination angles is calculated to determine shallow depressions and / or deep holes on the surface.
[0008] Preferably, the process of acquiring an image after suppressing fuzz interference includes: irradiating the surface of the monk fruit with a linearly polarized ultraviolet light source as the excitation source; setting an analyzer in the imaging optical path, wherein the transmission direction of the analyzer is orthogonal to the polarization direction of the linearly polarized ultraviolet light source; acquiring the image after passing through the analyzer to obtain a reference image after suppressing fuzz interference.
[0009] Preferably, the process of obtaining the mold mask includes: performing sliding window processing on the reference image; extracting grayscale distribution data within each window position; counting the number of pixels at each grayscale level; calculating the occurrence probability of each grayscale level; calculating the local texture entropy value corresponding to the center pixel of the window; obtaining an entropy distribution map covering the entire image; and marking pixel regions below the entropy threshold as low-entropy regions; performing connectivity analysis on the low-entropy regions; extracting connected regions that satisfy the minimum area condition as mold regions; and generating a binarized mold mask; and defining the remaining part of the original image after excluding the mold mask-marked region as the defect region of interest.
[0010] Preferably, the specific process of gradient edge detection includes: performing smoothing filtering on the transmission image within the region of interest of the defect; performing differential operations in the horizontal and vertical directions to obtain horizontal gradient components and vertical gradient components; calculating the gradient magnitude and gradient direction at each pixel location; performing non-maximum suppression processing based on the gradient direction to retain local maxima points and suppress non-edge points; comparing the gradient magnitude with a preset gradient magnitude threshold to extract pixels with gradient magnitudes exceeding the threshold as candidate edge points; and connecting the candidate edge points to form an edge contour to obtain an edge detection result image.
[0011] Preferably, the process of acquiring the crack mask includes: performing morphological analysis on the edge contours in the edge detection result image, calculating the length, width, and aspect ratio of each edge contour; selecting edge contours with an edge width less than a preset number of pixels and an aspect ratio greater than a preset ratio as crack candidate contours; verifying the grayscale features of the crack candidate contours, extracting the grayscale values on both sides of the contour, calculating the grayscale jump variable at the contour, and confirming crack candidate contours exceeding a preset threshold as cracks, generating a binarized crack mask; and extracting centroid coordinates and boundary contour data for the regions in the edge detection result image other than cracks, generating an undefined dark spot coordinate set.
[0012] Preferably, the process of obtaining the ratio parameter includes: Based on the set of coordinates of undetermined dark spots, near-infrared reflectance images are acquired, and the corresponding dark spot regions are located in the near-infrared reflectance images; the near-infrared gray values of each dark spot region are extracted, and the average gray value of the pixels in the region is calculated as the near-infrared response data of the dark spot. After completing the near-infrared image acquisition, a short-time pulsed light excitation is applied to the surface of the monk fruit, and a thermal response image is acquired after a preset delay time; the temperature data corresponding to the dark spot area in the thermal response image is extracted, and the temperature rise value of the area relative to the background temperature is calculated; For each dark spot, a ratio parameter is constructed based on the temperature rise value and the corresponding near-infrared response data. Dark spots with a ratio parameter lower than the first ratio threshold are identified as good quality sugar spots, dark spots with a ratio parameter higher than the second ratio threshold are identified as defective rotten areas, and dark spots with a ratio parameter between the two thresholds are marked as suspected insect eyes. The coordinate data of suspected insect eyes are extracted.
[0013] Preferably, the specific acquisition process of the image sequence includes: Multiple oblique light sources are set up around the monk fruit, with the angle between the optical axis of the oblique light source and the normal to the surface of the monk fruit within a preset angle range; the oblique light sources in each direction are turned on one at a time; when each light source is turned on, an image of the surface of the monk fruit is acquired to obtain a single frame image of the corresponding illumination direction; the light source switching and image acquisition process is repeated until the illumination and image acquisition of all preset light sources are completed, resulting in an image sequence containing multiple images of different illumination directions.
[0014] Preferably, the determination process for surface shallow depressions and / or deep hole defects includes: for each suspected insect eye coordinate location, extracting grayscale value data of the coordinates at various illumination angles from the image sequence; performing a maximum value calculation on the grayscale value data to obtain the maximum grayscale value of the coordinate location at all illumination angles; comparing the maximum grayscale value with a preset determination threshold; if the maximum grayscale value is higher than the determination threshold, it indicates that direct light can be received at at least one illumination angle, and it is determined to be a surface shallow depression; if the maximum grayscale value is less than or equal to the determination threshold, it indicates that it is in a shadow area and cannot receive direct light at all illumination angles, and it is determined to be a deep hole defect.
[0015] In summary, the present invention adopts the above technical solution, and the present invention has the following technical effects: 1. This invention introduces a linearly polarized ultraviolet light source and an orthogonal polarization analysis imaging structure. Utilizing the physical difference between the polarization-preserving characteristics of the surface fuzz of the monk fruit and the depolarization scattering characteristics of moldy areas, it effectively suppresses strong scattering interference from the fuzz, obtaining a more discriminative reference image. Based on this, a sliding window local texture entropy calculation method is used to identify low-entropy moldy areas, and a mold mask is generated through connectivity and area constraints to avoid misleading defect judgments by fuzz texture and natural color differences. This invention can stably distinguish between moldy and normal tissue even under conditions of complex fruit surface structure and dense fuzz, significantly reducing the false detection rate and improving the consistency and robustness of detection results.
[0016] 2. After excluding moldy areas, this invention introduces a detection strategy combining transmission imaging and gradient edge analysis. Through multi-dimensional geometric and grayscale features such as gradient amplitude, edge width, and aspect ratio, it accurately identifies minute cracks and generates a crack mask. Simultaneously, dark spot areas that do not meet the crack determination criteria are independently extracted as a set of indeterminate dark spot coordinates, avoiding mixed processing of different defect types in the same detection stage. This invention achieves effective decoupling between cracked and non-cracked dark spots, improving the sensitivity of crack detection to small, low-contrast defects, and providing clear and reliable intermediate results for subsequent differential discrimination.
[0017] 3. This invention introduces a joint analysis mechanism of near-infrared reflectance and thermal response information, constructing a ratio parameter based on temperature rise and near-infrared grayscale value to achieve quantitative characterization of the internal structure of dark spots. A dual-threshold strategy is used to clearly distinguish between good quality sugar spots, rot defects, and suspected insect-eaten defects. Furthermore, multi-directional oblique light image sequences are used to perform maximum grayscale response analysis on suspected insect-eaten defects, differentiating shallow depressions from deep holes from a geometric occlusion perspective, significantly improving the accuracy and interpretability of insect-eaten defect identification. Attached Figure Description
[0018] Figure 1This is a schematic diagram of a surface defect detection method for organic monk fruit raw materials provided by the present invention; Figure 2 A schematic diagram illustrating the process of obtaining the ratio parameter provided by the present invention; Figure 3 This is a schematic diagram of the defect determination process provided by the present invention. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and preferred embodiments. However, it should be noted that many details listed in the specification are merely to provide the reader with a thorough understanding of one or more aspects of the present invention, and these aspects of the invention can be implemented even without these specific details.
[0020] Example 1 This invention provides a method for detecting surface defects in organic monk fruit raw materials. It employs a cascaded data flow architecture, using four detection stages to classify and detect defects such as mold, cracks, rot, and insect holes. The output data of each detection stage serves as the input for the next stage, avoiding cross-interference between different types of defects.
[0021] The first stage is the polarization entropy analysis stage. A linearly polarized ultraviolet light source is used to illuminate the surface of the monk fruit. The polarization-preserving properties of the fuzz and the depolarization scattering properties of mold are utilized to obtain an image after suppressing fuzz interference. A sliding window local texture entropy calculation is performed on this image to extract low-entropy regions and generate a mold mask. The portion of the original image excluding the mold mask region is defined as the defect region of interest and transferred to the second stage.
[0022] The second stage is the transmission gradient analysis stage, which involves transmission imaging of the region of interest (ROI) and performing gradient edge detection. Linear regions exceeding a preset gradient magnitude threshold and with an edge width less than a preset number of pixels are identified as cracks, and crack masks are generated. Dark spot regions with gentle gradients are extracted, generating a set of indeterminate dark spot coordinates, which is then passed to the third stage. A gentle gradient is defined as follows: the gradient magnitude of all pixels in a connected region of the transmission image is lower than a preset gradient magnitude threshold, the average gray value of this region is lower than 90% of the surrounding background gray value, and the region area is not less than fifty square pixels. Connected regions that meet these three conditions are identified as indeterminate dark spot regions with gentle gradients.
[0023] The third stage is the photothermal response analysis stage. For each dark spot in the set of undetermined dark spot coordinates, near-infrared reflectance images are acquired to obtain near-infrared grayscale values. After applying pulsed light excitation, thermal response images are acquired to obtain temperature rise values. Based on the near-infrared grayscale values and temperature rise values, ratio parameters are constructed to distinguish between good quality sugar spots and defective rotten areas. The coordinates of suspected insect-eaten eyes with ratio parameters in the middle range are extracted and transferred to the fourth stage.
[0024] The fourth stage is the multi-directional illumination analysis stage. For the coordinates of suspected insect eyes, image sequences are collected under multiple illumination directions. The maximum value of the gray value of the same pixel under different illumination angles is calculated to determine whether the surface is shallow depression or deep hole defect.
[0025] After the inspection is completed, the system outputs a complete defect inspection report, which includes the location information and classification results of moldy areas, cracks, rotten areas and insect holes.
[0026] Technical solution reference Figure 1 The scheme is as follows: The surface of the monk fruit is irradiated with a linearly polarized ultraviolet light source. The polarization-preserving properties of the fuzz and the depolarization scattering properties of mold are used to obtain an image after suppressing fuzz interference. Local texture entropy calculation is performed using a sliding window to extract low-entropy regions and generate mold masks. The portion excluding the mold mask region is defined as the defect region of interest. Transmission imaging is performed on the defect region of interest, and gradient edge detection is executed. Regions exceeding a preset gradient amplitude threshold and with an edge width less than a preset number of pixels are used as crack masks, and a set of coordinates for undetermined dark spots with gentle gradients is extracted. For the set of undetermined dark spot coordinates, near-infrared reflection images are acquired to obtain near-infrared grayscale values, and thermal response images are acquired to obtain temperature rise values. Based on the near-infrared grayscale values and temperature rise values, a ratio parameter is obtained to distinguish between good quality sugar spots and defective rotten areas, and the coordinates of suspected insect-eaten areas with ratio parameters in the middle range are extracted. For the suspected insect-eaten coordinates, image sequences are acquired. The maximum value calculation is performed on the grayscale values of pixels at the same location under different illumination angles to determine shallow surface depressions and / or deep hole defects.
[0027] Furthermore, the process of acquiring the image after suppressing villous interference includes: A linearly polarized ultraviolet light source is used as the excitation source to irradiate the surface of the monk fruit. The linearly polarized ultraviolet light source has a specific polarization direction. An analyzer is set in the imaging optical path. The transmission direction of the analyzer is orthogonal to the polarization direction of the linearly polarized ultraviolet light source. The image after passing through the analyzer is acquired by the imaging device to obtain a reference image after suppressing fuzz interference. Among them, the hairs on the surface of the monk fruit have partial specular reflection characteristics on the incident polarized light. The polarization component retained in the reflected light is the same as or close to the polarization direction of the incident light. This polarization component is blocked by the orthogonally set analyzer. The spores and hyphae in the moldy area produce a scattering effect on the incident polarized light, which causes the polarization state of the reflected light to depolarize. The depolarized scattered light can be received by the imaging device through the analyzer.
[0028] Specifically, a linearly polarized ultraviolet light source is used as the excitation source to irradiate the surface of the monk fruit. The linearly polarized ultraviolet light source includes an ultraviolet light emitting device and a polarizer. The ultraviolet light emitting device can be an ultraviolet light-emitting diode or an ultraviolet lamp. The emitted ultraviolet light is formed into linearly polarized light with a specific polarization direction after passing through the polarizer. The wavelength of the ultraviolet light can be selected in the range of 340 nanometers to 400 nanometers. Ultraviolet light in this wavelength range can effectively excite the optical response differences on the surface of the monk fruit.
[0029] An analyzer is set in the imaging optical path; the analyzer is located in front of the lens of the imaging device and aligned with the optical axis of the lens; the transmission direction of the analyzer is orthogonal to the polarization direction of the linearly polarized ultraviolet light source, that is, the angle between the two is 90 degrees; the orthogonal configuration ensures that, theoretically, only the depolarized light component can pass through the analyzer.
[0030] When linearly polarized ultraviolet light shines on the surface of the monk fruit, different regions produce different optical responses. In the reflection of incident polarized light by the velvety surface, the surface reflection component retains strong polarization characteristics. The polarization component in the reflected light is the same as or close to the polarization direction of the incident light. This polarization component is blocked by the orthogonally set analyzers and cannot enter the imaging device, thus suppressing the velvety signal. The spores and hyphae in the moldy area produce a volume scattering effect on the incident polarized light. The scattering process involves multiple interactions between photons and particles, causing the polarization state of the reflected light to depolarize. The depolarized scattered light contains components in various polarization directions. Among them, the component that is consistent with the transmission direction of the analyzer can be received by the imaging device through the analyzer.
[0031] An image is acquired by an imaging device after passing through an analyzer to obtain a reference image after suppressing lint interference. The imaging device can be a camera sensitive to ultraviolet light or an industrial camera equipped with an ultraviolet filter. In this reference image, the signal in the lint region is significantly suppressed and appears as a dark area, while the signal in the moldy region is preserved and appears as a bright area, thus achieving preliminary separation of lint interference and moldy signals.
[0032] Furthermore, the process of obtaining the mold mask includes: The reference image is subjected to sliding window processing, wherein the sliding window moves pixel by pixel on the image; For each window location, extract the grayscale distribution data within the window, count the number of pixels at each grayscale level, and calculate the probability of occurrence of each grayscale level; Based on the occurrence probability of each gray level, the local texture entropy value corresponding to the center pixel of the window is calculated to obtain the entropy distribution map covering the entire image; Set an entropy threshold and mark pixel regions in the entropy distribution map that are below the entropy threshold as low-entropy regions; Connectivity analysis is performed on the low-entropy region, and the connected regions that meet the minimum area condition are extracted as the moldy regions to generate a binarized moldy mask. Among them, the gray values of the moldy area are concentrated in a specific range, the gray distribution within the window is highly concentrated, the texture changes gently, and the corresponding entropy value is low; the residual fuzz noise points are sparse gray abrupt change points, the gray distribution within the window spans a large range, and the corresponding entropy value is high. The remaining portion of the original image after excluding the mold mask marking area is defined as the defect region of interest.
[0033] Specifically, a sliding window process is applied to the reference image; the size of the sliding window is set, with the window side length set to 7 to 11 pixels, and the specific value is adjusted according to the image resolution and the typical size of the mold patches; the number of pixels in the window should be no less than 49 to ensure the statistical validity of the grayscale histogram; the sliding window moves pixel by pixel on the image, covering each local area of the image in turn.
[0034] For each window location, extract the grayscale distribution data within the window; count the number of pixels at each grayscale level within the window. Assuming the grayscale level range is 0 to 255, the number of pixels at each of the 256 grayscale levels is obtained; divide the number of pixels at each grayscale level by the total number of pixels within the window to calculate the probability of occurrence of each grayscale level.
[0035] Based on the occurrence probability of each gray level, the local texture entropy value corresponding to the center pixel of the window is calculated. The calculation method of the local texture entropy value is as follows: for each gray level with an occurrence probability greater than 0, the product of the probability and the logarithm of the probability to the base 2 is calculated, the sum of the product results of all gray levels is taken as the entropy value. When the gray level distribution in the window is concentrated in a few gray levels, the occurrence probability is concentrated in a few high probability terms, and the entropy value is low. When the gray level distribution in the window is scattered in multiple gray levels, the occurrence probability is scattered in multiple low probability terms, and the entropy value is high.
[0036] Repeat the above calculation process for all pixel positions in the image to obtain an entropy distribution map covering the entire image; the spores and hyphae in the moldy area form a uniform covering layer, which scatters ultraviolet light relatively uniformly, resulting in the gray value distribution of this area in the reflected image being concentrated in the low gray range, with a narrow range of gray level changes, and the calculated local texture entropy value is low; the residual fuzz noise points appear as sparse gray abrupt change points due to incomplete orthogonal polarization filtering, with the gray value distribution within the window spanning a large range, and the calculated local texture entropy value is high.
[0037] The entropy threshold was determined using a statistical method based on calibrated samples. A calibrated sample library containing normal, mildly moldy, and severely moldy samples was collected, and entropy values were calculated and statistically analyzed for all sample images. Normal samples, due to their complex velvety texture, typically exhibit higher peak entropy values; moldy samples, due to uniform spore coverage, typically exhibit lower peak entropy values. The optimal entropy threshold was chosen as the threshold that maximizes the product of sensitivity and specificity in mold detection. A recommended entropy threshold of 3.2 was adopted, allowing adjustment within the range of 2.9 to 3.5 based on actual sample characteristics.
[0038] Set an entropy threshold, which can be set to a value between 3 and 4; mark pixel regions in the entropy distribution map that are below the entropy threshold as low-entropy regions; perform connectivity analysis on the low-entropy regions, using the eight-neighbor connectivity criterion to group spatially adjacent pixels into the same connected region; set a minimum area condition, which can be set to 50 to 100 square pixels, and extract connected regions whose area meets the minimum area condition as moldy regions, filtering out isolated noise points with too small an area; generate a binarized moldy mask, where the pixel value of the moldy region is set to 1, and the pixel value of other regions is set to 0.
[0039] The remaining portion of the original image after excluding the moldy mask marking area is defined as the defect region of interest (ROI). The set of pixel coordinates of the defect ROI is passed to the transmission gradient analysis stage. In subsequent processing, only pixels within the defect ROI are subjected to crack detection to avoid the moldy area being misjudged as a crack.
[0040] Furthermore, the specific process of gradient edge detection includes: Smoothing filtering is applied to the transmission image within the region of interest of the defect to suppress image noise; The smoothed image is subjected to difference operations in the horizontal and vertical directions to obtain the horizontal gradient component and the vertical gradient component. Based on the horizontal and vertical gradient components, the gradient magnitude and gradient direction at each pixel location are calculated. Non-maximum suppression is performed based on the gradient direction, retaining local maxima of the gradient and suppressing non-edge points; The gradient magnitude is compared with a preset gradient magnitude threshold, and pixels whose gradient magnitude exceeds the threshold are extracted as candidate edge points. Connect the candidate edge points to form the edge contour, and obtain the edge detection result map.
[0041] Specifically, the transmission image within the region of interest of the defect is acquired. The transmission image is acquired by: placing a high-brightness broadband light source on the back of the monk fruit, with the light source's spectrum covering the visible light band from 400 to 700 nanometers, and the light source power being sufficient to allow light to penetrate the monk fruit shell; setting an imaging device on the front of the monk fruit to collect the light passing through the monk fruit to form a transmission image; the imaging device adopts a high dynamic range mode and acquires a high dynamic range transmission image by synthesizing multiple exposure times to simultaneously record detailed information of both bright and dark areas.
[0042] The transmission image within the region of interest (ROI) of the defect is smoothed using a Gaussian filter. The kernel size can be set to 3×3 or 5×5 pixels, and the standard deviation parameter is adjusted according to the image noise level. The smoothing filter employs a neighborhood pixel weighted average to suppress random noise in the image. Furthermore, due to the gentle smoothing properties of the Gaussian filter, it preserves the image's edge features.
[0043] The smoothed image is subjected to difference operations in both the horizontal and vertical directions. The horizontal difference operation calculates the gray-level difference between each pixel and its horizontal neighboring pixels to obtain the horizontal gradient component. The vertical difference operation calculates the gray-level difference between each pixel and its vertical neighboring pixels to obtain the vertical gradient component.
[0044] Based on the horizontal and vertical gradient components, the gradient magnitude and gradient direction at each pixel location are calculated. The gradient magnitude is equal to the square root of the sum of the squares of the horizontal and vertical gradient components, reflecting the degree of grayscale change at that location. The larger the gradient magnitude, the more drastic the grayscale change. The gradient direction is equal to the arctangent of the ratio of the vertical gradient component to the horizontal gradient component, reflecting the direction of the fastest grayscale change.
[0045] Non-maximum suppression is performed based on the gradient direction. For each pixel, the positions of adjacent pixels along the gradient direction are determined based on its gradient direction, and the gradient magnitude of the pixel is compared with that of its adjacent pixels. If the gradient magnitude of the pixel is greater than that of its adjacent pixels along the gradient direction, the pixel is retained as a local maximum. Otherwise, the gradient magnitude of the pixel is set to zero, and it is suppressed as a non-edge point. Non-maximum suppression can refine the edges and reduce the edge width to the single-pixel level.
[0046] The gradient magnitude is compared with a preset gradient magnitude threshold. The preset gradient magnitude threshold can be determined using an adaptive method. Based on the statistical distribution of gradient magnitude in the image, the threshold is set to the mean of the gradient magnitude plus two to three times the standard deviation, or it is set to ensure that the number of pixels with gradient magnitudes exceeding the threshold accounts for 2% to 5% of the total number of pixels. Pixels with gradient magnitudes exceeding the threshold are extracted as candidate edge points.
[0047] Candidate edge points are connected, and an edge tracking algorithm is used to search for adjacent candidate edge points along the direction perpendicular to the gradient direction. Spatially adjacent and gradient-direction-continuous candidate edge points are connected to form an edge contour, resulting in an edge detection result map.
[0048] Furthermore, the process of obtaining the crack mask includes: Morphological analysis is performed on the edge contours in the edge detection result image to calculate the length, width, and aspect ratio of each edge contour; Select edge contours whose edge width is less than a preset number of pixels and whose aspect ratio is greater than a preset ratio as candidate crack contours; The candidate crack contour is verified by grayscale features, the grayscale values on both sides of the contour are extracted, and the grayscale jump variable at the contour is calculated. Crack candidate contours whose grayscale jump variables exceed a preset threshold are identified as cracks, and a binarized crack mask is generated. For the dark areas other than cracks in the edge detection result image, extract their centroid coordinates and boundary contour data to generate an undefined dark spot coordinate set.
[0049] Specifically, morphological analysis is performed on the edge contours in the edge detection result image. First, connected regions are marked in the edge detection result image to identify each independent edge contour. Geometric features are extracted for each edge contour, including length, width, and aspect ratio. The length is defined as the dimension of the edge contour along its principal axis, which can be obtained by calculating the length of the longer side of the minimum bounding rectangle of the edge contour. The width is defined as the dimension of the edge contour perpendicular to the principal axis, which can be obtained by calculating the length of the shorter side of the minimum bounding rectangle. The aspect ratio is the ratio of length to width.
[0050] Edge contours that conform to the morphological characteristics of cracks are selected as candidate crack contours. The selection criteria include: the edge width is less than the preset number of pixels, which can be set to 3 to 5 pixels, because cracks appear as thin, dark lines in transmission images, and their width is usually only a few pixels; the aspect ratio is greater than the preset ratio, which can be set to 5 to 10, because cracks have a large aspect ratio and extend in a linear manner; natural grooves are wider and have a relatively smaller aspect ratio, and do not meet the above selection criteria.
[0051] The grayscale features of the candidate crack contours are verified. Along the normal direction of the candidate crack contour, a region of several pixels in width is taken on both sides of the contour, and the average grayscale value of one side and the other side of the contour is calculated respectively. The grayscale jump variable at the contour is calculated, which is the absolute value of the difference between the average grayscale values on both sides. Due to the blocking effect of the air gap on diffuse light at the crack, the light flux at the crack interface drops abruptly, and the grayscale jump variable is large, reaching dozens of grayscale levels. Due to the continuity of the shell medium, the light flux of the natural groove changes only gradually, and the grayscale jump variable is relatively small.
[0052] Set a grayscale jump threshold, which can be set to 20 to 40 grayscale levels; identify crack candidate contours whose grayscale jump exceeds the threshold as cracks; perform binarization on all identified crack contours to generate a crack mask, where the pixel value of the crack area is set to 1 and the pixel value of other areas is set to 0.
[0053] The regions outside the crack mask marking area in the edge detection result image are analyzed to identify dark spot regions with gentle gradients. Dark spot regions are defined as connected regions in the transmission image whose gray values are lower than the surrounding background and whose edge gradients are gentle. The centroid coordinates and boundary contour data of the dark spot regions are extracted. The centroid coordinates are used for localization in the subsequent detection stage, and the boundary contour data are used to determine the pixel range of the dark spot regions. An undefined dark spot coordinate set is generated, in which each element contains the centroid coordinates, boundary contour, and area information of the dark spot, which is then transferred to the photothermal response analysis stage.
[0054] Furthermore, the process of obtaining the ratio parameter refers to... Figure 2 ,include: Based on the set of coordinates of undetermined dark spots, near-infrared reflectance images are first acquired, and the corresponding dark spot regions are located in the near-infrared reflectance images. Extract the near-infrared grayscale value in each dark spot region, and calculate the average grayscale value of the pixels in the region as the near-infrared response data of the dark spot; After completing the near-infrared image acquisition, a short-time pulse light excitation was applied to the surface of the monk fruit, and a thermal response image was acquired after a preset delay time. Extract the temperature data of the location corresponding to the dark spot area in the thermal response image, and calculate the temperature rise of the area relative to the background temperature; For each dark spot, a ratio parameter reflecting the thermophysical properties of the material is constructed based on its temperature rise value and corresponding near-infrared response data. The ratio parameter is related to the material's density and thermal diffusivity. Set a first ratio threshold and a second ratio threshold. Dark spots with a ratio parameter lower than the first ratio threshold are identified as good quality sugar spots. Dark spots with a ratio parameter higher than the second ratio threshold are identified as defective rotten areas. Dark spots with a ratio parameter between the two thresholds are marked as suspected insect holes. Extract the coordinate data of suspected insect holes.
[0055] Specifically, based on the set of coordinates of undetermined dark spots, the location of each dark spot is determined in the detection system; the set of coordinates of undetermined dark spots contains the centroid coordinates and boundary contour information of each dark spot, and the detection system determines the target area that needs to be analyzed for photothermal response based on this information.
[0056] First, near-infrared reflectance images are acquired. These images are obtained by illuminating the surface of the monk fruit with a near-infrared light source. The wavelength of the near-infrared light source can be selected in the range of 800 to 900 nanometers. Near-infrared light in this wavelength range has a certain penetration depth and can reflect the optical properties of the surface and shallow layers of the monk fruit. The imaging device is equipped with appropriate near-infrared filters to receive the near-infrared light reflected from the surface of the monk fruit and form an image. The acquisition of the near-infrared image should be completed before pulsed light excitation to avoid interference from the excitation light on the near-infrared measurement. The corresponding dark spot region is located in the near-infrared reflectance image. The pixel range of the dark spot region is determined based on the boundary contour of the dark spot, and the near-infrared grayscale value of each dark spot region is extracted. The average grayscale value of all pixels in the region is calculated as the near-infrared response data of that dark spot. The near-infrared response data reflects the reflectivity of the region to near-infrared light and is related to the optical absorption characteristics of the material.
[0057] After near-infrared image acquisition, a short-time pulsed light excitation is applied to the surface of the monk fruit. The pulsed light excitation uses a flash lamp or a pulsed halogen lamp, and the pulse width can be set to 2 to 5 milliseconds to input light energy to the surface of the monk fruit in a short time. The light energy is absorbed by the surface of the monk fruit and converted into heat energy, resulting in an increase in surface temperature. The energy density of the pulsed light should be moderate to ensure a detectable temperature rise while avoiding damage to the sample to be tested due to excessive energy. Thermal response images are acquired after a preset delay time. The preset delay time can be set from 30 milliseconds to 80 milliseconds. Within this time window, the temperature rise difference between different materials is more obvious. The physical mechanism is as follows: dense materials have high thermal conductivity, and the heat generated by pulse excitation can be quickly conducted and diffused into the material interior, making it difficult for surface heat to accumulate and resulting in a relatively small surface temperature rise. Loose or porous materials have low thermal conductivity, and heat conduction is hindered. The heat generated by surface excitation mainly accumulates on the surface and near-surface layer, resulting in a relatively large surface temperature rise. Thermal response images are acquired using a thermal imager or an infrared thermal imaging device. The temperature resolution of the thermal imager should be better than 0.1 degrees Celsius to ensure that subtle temperature rise differences can be detected.
[0058] Extract temperature data from the thermal response image corresponding to the dark spot area; locate the corresponding area in the thermal response image based on the boundary contour of the dark spot, and extract the average temperature value of the pixels in the area; at the same time, select the normal area around the dark spot as the background area, and calculate the average temperature value of the background area as the reference temperature; calculate the temperature rise value of the dark spot area relative to the background temperature, that is, the difference between the average temperature of the dark spot area and the average temperature of the background area.
[0059] For each dark spot, a ratio parameter is constructed based on the temperature rise value and the corresponding near-infrared response data. The specific calculation process of the ratio parameter is as follows: First, the near-infrared gray values are normalized by dividing the near-infrared gray value of the dark spot region by the average near-infrared gray value of the normal region in the image to obtain the normalized near-infrared response value. Then, the ratio parameter is calculated, which is equal to the sum of the temperature rise value divided by the normalized near-infrared response value and a small constant. This small constant is usually taken as 0.01 to prevent the denominator from being zero. The physical meaning of this ratio parameter is: under the same light absorption capacity conditions, the greater the relative temperature rise of the material, the larger the ratio parameter, indicating that the material has a poorer thermal diffusion capacity; conversely, the stronger the thermal diffusion capacity, the smaller the ratio parameter.
[0060] The first ratio threshold is the boundary between sugar spots and suspected insect holes, which can be determined based on the ratio parameter distribution of the calibration samples. The second ratio threshold is the boundary between suspected insect holes and rot, also determined based on the calibration samples. Specifically, collect calibration samples of known types, including no fewer than twenty samples each of good quality sugar spots, rot, and insect holes. Perform photothermal response analysis on all samples and calculate the ratio parameters. Statistically analyze the ratio parameter distribution characteristics of the three types of samples. The first ratio threshold is the optimal boundary value between the ratio parameter distribution of sugar spot samples and insect hole samples, with a recommended value of 1.2. The second ratio threshold is the optimal boundary value between the ratio parameter distribution of insect hole samples and rot samples, with a recommended value of 2.8. Dark spots with ratio parameters lower than the first ratio threshold are identified as good quality sugar spots, which are dense areas formed by sugar precipitation during the drying process of monk fruit and belong to normal quality characteristics. Dark spots with ratio parameters higher than the second ratio threshold are identified as defective rotten areas, where cavities or loose structures formed by tissue degradation exist within the rotten areas. Dark spots with ratio parameters between two thresholds are marked as suspected insect eyes. The coordinate data of the suspected insect eyes are extracted and passed to the multi-directional lighting analysis stage.
[0061] Furthermore, the specific acquisition process of the image sequence includes: Multiple oblique light sources are set around the monk fruit. The angle formed by the optical axis of the oblique light source and the normal of the monk fruit surface is within a preset angle range. The selection of the preset angle range is such that shallow depressions with a depth-to-width ratio less than a first depth-to-width ratio threshold can receive direct light at at least one illumination angle, while deep holes with a depth-to-width ratio greater than a second depth-to-width ratio threshold are in the shadow area at all illumination angles. Turn on the oblique light sources from each direction one by one, keeping the other light sources off at a time; When each light source is turned on, an image of the surface of the monk fruit is captured to obtain a single-frame image corresponding to the direction of the light. Repeat the above light source switching and image acquisition process until all preset light source illumination and image acquisition are completed, resulting in an image sequence containing multiple images with different lighting directions; Each frame in the image sequence records the grayscale information of the suspected insect eye coordinates under a specific oblique illumination angle.
[0062] The preset angle range is determined based on the principles of geometric optics. Let the defect be a circular hole or depression with a depth of 'd' and an opening diameter of 'D'. The aspect ratio is defined as 'd' divided by 'D'. The critical condition for oblique light to illuminate the bottom of the hole is that the tangent of the incident angle equals 'D' divided by twice 'd'. For a shallow depression with an aspect ratio of 0.3, the critical incident angle is approximately 59 degrees; for a deep hole with an aspect ratio of 1.0, the critical incident angle is approximately 27 degrees. Therefore, when the incident angle of oblique light is set within the range of 45 to 70 degrees, shallow depressions with an aspect ratio less than 0.3 can be illuminated under certain lighting directions, while deep holes with an aspect ratio greater than 1.0 remain in shadow under all lighting directions.
[0063] Specifically, multiple oblique light sources are set around the monk fruit, distributed in different directions. In this embodiment, the arrangement is in the east, south, west, and north, with the four light sources evenly distributed at 90 degrees relative to the center of the monk fruit. Each oblique light source can be a collimated light source, such as a light-emitting diode module with a Fresnel lens or a collimated halogen lamp, to ensure good beam directionality. The angle formed between the optical axis of each oblique light source and the normal to the surface of the monk fruit is within a preset angle range. The preset angle range is selected based on the aspect ratio characteristics of the defect to be detected; the upper limit of the aspect ratio of shallow depressions is set to 0.3, and the lower limit of the aspect ratio of deep holes is set to 1.0. When the incident angle is greater than the critical angle corresponding to an aspect ratio of 0.3 (approximately 56 degrees), the bottom of shallow depressions with an aspect ratio of less than 0.3 can still be illuminated; when the incident angle is less than the critical angle corresponding to an aspect ratio of 1.0 (approximately 26 degrees), deep holes with an aspect ratio of greater than 1.0 are always in the umbra. Therefore, the preset angle range can be set from 45 degrees to 70 degrees. Within this angle range, the shallow recess can receive direct light at at least one illumination angle, while the deep hole is in the shadow area at all illumination angles.
[0064] During image sequence acquisition, oblique light sources in each direction are turned on individually and sequentially using a sequential control method, lighting up the light sources in the order of east, south, west, and north. Only one light source is turned on at a time, while the other three light sources remain off, ensuring that the shadow features in the image are generated by a light source from a single direction, which facilitates subsequent analysis.
[0065] When each light source is turned on, the imaging device acquires an image of the surface of the monk fruit, obtaining a single-frame image corresponding to the illumination direction. The imaging device can use a grayscale industrial camera, and the exposure parameters are set so that the grayscale value of the normal surface area is in the middle of the dynamic range, neither overexposed nor underexposed. Each single-frame image records the grayscale information of each position on the surface of the monk fruit under the specific oblique illumination angle, including whether the coordinates of the suspected insect eye position are in an illuminated state or a shadow state under the illumination angle.
[0066] The process of switching light sources and acquiring images is repeated, and the illumination and image acquisition of all oblique light sources are completed in sequence according to the preset directional order. In this embodiment, after completing the illumination and image acquisition of four directions, an image sequence containing four frames of images with different illumination directions is obtained. Each frame of the image sequence corresponds to the directional of the light source. The first frame corresponds to the east-facing light source, the second frame corresponds to the south-facing light source, the third frame corresponds to the west-facing light source, and the fourth frame corresponds to the north-facing light source.
[0067] Furthermore, the process for determining shallow surface depressions and / or deep hole defects refers to... Figure 3 ,include: For each suspected insect eye location, extract the grayscale data of that location under various lighting angles from the image sequence; Perform a maximum value calculation on the grayscale data to obtain the maximum grayscale value of the coordinate position under all illumination angles; The maximum grayscale value is compared with a preset judgment threshold; If the maximum gray value is higher than the judgment threshold, it indicates that the location can receive direct light at at least one illumination angle, and is judged as a shallow surface depression. If the maximum gray value is lower than or equal to the judgment threshold, it indicates that the location is in the shadow area under all lighting angles and cannot receive direct light, and is judged as a deep hole defect; Among them, shallow depressions have a small depth-to-width ratio, and the bottom of the depression can be illuminated at certain oblique angles of illumination; deep hole defects have a large depth-to-width ratio, and the bottom of the hole is blocked by the hole wall at all oblique angles of illumination, forming an umbra.
[0068] Specifically, for each suspected insect eye coordinate location, the grayscale value data of that coordinate under various illumination angles is extracted from the image sequence; based on the coordinate information of the suspected insect eye, the corresponding pixel position is located in each frame of the image sequence; since each frame of the image sequence is acquired at the same detection station, the spatial correspondence between each frame is consistent, and the same pixel coordinates can be used directly for positioning; the grayscale value of that position in each frame is read to obtain the grayscale value data set of that coordinate location, which contains four grayscale values, corresponding to the four illumination directions of east, south, west, and north.
[0069] The maximum value operation is performed on the grayscale data. The grayscale values of the same coordinate position under all illumination angles are compared, and the maximum value is selected to obtain the maximum grayscale value of that coordinate position under all illumination angles. The physical meaning of the maximum value operation is that if the position is illuminated by direct light under any illumination angle, the grayscale value of that position in the corresponding frame image will be higher. Taking the maximum value can detect whether the position is illuminated under at least one illumination angle.
[0070] The maximum grayscale value is compared with a preset judgment threshold. The judgment threshold is determined as follows: Calibration samples of known types are collected, including no fewer than twenty shallow depression samples and no fewer than twenty deep hole samples. Four-directional illumination image sequences are acquired for each sample. The maximum grayscale value at each defect location is calculated. The distribution of the maximum grayscale value for shallow depression samples and deep hole samples is statistically analyzed separately. The judgment threshold is the optimal boundary between the two distributions. Under standard configuration, a judgment threshold of 20% of the image's grayscale dynamic range is recommended; for an eight-bit image, the grayscale value is approximately fifty to fifty-five.
[0071] The judgment threshold is set based on the difference in grayscale response between shallow surface depressions and deep holes under multi-directional illumination. During the calibration phase, image sequences of known defect types are acquired, and the maximum grayscale value distributions at shallow depression locations and deep hole locations are statistically analyzed. Shallow depression locations are illuminated at at least one illumination angle, resulting in a higher grayscale value distribution; deep hole locations are in shadow at all illumination angles, resulting in a lower grayscale value distribution. The judgment threshold is set at the boundary between these two distributions to minimize the false positive rate. The judgment threshold can be set to 15% to 25% of the image's grayscale dynamic range, with the specific value adjusted according to imaging conditions and light source parameters.
[0072] If the maximum grayscale value is higher than the judgment threshold, it indicates that the location can receive direct light at at least one illumination angle, and is judged as a shallow surface depression. A shallow surface depression has a small depth-to-width ratio, meaning the depression depth is shallower than the depression opening diameter. Taking a shallow depression with a depth-to-width ratio of 0.3 as an example, when the incident angle of oblique light is greater than approximately 56 degrees, the light can illuminate the bottom of the depression. In the four-directional illumination configuration of this embodiment, oblique light from at least one direction can illuminate the bottom of the shallow depression, causing this location to exhibit a higher grayscale value in the corresponding image frame, with the maximum grayscale value exceeding the judgment threshold. Shallow surface depressions are typically natural pits or old, shallow scars on the surface of the monk fruit and do not affect product quality.
[0073] If the maximum grayscale value is lower than or equal to the judgment threshold, it indicates that the location is in the shadow area under all lighting angles and cannot receive direct light, thus being judged as a deep hole defect. The depth-to-width ratio of a deep hole defect is large, and the hole depth is relatively large compared to the hole opening diameter. Taking a deep hole with a depth-to-width ratio of 1.0 as an example, light can only reach the bottom of the hole when the incident angle of oblique light is less than about 26 degrees. However, in this embodiment, the incident angle of oblique light is set in the range of 45 degrees to 70 degrees, which exceeds the critical angle of 26 degrees. Therefore, the bottom of the deep hole is blocked by the hole wall under all lighting angles, forming an umbra. The deep hole location shows a low grayscale value in all image frames, with the maximum grayscale value being lower than or equal to the judgment threshold. Deep hole defects are usually insect holes, which are holes formed by pests boring into the shell of the monk fruit, and are serious defects that affect product quality. After determining the coordinates of all suspected insect holes, the results of each detection stage are summarized, and a complete defect detection report is output. The report includes the location and area of moldy areas, the location and length of cracks, the location and area of rotten areas, and the location and number of insect holes, providing a basis for the quality grading of monk fruit.
[0074] This invention proposes a multi-stage cascaded surface defect detection method for organic monk fruit raw materials. By constructing a clear data flow relationship, it achieves high-precision differentiation and localization of various defects. The method follows a general approach of "elimination first, then subdivision," processing defects such as mold, cracks, rot, and insect holes in stages according to their physical causes and imaging characteristics, avoiding misjudgments caused by the superposition of different defect features. First, linearly polarized ultraviolet imaging and local texture entropy analysis are used to effectively suppress fuzz interference and stably extract moldy areas, ensuring that subsequent detection is performed against a clean background. Second, transmission imaging combined with gradient and morphological feature analysis reliably identifies slender cracks and separates undetermined dark spots. Then, the fusion analysis of near-infrared reflection and pulsed thermal response is introduced to accurately distinguish sugar spots from rot based on the differences in the material's photothermal properties, and to screen for suspected insect holes. Finally, multi-directional oblique illumination and a maximum grayscale determination mechanism are used to distinguish shallow depressions from deep pores from a geometric imaging perspective. The overall solution organically combines optical, thermal, and geometric features, with a clear detection logic and distinct levels. It not only improves the robustness of detection under complex surface conditions but also enhances the physical interpretability of defect classification, providing a systematic and reliable technical path for the quality grading and automated detection of monk fruit.
[0075] Example 2 Based on Example 1, this embodiment further introduces three enhancement technologies: time-series thermal decay analysis, polarization degree quantitative analysis, and defect spatial correlation verification, forming a complete enhanced method for detecting surface defects in monk fruit.
[0076] The detection method in this embodiment also adopts a cascaded data flow architecture, including a polarization entropy analysis stage, a transmission gradient analysis stage, a photothermal response analysis stage, and a multi-directional illumination analysis stage; the basic detection process of each stage is the same as that in the aforementioned embodiment.
[0077] In the polarization entropy analysis stage, this embodiment adds a quantitative polarization degree analysis step during the acquisition of images after suppressing fuzz interference.
[0078] The process of acquiring images after suppressing velvet interference also includes quantitative polarization analysis: A switchable analyzer assembly is added to the imaging optical path, so that the transmission direction of the analyzer can be switched between a first state orthogonal to the polarization direction of the excitation light and a second state parallel to the polarization direction of the excitation light. A first polarization image is acquired in the first state, and a second polarization image is acquired in the second state. Based on the grayscale values of the first polarization image and the second polarization image, the polarization degree value of each pixel position is calculated to generate a polarization degree distribution map; Set an upper limit threshold and a lower limit threshold for polarization degree. Mark regions with polarization degree higher than the upper limit threshold as high polarization-preserving regions and regions with polarization degree lower than the lower limit threshold as low polarization-preserving regions. Areas with high polarization retention were excluded from subsequent testing as areas with residual lint, while areas with low polarization retention were directly marked as high-confidence areas of mold.
[0079] A switchable analyzer assembly is added to the imaging optical path. The analyzer assembly includes an analyzer body and a rotation drive mechanism. The rotation drive mechanism can drive the analyzer body to rotate along its optical axis. The transmission direction of the analyzer can be switched between a first state orthogonal to the polarization direction of the excitation light and a second state parallel to the polarization direction of the excitation light.
[0080] During image acquisition, the analyzer is first switched to the first state to acquire the first polarization image; then, the analyzer is switched to the second state to acquire the second polarization image. Based on the grayscale values of the two polarization images, the polarization degree value for each pixel is calculated. For each pixel, the grayscale value of that location in the two images is extracted, and the absolute value of the difference is calculated and divided by the sum of the grayscale values to obtain the polarization degree value. When the sum of the two grayscale values is less than a preset minimum valid value, the polarization degree of that pixel is set to an invalid value and is not included in subsequent threshold determination. This calculation is repeated for all valid pixel locations to generate a polarization degree distribution map.
[0081] An upper and lower threshold for polarization degree are set. Regions with polarization degree above the upper threshold are marked as high polarization-preserving regions and excluded from subsequent detection as areas with residual fuzz. Regions with polarization degree below the lower threshold are marked as low polarization-preserving regions and directly marked as high-confidence areas of mold. For regions with polarization degree between the two thresholds, the sliding window local texture entropy calculation continues.
[0082] In the photothermal response analysis stage, this embodiment adds a time-series thermal decay analysis step to the process of obtaining the ratio parameter. The process of obtaining the ratio parameter also includes time-series thermal decay analysis. After applying pulsed light excitation, multiple frames of thermal response images are continuously acquired at preset time intervals to obtain a thermal response image sequence. For each dark spot region, the temperature data of that region at each acquisition time is extracted from the thermal response image sequence to obtain the temperature decay data over time. The decay data is fitted to extract the thermal decay time constant; The thermal decay time constant is compared with a preset time constant threshold as an auxiliary verification condition for the ratio parameter determination result. When the ratio parameter determination result is consistent with the thermal decay time constant determination result, the classification result of the dark spot is confirmed; when the two determination results are inconsistent, the dark spot is marked as a region to be reviewed.
[0083] Specifically, after acquiring near-infrared images, a short-duration pulsed light excitation is applied to the surface of the monk fruit. The parameter settings for the pulsed light excitation are the same as in Example 1. Unlike Example 1, in this example, instead of acquiring a single frame of thermal response image after pulsed light excitation, multiple frames of thermal response images are continuously acquired at preset time intervals to obtain a thermal response image sequence.
[0084] The preset time interval can be set from 20 milliseconds to 50 milliseconds, and the number of frames continuously acquired can be set from five to ten frames. Taking a time interval of 30 milliseconds and eight frames acquired as an example, the thermal response image sequence records the temperature distribution at eight time points: 30 milliseconds, 60 milliseconds, 90 milliseconds, 120 milliseconds, 150 milliseconds, 180 milliseconds, 210 milliseconds, and 240 milliseconds after pulse excitation.
[0085] For each dark spot region, temperature data for that region at each acquisition time is extracted from the thermal response image sequence. Based on the boundary contour of the dark spot, the corresponding region is located in each frame of the thermal response image, and the average temperature value of the pixels within that region is calculated to obtain the temperature value sequence of the dark spot at each acquisition time. The ambient background temperature is subtracted from the temperature values at each time point to obtain the temperature decay data over time.
[0086] The decay data is fitted to extract the thermal decay time constant. An exponential decay model is used for fitting, expressing the temperature rise as the product of the initial temperature rise and the decay factor, which decreases exponentially with time. The decay time constant that minimizes the deviation between the fitted curve and the measured data points is determined using the least squares method or other fitting algorithms. The unit of the thermal decay time constant is milliseconds; a larger value indicates slower temperature decay.
[0087] A time constant threshold is set, which can be determined based on the calibration samples. The thermal decay time constant of sugar stain samples is usually less than 100 milliseconds, while that of decay samples is usually greater than 200 milliseconds. The thermal decay time constant is compared with the time constant threshold: if the thermal decay time constant is less than the threshold, it is determined to be a dense material, corresponding to the characteristics of sugar stains; if the thermal decay time constant is greater than the threshold, it is determined to be a loose material, corresponding to the characteristics of decay.
[0088] The thermal decay time constant determination result is used as an auxiliary verification condition for the ratio parameter determination result. When the ratio parameter determination result is consistent with the thermal decay time constant determination result, the classification result of the dark spot is confirmed, and the final determination is output. When the two determination results are inconsistent, it indicates that the material properties of the dark spot are abnormal or in a boundary state. The dark spot is marked as a region to be reviewed and listed separately in the test report.
[0089] Time-series thermal decay analysis incorporates time-dimensional information to extract time constant parameters reflecting the thermal diffusion characteristics of materials. Compared to single-point temperature rise measurements, time-series analysis reduces measurement errors caused by ambient temperature fluctuations and uneven initial surface temperatures. A dual-parameter validation mechanism improves the accuracy and reliability of classifying sugar spots and decay zones.
[0090] After completing the defect detection at each stage, this embodiment adds a defect spatial correlation verification step; specifically, after completing the defect detection at each stage, spatial coordinate data of mold mask, crack mask, rotten area and insect hole location are obtained; Calculate the spatial distance relationship between various defect regions and identify spatially adjacent or overlapping defect combinations; For cases where moldy areas are adjacent to cracks, the cracks are marked as mold-associated cracks; for cases where rotten areas are adjacent to insect holes, the spatial connectivity between the two is verified, and if they are connected, they are merged into a composite defect of insect infestation and rot. For isolated defects with an area smaller than a preset area threshold, their classification results are marked as low confidence and listed separately in the comprehensive inspection report for manual review; Output a comprehensive inspection report that includes defect type, location, area, and related information.
[0091] Specifically, spatial coordinate data of the detection results at each stage is acquired, including the pixel coordinate set of the mold mask, the pixel coordinate set of the crack mask, the boundary contour and centroid coordinates of the rotten area, and the center coordinates of the insect eye location. The spatial coordinate data of various defects are then unified under the same image coordinate system.
[0092] Calculate the spatial distance relationships between various defect regions. For two defect regions, the spatial distance can be calculated using the nearest boundary point distance. This involves extracting the boundary pixels of both regions, calculating the Euclidean distance between all pairs of boundary points, and taking the minimum value as the spatial distance between the two regions. When the spatial distance is less than a preset proximity threshold, the two regions are considered spatially adjacent; when the two regions have pixel overlap, they are considered spatially overlapping. The proximity threshold can be set to ten to twenty pixels.
[0093] Identify spatially adjacent or overlapping defect combinations and perform correlation labeling. For cases where a moldy area is adjacent to a crack, the crack is marked as a mold-associated crack. A mold-associated crack indicates that mold may have penetrated the fruit along the crack; this combined defect is more severe than a single crack defect. For cases where a rotten area is adjacent to an insect-eaten area, further verify their spatial connectivity. Connectivity verification uses a morphological dilation operation, expanding the insect-eaten area outwards by several pixels and determining if the expanded area intersects with the rotten area. If an intersection exists, the two are considered connected and merged into a combined insect-eaten and rotten defect.
[0094] A confidence level assessment is performed on isolated single defects. An isolated defect is defined as one whose spatial distance from any other defect area is greater than a proximity threshold. For isolated single defects with an area smaller than a preset area threshold, their classification result is marked as low confidence. The area threshold can be set to 30 to 50 square pixels. Low-confidence defects are listed separately in the comprehensive inspection report for manual review and confirmation.
[0095] The output includes a comprehensive inspection report with annotations of defect type, location, area, and correlation. The report is categorized by defect type, and for related defect combinations, their symbiotic relationship or composite type is indicated in the report. Low-confidence defects are presented in a separate section at the end of the report, prompting operators to conduct manual review.
[0096] Defect spatial correlation verification analyzes the spatial relationships between various defects, identifies their associated patterns and complex forms, and can more accurately reflect the actual quality of monk fruit. By downgrading the confidence level of isolated minor defects, the false alarm rate can be effectively reduced, and the reliability of the test results can be improved.
[0097] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for detecting surface defects in organic monk fruit raw materials, characterized in that, include: The surface of the monk fruit was irradiated with a linearly polarized ultraviolet light source. The polarization retention characteristics of the fuzz and the depolarization scattering characteristics of the mold were used to obtain an image after suppressing the interference of the fuzz. The local texture entropy was calculated by sliding window, and the low-entropy region was extracted to generate a mold mask. The part after excluding the mold mask region was defined as the defect region of interest. Transmission imaging is performed on the region of interest of the defect, gradient edge detection is performed, and the region that exceeds the preset gradient magnitude threshold and the edge width is less than the preset number of pixels is used as the crack generation crack mask, and the set of coordinates of undetermined dark spots with gentle gradient is extracted. For the set of coordinates of undetermined dark spots, near-infrared reflectance images are collected to obtain near-infrared gray values, and thermal response images are collected to obtain temperature rise values. Based on the near-infrared gray values and temperature rise values, ratio parameters are obtained to distinguish between good quality sugar spots and defective rotten areas, and the coordinates of suspected insect holes with ratio parameters in the middle range are extracted. For suspected insect eye coordinates, image sequences are acquired; the maximum value of the grayscale value of the same pixel at different illumination angles is calculated to determine shallow depressions and / or deep holes on the surface.
2. The method for detecting surface defects in organic monk fruit raw materials according to claim 1, characterized in that, The process of acquiring an image after suppressing fuzz interference includes: using a linearly polarized ultraviolet light source as the excitation source to irradiate the surface of the monk fruit; setting an analyzer in the imaging optical path, wherein the transmission direction of the analyzer is orthogonal to the polarization direction of the linearly polarized ultraviolet light source; acquiring the image after passing through the analyzer to obtain a reference image after suppressing fuzz interference.
3. The method for detecting surface defects in organic monk fruit raw materials according to claim 2, characterized in that, The process of obtaining the mold mask includes: performing sliding window processing on the reference image; extracting grayscale distribution data within each window position; counting the number of pixels at each grayscale level; calculating the occurrence probability of each grayscale level; calculating the local texture entropy value corresponding to the central pixel of the window; obtaining an entropy distribution map covering the entire image; and marking pixel regions below the entropy threshold as low-entropy regions; performing connectivity analysis on the low-entropy regions; extracting connected regions that satisfy the minimum area condition as mold regions; and generating a binarized mold mask; and defining the remaining part of the original image after excluding the mold mask-marked region as the defect region of interest.
4. The method for detecting surface defects in organic monk fruit raw materials according to claim 1, characterized in that, The specific process of gradient edge detection includes: smoothing and filtering the transmission image within the region of interest of the defect; performing differential operations in the horizontal and vertical directions to obtain the horizontal gradient component and the vertical gradient component; calculating the gradient magnitude and gradient direction at each pixel location; performing non-maximum suppression processing based on the gradient direction to retain local maxima points and suppress non-edge points; comparing the gradient magnitude with a preset gradient magnitude threshold to extract pixels with gradient magnitudes exceeding the threshold as candidate edge points; and connecting the candidate edge points to form an edge contour to obtain the edge detection result image.
5. The method for detecting surface defects in organic monk fruit raw materials according to claim 4, characterized in that, The process of acquiring the crack mask includes: performing morphological analysis on the edge contours in the edge detection result image, calculating the length, width, and aspect ratio of each edge contour; selecting edge contours with an edge width less than a preset number of pixels and an aspect ratio greater than a preset ratio as crack candidate contours; verifying the grayscale features of the crack candidate contours, extracting the grayscale values on both sides of the contour, calculating the grayscale jump variable at the contour, and confirming crack candidate contours that exceed a preset threshold as cracks, generating a binarized crack mask; and extracting centroid coordinates and boundary contour data for the regions in the edge detection result image other than cracks, generating an undefined dark spot coordinate set.
6. The method for detecting surface defects in organic monk fruit raw materials according to claim 1, characterized in that, The process of obtaining the ratio parameter includes: Based on the set of coordinates of undetermined dark spots, near-infrared reflectance images are acquired, and the corresponding dark spot regions are located in the near-infrared reflectance images; the near-infrared gray values of each dark spot region are extracted, and the average gray value of the pixels in the region is calculated as the near-infrared response data of the dark spot. After completing the near-infrared image acquisition, a short-time pulsed light excitation is applied to the surface of the monk fruit, and a thermal response image is acquired after a preset delay time; the temperature data corresponding to the dark spot area in the thermal response image is extracted, and the temperature rise of the area relative to the background temperature is calculated; For each dark spot, a ratio parameter is constructed based on the temperature rise value and the corresponding near-infrared response data. Dark spots with a ratio parameter lower than the first ratio threshold are identified as good quality sugar spots, dark spots with a ratio parameter higher than the second ratio threshold are identified as defective rotten areas, and dark spots with a ratio parameter between the two thresholds are marked as suspected insect eyes. The coordinate data of suspected insect eyes are extracted.
7. The method for detecting surface defects in organic monk fruit raw materials according to claim 1, characterized in that, The specific acquisition process of the image sequence includes: Multiple oblique light sources are set up around the monk fruit, with the angle between the optical axis of the oblique light source and the normal to the surface of the monk fruit within a preset angle range; the oblique light sources in each direction are turned on one at a time; when each light source is turned on, an image of the surface of the monk fruit is acquired to obtain a single frame image of the corresponding illumination direction; the light source switching and image acquisition process is repeated until the illumination and image acquisition of all preset light sources are completed, resulting in an image sequence containing multiple images of different illumination directions.
8. The method for detecting surface defects in organic monk fruit raw materials according to claim 7, characterized in that, The process for determining surface shallow depressions and / or deep holes includes: for each suspected insect eye coordinate location, extracting grayscale value data of the coordinates at various illumination angles from the image sequence; performing a maximum value calculation on the grayscale value data to obtain the maximum grayscale value of the coordinate location at all illumination angles; comparing the maximum grayscale value with a preset determination threshold; if the maximum grayscale value is higher than the determination threshold, it indicates that direct light can be received at at least one illumination angle, and it is determined to be a surface shallow depression; if the maximum grayscale value is less than or equal to the determination threshold, it indicates that it is in a shadow area and cannot receive direct light at all illumination angles, and it is determined to be a deep hole defect.