Collected walnut pairing method and device

By comprehensively considering texture similarity, boundary similarity, and color similarity, and combining edge detection and boundary dilation processing, the problems of low efficiency and poor accuracy in matching collectible walnuts are solved, achieving more efficient three-dimensional feature matching and improving the success rate of walnut matching.

CN120953639APending Publication Date: 2025-11-14ZHANGJIAKOU WENJI AGRICULTURAL TECHNOLOGY CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202511059028.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-30
Publication Date
2025-11-14

AI Technical Summary

Technical Problem

Existing technologies for matching collectible walnuts suffer from low efficiency, high subjectivity, and difficulty in scaling up. Furthermore, traditional methods struggle to accurately match the size, shape, texture, and color of walnuts, with a high misjudgment rate, especially under certain lighting conditions and with irregularly shaped walnuts.

Method used

A method that comprehensively considers texture similarity, boundary similarity, and color similarity is adopted. By using edge detection and boundary dilation processing, the 3D feature matching is improved. By combining texture complexity, contour variability, and color dispersion, a multi-dimensional similarity evaluation is achieved.

Benefits of technology

This improves the accuracy and success rate of walnut pairing, enabling more precise matching of suitable "pairs" to meet user needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120953639A_ABST
    Figure CN120953639A_ABST
Patent Text Reader

Abstract

The invention provides a collectable walnut pairing method and device. The method comprises the following steps: classifying a plurality of collection walnuts based on a classification algorithm to obtain a first set; marking the amusement walnuts in the first set as first amusement walnuts; acquiring a first image of the target collection walnut, acquiring a second image of the first collection walnut, and acquiring texture complexity, contour variation and chromaticity dispersion of the second image; calculating texture similarity, color similarity and boundary similarity based on the first image and the second image; determining a texture similarity weight, a boundary similarity weight and a color similarity weight based on the texture complexity, the contour variability and the chromaticity dispersion; and based on the texture similarity, the texture similarity weight, the boundary similarity, the boundary similarity weight, the color similarity and the color similarity weight, determining a first collection walnut most similar to the target collection walnut. According to the invention, high matching between walnuts can be realized more accurately in a complex environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image analysis technology, and in particular to a method and device for matching collectible walnuts. Background Technology

[0002] The value of collectible walnuts lies not only in their variety and appearance, but also in the precision of their "pairing." Pairing refers to matching two walnuts in terms of size, shape, texture, weight, color, and other characteristics to form a "pair," whose market value can be several times or even dozens of times that of a single walnut. Traditionally, the pairing of collectible walnuts relies on manual experience (an average person can process less than 20 pairs per day), which suffers from low efficiency, high subjectivity (the difference in matching results between different technicians is greater than 35%), and difficulty in scaling up.

[0003] With the increasing demand for paired ornamental walnuts, there is an urgent need to achieve intelligent and standardized pairing solutions through technological means. However, the industry faces unique challenges in the process of technological exploration: First, the walnut shell has non-Lambertian reflective properties, and the traditional color histogram method is easily affected by the reflection of the surface patina; Second, irregularly shaped walnuts (such as eagle beak and three-ribbed walnuts) have asymmetrical three-dimensional features, and two-dimensional contour analysis is difficult to quantify the three-dimensional curvature differences of the belly / side / point; Third, the depth and direction of the texture have category specificity.

[0004] Current intelligent matching solutions still rely on single-feature matching, specifically including:

[0005] (1) Color histogram matching: HSV color space histogram comparison is used, and the color difference of walnut skin is evaluated by chi-square distance. In practical applications, it is significantly affected by lighting conditions. The same pair of walnuts may have a misjudgment rate of more than 15% due to different shooting angles.

[0006] (2) Two-dimensional contour analysis and matching: The projected contour of the walnut is extracted by edge detection, and the Hu moment algorithm is used for shape matching. The matching accuracy of this method for irregularly shaped walnuts (such as eagle beak and three-ribbed walnuts) is less than 60%, and it cannot distinguish the three-dimensional features of the belly / side / point.

[0007] (3) Texture feature extraction pairing: The LBP (Local Binary Pattern) algorithm was applied to quantify the texture depth, but the test showed that the discrimination of fine texture was only 0.32 (the ideal value should be >0.8). Summary of the Invention

[0008] This invention provides a method and device for matching walnuts for collecting and playing with, so as to achieve a high degree of matching between walnuts in terms of size, shape, texture, weight, color and other characteristics more accurately in complex environments.

[0009] In a first aspect, embodiments of the present invention provide a method for pairing collectible walnuts, including:

[0010] Based on the walnut classification algorithm, multiple walnuts are classified to obtain the walnuts of the same type as the target walnut, which is denoted as the first set; among them, the target walnut is the walnut that needs to be paired.

[0011] The walnuts in the first set are designated as the first walnut for collecting and playing with.

[0012] Acquire the image of the target ornamental walnut, denoted as the first image; acquire the image of the first ornamental walnut, denoted as the second image; and acquire the texture complexity, contour variability, and chromaticity dispersion of the second image.

[0013] Based on the first image and the second image, calculate texture similarity and color similarity.

[0014] Edge detection algorithms are used to extract edges from the first and second images to obtain the first and second contours, respectively. Boundary dilation is applied to the second contour to obtain the third contour. Boundary similarity is determined based on the first and third contours.

[0015] Based on the texture complexity, contour variability, and chromaticity dispersion of the second image, the texture similarity weight, boundary similarity weight, and color similarity weight are determined.

[0016] Based on texture similarity, texture similarity weight, boundary similarity, boundary similarity weight, color similarity, and color similarity weight, the first collectible walnut most similar to the target collectible walnut is determined.

[0017] In one possible implementation, the second contour is subjected to boundary expansion to obtain the third contour, which includes:

[0018] The second image is converted to a grayscale image, and then Gaussian filtering and contrast enhancement are applied to the grayscale image to obtain the third image.

[0019] The horizontal and vertical gradients of each pixel in the third image are calculated using the Sobel algorithm.

[0020] Calculate the gradient direction of each pixel in the third image based on the horizontal and vertical gradients of each pixel in the third image.

[0021] The gradient direction of each pixel is converted into a unit direction vector to obtain the vector direction of each pixel.

[0022] The second contour is smoothed by using a B-spline fitting algorithm to obtain a smooth contour.

[0023] Calculate the Euclidean distance field from each pixel on the smooth contour to all pixels inside the smooth contour.

[0024] For each pixel on the smooth contour, calculate the product of the pixel value, the preset dilation step size, and the vector direction of the pixel, and record it as the first result. Then, calculate the sum of the Euclidean distance field from the pixel to all pixels inside the smooth contour and the first result to obtain the dilated pixel corresponding to the pixel.

[0025] The third contour is obtained based on the dilated pixels corresponding to all pixels.

[0026] In one possible implementation, boundary similarity is determined based on the first and third contours, including:

[0027] Align the center points of the first contour and the third contour, and calculate the similarity between the first contour and the third contour, which is denoted as the first similarity.

[0028] Rotate the third contour around its center point to obtain the rotated third contour, and calculate the similarity between the rotated third contour and the first contour, which is denoted as the second similarity.

[0029] Multiple rotations of the third contour yield multiple second similarity scores.

[0030] The maximum value among the first similarity and multiple second similarities is used as the boundary similarity.

[0031] In one possible implementation, texture similarity weights, boundary similarity weights, and color similarity weights are determined based on the texture complexity, contour variability, and chromaticity dispersion of the second image, including:

[0032] The second result is obtained by calculating the reciprocal of the sum of the texture complexity, contour variability, and chromaticity dispersion of the second image.

[0033] The texture similarity weight is obtained by multiplying the texture complexity of the first preset range, the second result, and the second image.

[0034] The boundary similarity weight is obtained by multiplying the second preset range, the second result, and the contour variability of the second image.

[0035] The color similarity weight is obtained by calculating the product of the third preset range, the second result, and the color dispersion of the second image.

[0036] In one possible implementation, texture similarity weights, boundary similarity weights, and color similarity weights are determined based on the texture complexity, contour variability, and chromaticity dispersion of the second image, including:

[0037] The third result is obtained by multiplying the first preset parameter by the texture complexity of the second image.

[0038] The difference between the third result and the second preset parameter is calculated to obtain the fourth result.

[0039] Substituting the fourth result as the independent variable into the Sigmoid function yields the fifth result.

[0040] The product of the third preset parameter and the fifth result is calculated to obtain the sixth result.

[0041] The sum of the fourth preset parameter and the sixth result is used as the texture similarity weight.

[0042] The product of the fifth preset parameter and the contour variation of the second image is calculated to obtain the seventh result.

[0043] Calculate the difference between the sixth preset parameter and the seventh power of e to obtain the eighth result.

[0044] The product of the seventh preset parameter and the eighth result is denoted as the boundary similarity weight.

[0045] The product of the eighth preset parameter, the chromaticity dispersion of the second image, and the walnut variety coefficient is used as the color similarity weight.

[0046] In one possible implementation, the texture complexity, contour variability, and chromaticity dispersion of the second image are obtained, including:

[0047] The LBP feature variance is calculated based on the second image using the LBP variance plot.

[0048] The number of edge points and the area of ​​the walnut region are obtained based on the second image using the Canny algorithm.

[0049] The maximum pixel gradient is calculated based on the second image using the Sobel operator.

[0050] Calculate the ratio of the number of edge points to the area of ​​the walnut region, and record it as the ninth result.

[0051] Calculate the sum of the ninth preset parameter and the maximum pixel gradient, and denote it as the tenth result.

[0052] The logarithm of the tenth result to the base 2 is denoted as the eleventh result.

[0053] The product of the LBP feature variance, the ninth result, and the eleventh result is used as the texture complexity.

[0054] The second contour is divided into multiple segments, and the curvature of the second contour and the curvature of each segment are calculated.

[0055] The difference between the curvature of the second contour and the inversion of the curvature of the second contour is denoted as the first difference.

[0056] The L2 norm of the first difference is denoted as the first norm.

[0057] The ratio of the diameter of the first function to the diameter of the second contour is denoted as the twelfth result.

[0058] The difference between the tenth preset parameter and the twelfth result is denoted as the axial symmetry index.

[0059] The product of the eleventh preset parameter and the axial symmetry index is recorded as the thirteenth result.

[0060] The sum of the standard deviations of the curvature of multiple segments and the thirteenth result is used as the profile variability.

[0061] Convert the second image to an HSV image.

[0062] Calculate the standard deviation of pixels in the H channel based on the H channel of the HV image.

[0063] The saturation entropy is calculated based on the S channel in the HSV image.

[0064] Calculate the product of the twelfth preset parameter and the entropy of Shannon, and denote it as the fourteenth result.

[0065] The number of spots is obtained by connecting component analysis based on the V channel in the HSV image.

[0066] The density of the spots is obtained by calculating the ratio of the number of spots to the area of ​​the walnut region.

[0067] Calculate the product of the thirteenth preset parameter and the color spot density, and record it as the fifteenth result.

[0068] The sum of the standard deviation of the pixels in the H channel, the fourteenth result, and the fifteenth result is used as the chromaticity dispersion.

[0069] In one possible implementation, based on a walnut classification algorithm, multiple walnuts are classified to obtain walnuts of the same type as the target walnut, denoted as the first set, which includes:

[0070] Obtain the texture complexity, contour variability, and color dispersion of each of the multiple collectible walnuts, as well as the texture complexity, contour variability, and color dispersion of the target collectible walnut.

[0071] Based on the texture complexity, contour variability, and color dispersion of the target collectible walnut, a collectible walnut classification algorithm is used to determine whether the texture complexity, contour variability, and color dispersion of each collectible walnut in multiple collectible walnuts correspond to the texture complexity, contour variability, and color dispersion of the target collectible walnut.

[0072] For each of the multiple collectible walnuts, if the texture complexity, contour variability, and color dispersion of the collectible walnut correspond to the texture complexity, contour variability, and color dispersion of the target collectible walnut, then the collectible walnut is added to the first set.

[0073] In one possible implementation, an image of the target collectible walnut is acquired, denoted as the first image, including:

[0074] The original image of the target ornamental walnut is obtained, and the original image of the target ornamental walnut is processed by illumination normalization and noise suppression. The main body of the walnut is separated by the GrabCut algorithm. The target ornamental walnut in the processed image is separated to obtain the first image.

[0075] Obtain the image of the first collectible walnut, denoted as the second image, which includes:

[0076] The original image of the first collectible walnut is obtained, and the original image of the first collectible walnut is processed by illumination normalization and noise suppression. The main body of the walnut is separated by the GrabCut algorithm. The first collectible walnut in the processed image is separated to obtain the second image.

[0077] In one possible implementation, based on texture similarity, texture similarity weight, boundary similarity, boundary similarity weight, color similarity, and color similarity weight, the first collectible walnut most similar to the target collectible walnut is determined, including:

[0078] The sum of the product of texture similarity and texture similarity weight, the product of boundary similarity and boundary similarity weight, and the product of color similarity and color similarity weight is used as the similarity between the first and the target ornamental walnuts.

[0079] The first walnut with the highest similarity between the first walnut and the target walnut is considered the first walnut most similar to the target walnut.

[0080] Secondly, embodiments of the present invention provide a walnut pairing device, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the method described in the first aspect or any possible implementation of the first aspect.

[0081] In this embodiment of the invention, the method not only comprehensively considers texture similarity, boundary similarity, and color similarity to evaluate the similarity between collectible walnuts from multiple dimensions, making the evaluation results more accurate, but more importantly, in calculating boundary similarity, it does not simply calculate the two-dimensional similarity between two contours. Instead, it uses a dilation process to expand the contours into three-dimensional data to conduct similarity evaluation. This process realizes the dimensionality upgrade of features, elevating the simple two-dimensional feature similarity calculation to the three-dimensional feature similarity calculation. For example, the expanded contours can reflect the "belly, edge, and tip" of the walnut, as well as the three-dimensional features such as the curvature and thickness of the edge, and the fullness and symmetry of the belly, which are difficult to achieve with traditional two-dimensional contour similarity calculation methods. This solution cleverly integrates three-dimensional features into two-dimensional calculation through the design of this application. Therefore, the calculation results of this solution are more accurate, the matching success rate is higher, and it can match suitable "pairs" for target collectible walnuts, thereby meeting the needs of users. Attached Figure Description

[0082] Figure 1 This is a flowchart illustrating the implementation of the walnut pairing method provided in this embodiment of the invention.

[0083] Figure 2 This is a schematic diagram of the walnut pairing device provided in an embodiment of the present invention. Detailed Implementation

[0084] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.

[0085] See Figure 1 The document illustrates a flowchart of the implementation of the walnut pairing method provided in an embodiment of the present invention, which is described in detail below:

[0086] Step 101: Based on the walnut classification algorithm, classify multiple walnuts to obtain walnuts of the same type as the target walnut, which is denoted as the first set; where the target walnut is the walnut that needs to be paired.

[0087] In one possible implementation, step 101 may include:

[0088] Obtain the texture complexity, contour variability, and color dispersion of each of the multiple collectible walnuts, as well as the texture complexity, contour variability, and color dispersion of the target collectible walnut.

[0089] Based on the texture complexity, contour variability, and color dispersion of the target collectible walnut, a collectible walnut classification algorithm is used to determine whether the texture complexity, contour variability, and color dispersion of each collectible walnut in multiple collectible walnuts correspond to the texture complexity, contour variability, and color dispersion of the target collectible walnut.

[0090] For each of the multiple collectible walnuts, if the texture complexity, contour variability, and color dispersion of the collectible walnut correspond to the texture complexity, contour variability, and color dispersion of the target collectible walnut, then the collectible walnut is added to the first set.

[0091] For example, the specific process of classifying multiple collectible walnuts based on the walnut classification algorithm may include:

[0092] 1. Feature Vector Construction

[0093] The three indices—Texture Complexity Index (TCI), Contour Variability Index (CVI), and Chromatic Dispersion Index (CDI)—are combined into a feature vector: [TCI, CVI, CDI]. Each walnut sample corresponds to one feature vector. For example:

[0094] Sample A: ([0.8,0.3,0.2]) (complex texture, symmetrical shape, uniform color);

[0095] Sample B: ([0.4,0.7,0.5])(simple texture, large morphological differences, and discrete colors).

[0096] 2. Classification boundary optimization

[0097] Objective: To find the maximum margin hyperplane in the feature space to distinguish different varieties.

[0098] Kernel function: Due to the potential for nonlinear boundaries between varieties (such as the mixed characteristics of Hetian walnut and Gongzimao walnut), the RBF kernel (Gaussian kernel) is used to map to a high-dimensional space: K(x i ,x j )=exp(-γ|x i -x j | 2 ), where (γ) is optimized through grid search (typical value range: 0.1≤γ≤1).

[0099] Soft margin treatment: Introduce a slack variable (C) (also known as the penalty coefficient) to balance classification purity and boundary tolerance. Typical value range of (C): (0.1≤C≤10).

[0100] 3. Classification Decision

[0101] Multi-class classification: Extend SVM to multi-variety classification through one-to-one (OvO) or one-to-many (OvR) strategies.

[0102] For example, for the three varieties "Lion's Head", "Four Towers", and "Young Master's Hat", train three binary classifiers (OvO) or one multi-class classifier (OvR).

[0103] Output results: Each sample is assigned to the variety category with the highest probability, for example: P(Lion Head|x)=sigmoid(w·x+b), and the final output is the variety label and confidence level (e.g. "Four Buildings, 98%").

[0104] Step 102: Record the collectible walnuts in the first set as the first collectible walnut.

[0105] Step 103: Obtain the image of the target ornamental walnut, denoted as the first image; obtain the image of the first ornamental walnut, denoted as the second image; and obtain the texture complexity, contour variability, and chromaticity dispersion of the second image.

[0106] For example, texture complexity (TCI) reflects texture density and distribution characteristics; contour variability (CVI) quantifies the three-dimensional morphological differences of the belly / edge / point; and color dispersion (CDI) characterizes the consistency of epidermal color.

[0107] In one possible implementation, acquiring an image of the target walnut for collecting and playing with, denoted as the first image, may include:

[0108] The original image of the target ornamental walnut is obtained, and the original image of the target ornamental walnut is processed by illumination normalization and noise suppression. The main body of the walnut is separated by the GrabCut algorithm. The target ornamental walnut in the processed image is separated to obtain the first image.

[0109] In one possible implementation, acquiring an image of the first collectible walnut, denoted as the second image, may include:

[0110] The original image of the first collectible walnut is obtained, and the original image of the first collectible walnut is processed by illumination normalization and noise suppression. The main body of the walnut is separated by the GrabCut algorithm. The first collectible walnut in the processed image is separated to obtain the second image.

[0111] For example, traditional edge detection methods are susceptible to interference from uneven lighting or surface defects, leading to incorrect segmentation. Therefore, a gray-world assumption white balance with adaptive gamma correction (γ = 0.4-0.6) is used to eliminate color cast and achieve lighting normalization. Frequency domain high-pass filtering (cutoff frequency 8-12Hz) removes shooting jitter, and Gaussian filtering (σ = 1.5) smooths textures, achieving noise suppression. When separating the walnut body using the GrabCut algorithm, the algorithm is improved to fill holes smaller than 5 pixels in the target. In addition, segment matching tolerance is implemented: allowing segment boundary offsets of ±5% pixels to avoid matching failures due to minor perturbations. By combining these four processing methods, accurate separation of the walnut body can be achieved even under conditions of uneven lighting or surface defects, resulting in an accurate image.

[0112] Specifically, a hole is defined as: in a binary mask, there may be isolated black pixels or extremely small black areas (i.e., "holes") within the foreground region (white), where the area of ​​these areas is smaller than a set threshold (5 pixels in this case). Causes: These may be due to errors in segmentation algorithms (such as GrabCut), noise, or misclassification caused by subtle textures on the object's surface (such as the dents or shadows on a walnut).

[0113] For example, it is necessary to ensure that the first image and the second image have the same resolution and size. In addition, it is also necessary to determine the image shooting angle, shooting conditions, etc., to ensure that the acquired images have matching value.

[0114] Specifically, it includes:

[0115] 1. Parameter standardization

[0116] Technical requirements for shooting angle: pitch angle ≤ 10°, rotation angle deviation ≤ 5°.

[0117] The corresponding implementation method is as follows: use a custom clamp to fix the walnut, with the main shaft perpendicular to the camera's optical axis, and mark the direction of the belly / side / point towards the reference line.

[0118] Technical requirements for shooting distance: fixed object distance (30±1cm recommended).

[0119] The corresponding implementation method is: laser rangefinder calibration + mechanical limit device.

[0120] Technical requirements for focal plane positioning: The largest cross-section of the walnut must be parallel to the imaging plane.

[0121] The corresponding implementation method is: dual laser crosshair projectors for assisted positioning.

[0122] 2. Standardization of optical environment

[0123] Technical requirements for light intensity: diffuse light source with a color temperature of 5500±100K and an illuminance of 200±10 lux.

[0124] The corresponding implementation method is: ring-shaped LED shadowless lamp (color rendering index CRI≥95), and closed-loop feedback adjustment of illuminance meter.

[0125] Technical requirements for spectral consistency: D65 standard light source.

[0126] The corresponding implementation method is: real-time calibration using a built-in spectral sensor.

[0127] Technical requirements for reflection suppression: the percentage of reflective points on the surface must be less than 3%.

[0128] The corresponding implementation method is: polarizing filter (linear polarization angle adjustable) + matte black velvet background.

[0129] In one possible implementation, obtaining the texture complexity, contour variability, and chromaticity dispersion of the second image may include:

[0130] The LBP feature variance is calculated based on the second image using the LBP variance map. The LBP feature variance characterizes the local texture variance.

[0131] The number of edge points and the area of ​​the walnut region are obtained based on the second image using the Canny algorithm.

[0132] The maximum pixel gradient is calculated based on the second image using the Sobel operator.

[0133] The ratio of the number of edge points to the area of ​​the walnut-shaped region is calculated and denoted as the ninth result. The ninth result represents the texture density.

[0134] Calculate the sum of the ninth preset parameter and the maximum pixel gradient, and denote it as the tenth result.

[0135] The logarithm of the tenth result, base 2, is denoted as the eleventh result. The eleventh result represents the depth enhancement factor.

[0136] The product of the LBP feature variance, the ninth result, and the eleventh result is used as the texture complexity.

[0137] The second contour is divided into multiple segments, and the curvature of the second contour and the curvature of each segment are calculated.

[0138] The difference between the curvature of the second contour and the inversion of the curvature of the second contour is denoted as the first difference.

[0139] The L2 norm of the first difference is denoted as the first norm.

[0140] The ratio of the diameter of the first function to the diameter of the second contour is denoted as the twelfth result.

[0141] The difference between the tenth preset parameter and the twelfth result is denoted as the axial symmetry index.

[0142] The product of the eleventh preset parameter and the axial symmetry index is recorded as the thirteenth result.

[0143] The sum of the standard deviations of the curvature of multiple segments and the thirteenth result is taken as the profile variability. Here, the standard deviations of the curvature of multiple segments represent the curvature dispersion, and the thirteenth result characterizes the asymmetric penalty term.

[0144] Convert the second image to an HSV image.

[0145] The standard deviation of pixels in the H channel of an HSV image is calculated. The standard deviation of pixels in the H channel represents hue fluctuation.

[0146] The saturation entropy is calculated based on the S channel in the HSV image.

[0147] Calculate the product of the twelfth preset parameter and the entropy of Shannon, and denote it as the fourteenth result.

[0148] The number of spots is obtained by connecting component analysis based on the V channel in the HSV image.

[0149] The density of the spots is obtained by calculating the ratio of the number of spots to the area of ​​the walnut region.

[0150] Calculate the product of the thirteenth preset parameter and the color spot density, and record it as the fifteenth result.

[0151] The sum of the standard deviation of the pixels in the H channel, the fourteenth result, and the fifteenth result is used as the chromaticity dispersion.

[0152] For example, the ninth preset parameter can be 1, the tenth preset parameter can be 1, the eleventh preset parameter can be λ, the twelfth preset parameter can be α, and the thirteenth preset parameter can be β.

[0153] For example, the formula for calculating texture complexity (TCI) can be:

[0154]

[0155] Wherein, σ(LBP) var ) represents the characteristic variance of LBP, N edge Indicates the number of edge points, and A represents the area of ​​the walnut region. Indicates the ninth result, Gradient max This represents the maximum pixel gradient.

[0156] For example, a low TCI (0.2-0.4) indicates the radial pattern (regular shallow pattern) of the Sizuolou walnut; a high TCI (0.6-0.8) indicates the dense deep pit pattern of the Mantianxing walnut.

[0157] For example, the formula for calculating contour variability (CVI) can be:

[0158]

[0159] Among them, K i Let represent the curvature of the i-th segment, 'contour' represent the curvature of the second contour, 'contourfilp' represent the inversion of the curvature of the second contour, '||contour-contourfilp||2' represent the first norm, and 'diameter' represent the diameter of the second contour. ASM def Indicates the axial symmetry index. The standard deviation of the curvature of multiple segments is represented by n, where n represents the number of segments.

[0160] For example, a low CVI (0.1-0.3) indicates the symmetrical outline of the official hat walnut; a high CVI (0.5-0.7) indicates the irregular pointed protrusion of the eagle beak walnut.

[0161] For example, the formula for calculating the color dispersion (CDI) can be:

[0162]

[0163] Where σ(H) represents the standard deviation of pixels in the H channel, Entropy(S) represents the saturation entropy, and N spot Indicates the number of spots.

[0164] For example, a low CDI (0.05-0.1) indicates a uniform orange-red color in white lion's head stone; a high CDI (0.3-0.4) indicates a gradient patina color in old tree Nanjiang stone.

[0165] For example, the division of key segments is the core of the Boundary Dilatation Matching (BDM) algorithm. Its design directly addresses the asymmetry, curvature differences, and three-dimensional morphological features of the walnut contour, achieving targeted improvements through the following steps:

[0166] 1. The core logic of the partitioning method

[0167] (1) Growth axis orientation division

[0168] Problem Targeting: Traditional two-dimensional contour analysis (such as Hu rectangle) cannot distinguish the three-dimensional features of the "belly, edge, and tip" of a walnut, resulting in the failure to match irregularly shaped walnuts (such as eagle beak and three-ribbed walnuts).

[0169] Improvement methods:

[0170] Growth axis calibration: The long axis direction of the walnut profile was extracted by principal component analysis (PCA) to simulate the natural growth direction of the walnut.

[0171] Segment division aligned along the growth axis: The outline is unfolded along the growth axis and divided into 12 key segments to ensure that each segment corresponds to the local structure of the actual walnut (such as the belly, edge, and tip).

[0172] (2) Dynamic positioning of curvature extrema

[0173] Problem Targeting: The curvature abrupt change points of the walnut outline (such as the bend of the eagle's beak, the ridge line of the three ribs) are the key to distinguishing three-dimensional features, but traditional uniform division will ignore these details.

[0174] Improvement methods:

[0175] Curvature calculation: Perform second derivative calculation on the contour points to extract the curvature extrema.

[0176] Dynamic segment boundaries: Increase segment density in regions with abrupt curvature changes (such as sharp bends) and reduce the number of segments in smooth regions (such as the belly) to achieve adaptive segmentation.

[0177] 2.12 Key Segments: Specific Definitions

[0178] Section number corresponds to the functional positioning of the part and targeted improvement points

[0179] 1-3. The tip region is used to capture the height of the tip and the direction of bending. The extreme point of curvature is used to distinguish between the single-sided tip and the conventional double tip of the eagle's beak.

[0180] 4-6 Tip transition zone: The width of the section is dynamically adjusted to quantify the curvature of the connection between the tip and the edge, adapting to the asymmetry of irregularly shaped walnuts.

[0181] 7-9 Main edge area, representing the lateral gradient of the expansion profile of the edge curvature and thickness, distinguishing the edge width difference between the four buildings and the Prince's Hat.

[0182] The 10-12 belly support area reflects the fullness and symmetry of the belly. By comparing the longitudinal expansion, the difference in belly height between hemp walnuts and iron walnuts can be identified.

[0183] 3. Improvements to the walnut's outline

[0184] (1) Asymmetric treatment

[0185] The drawback of traditional methods: Two-dimensional contour analysis assumes that the object is symmetrical, which leads to the failure of matching asymmetrical walnut shapes such as eagle beak and three-ribbed shapes.

[0186] Improvement plan:

[0187] Independent segmentation of left and right sections: The contour is divided into left and right sides, and 6 sections are extracted from each side (12 in total). The asymmetry is quantified by the difference in Hausdorff distance between the left and right sections.

[0188] Dynamic weight allocation: The weight of matching results for asymmetric segments (such as the unilateral tip of the eagle's beak) is increased to 60%, while the weight of symmetric segments (such as the belly) is reduced to 40%.

[0189] (2) Quantification of curvature difference

[0190] Traditional methods have limitations: algorithms such as Hu's moment cannot distinguish the curvature difference between "flat belly and steep side" and "steep belly and flat side".

[0191] Improvement plan:

[0192] Curvature feature encoding: Calculate the mean curvature and rate of change of curvature for each segment to generate a 12-dimensional curvature feature vector.

[0193] Expansion profile correction: The curvature loss of the 2D projection is compensated by boundary expansion (expansion coefficient is 0.2), so that the calculation results are closer to the real 3D curvature.

[0194] Step 104: Calculate texture similarity and color similarity based on the first image and the second image.

[0195] For example, traditional methods for calculating texture similarity from images typically use the ZNCC formula. However, to ensure accuracy, this method modifies the traditional ZNCC formula, which is as follows:

[0196]

[0197] The improved ZNCC formula in this application differs from the traditional ZNCC formula in that it introduces ripple significance w. i Wherein, texture saliency = gradient magnitude × curvature response. Specifically, the gradient magnitude is the difference between the maximum and minimum values ​​of the pixel gradient, and the curvature response is the difference between the maximum and minimum values ​​of curvature in each segment.

[0198] In addition, a local structure constraint term (a penalty term for consistency in texture direction) is incorporated when calculating texture similarity:

[0199]

[0200] Where, θ template and θ target The actual and desired trajectories are represented by a Gabor filter bank, where the input to the Gabor filter bank is the gradient direction θ(x,y) of the pixel. This represents the penalty coefficient.

[0201] Finally, based on the modified ZNCC and local structure constraints, the texture similarity is calculated using the following formula:

[0202] S t =ZNCC nut -0.3P

[0203] Specifically, this improvement can reduce the mismatch rate of texture orientation by 58%.

[0204] For example, the process of calculating color similarity based on the first image and the second image may include:

[0205] Acquire a standard image and obtain its HSV image; the standard image can be a completely black image.

[0206] In the H channel, the chi-square values ​​of the first image and the second image are obtained according to the chi-square test, and are denoted as the first chi-square value, and the chi-square values ​​of the first image and the standard image are denoted as the second chi-square value;

[0207] Calculate the ratio of the square of the first chi-square value to the square of the second chi-square value to obtain the normalized ratio;

[0208] In the S channel, the saturation similarity value of the first and second images is obtained by histogram intersection.

[0209] Color similarity is obtained based on the normalized ratio and saturation similarity value.

[0210] For example, the formula for calculating color similarity can be:

[0211]

[0212] Among them, w H w represents the weight of the H channel. S Indicates the weight of the S channel. x represents the normalized ratio. 2 x represents the square of the first chi-square value. max 2 This represents the square of the second chi-square value, and Intersection represents the saturation similarity value.

[0213] Step 105: Edge extraction is performed on the first image and the second image respectively using an edge detection algorithm to obtain the first contour and the second contour respectively; boundary dilation processing is performed on the second contour to obtain the third contour; based on the first contour and the third contour, the boundary similarity is determined.

[0214] For example, the edge detection algorithm can be the Canny detection algorithm.

[0215] In this algorithm, a high-intensity gradient (>100) can be considered as the extracted outer contour (the abrupt boundary between the walnut and the background). A medium-low intensity gradient (30-80) can be considered as the extracted texture edge (the internal edge generated by texture depressions / protrusions). A high-frequency scattered gradient can be considered as the extracted reflection artifact (false edges formed by patina reflection).

[0216] A clean outer contour extraction technique can include: preprocessing to suppress texture, gradient domain filtering, Canny edge detection, contour topology cleanup, and outer contour reconstruction. Among these, preprocessing to suppress texture is a key step, and its technical principle is to use the characteristic that the texture scale is much smaller than the contour scale for frequency domain separation.

[0217] In gradient domain filtering, an innovative dual gradient domain filtering design was implemented, as detailed in Table 1 below:

[0218] Table 1 Dual-channel gradient constraints

[0219]

[0220] Furthermore, Canny edge detection is set to adaptive Canny edge detection, which automatically adjusts the threshold ratio according to different situations, as shown in Table 2:

[0221] Table 2 Parameter Automatic Adjustment

[0222]

[0223] Finally, the contour topology cleanup process uses a four-step filtering method, the specific steps of which are as follows:

[0224] a) Area filtering: Remove connected components with an area less than 15 pixels.

[0225] b) Convexity detection: Contours with convex hull similarity > 0.9 are preserved.

[0226] c) Texture direction verification: Delete edge segments with an angle of less than 30° to the main axis.

[0227] d) Ellipse fitting evaluation: If the residual is greater than the threshold, it is determined to be texture interference.

[0228] In one possible implementation, the second contour is subjected to boundary expansion to obtain the third contour, which may include:

[0229] The second image is converted to a grayscale image, and then Gaussian filtering and contrast enhancement are applied to the grayscale image to obtain the third image.

[0230] The horizontal and vertical gradients of each pixel in the third image are calculated using the Sobel algorithm.

[0231] Calculate the gradient direction of each pixel in the third image based on the horizontal and vertical gradients of each pixel in the third image.

[0232] The gradient direction of each pixel is converted into a unit direction vector to obtain the vector direction of each pixel.

[0233] The second contour is smoothed by using a B-spline fitting algorithm to obtain a smooth contour.

[0234] Calculate the Euclidean distance field from each pixel on the smooth contour to all pixels inside the smooth contour.

[0235] For each pixel on the smooth contour, calculate the product of the pixel value, the preset dilation step size, and the vector direction of the pixel, and record it as the first result. Then, calculate the sum of the Euclidean distance field from the pixel to all pixels inside the smooth contour and the first result to obtain the dilated pixel corresponding to the pixel.

[0236] The third contour is obtained based on the dilated pixels corresponding to all pixels.

[0237] For example, the calculation process for the third contour may specifically include:

[0238] 1. Determine the direction of texture growth

[0239] (1) Image preprocessing

[0240] Grayscale conversion and denoising: Convert the color image to a grayscale image, remove high-frequency noise through Gaussian filtering (σ = 1~2), and preserve texture details.

[0241] Contrast Enhancement: Use histogram equalization or adaptive Gamma correction (γ = 0.5–0.8) to enhance the contrast between texture and background.

[0242] (2) Texture direction extraction

[0243] Gradient calculation: The horizontal and vertical gradients are calculated using the Sobel operator to obtain the gradient direction for each pixel.

[0244]

[0245] Among them, G x and (G) y ) represent the horizontal and vertical gradients, respectively.

[0246] Directional smoothing: Gaussian blurring (σ = 3~5) is applied to the gradient direction pattern to eliminate local noise interference.

[0247] Main direction statistics: Quantize the direction angle into 8 to 12 dominant directions (e.g., each interval is 30°), and statistically analyze the direction histogram within a local window (e.g., 15×15 pixels). Take the peak direction as the texture growth direction of that region.

[0248] (3) Dynamic adjustment and abnormal handling

[0249] Non-maximum suppression: Only retains directions where the gradient magnitude is greater than the neighborhood threshold to avoid weak texture interference.

[0250] Directional continuity constraint: By using bilateral filtering or directional propagation algorithms, the orientation of adjacent pixels is forced to be consistent, thus solving the problem of bifurcation or breakage.

[0251] 2. Ensure the realization of directional expansion

[0252] (1) Constructing the direction field

[0253] Vector field generation: Convert the texture direction θ(x,y) of each pixel into a unit direction vector.

[0254] v(x,y)=[cosθ,sinθ)

[0255] Boundary expansion: B-spline fitting is performed on the walnut outline to generate a smooth boundary curve, which serves as the starting point for expansion.

[0256] 2. Directed Dilation Algorithm

[0257] Distance transformation and direction constraints:

[0258] (1) Calculate the Euclidean distance field D(x,y) from the contour to all internal pixels.

[0259] (2) Perform weighted expansion along the direction vector v(x,y):

[0260] D new (x,y)=D(x,y)+Δ·v(x,y)·φ(x,y)

[0261] Among them, D new (x,y) represents the dilated Euclidean distance field, Δ is the dilation step size, and φ(x,y) is the texture intensity weight, which takes the value of a pixel. Based on D new (x,y) can be used to determine the dilated pixels in the graph, and the third contour can be obtained by combining all the dilated pixels.

[0262] Specifically, to optimize the dilation process, elliptical structural elements can be incorporated into the B-spline fitting process. The major axis of these elliptical structural elements is aligned with v(x,y), while the minor axis length is dynamically adjusted based on texture density (e.g., the major axis is longer in sparse texture areas). Morphological dilation is applied pixel-by-pixel to the contour, with the structural elements varying according to their position.

[0263] After obtaining the initial third contour, the contour needs to be evolved using the Level Set method to avoid self-overlapping caused by dilation. The dilated contour is then smoothed using curvature smoothing (such as mean curvature flow) to eliminate jagged artifacts.

[0264] In one possible implementation, determining boundary similarity based on the first and third contours can include:

[0265] Align the center points of the first contour and the third contour, and calculate the similarity between the first contour and the third contour, which is denoted as the first similarity.

[0266] Rotate the third contour around its center point to obtain the rotated third contour, and calculate the similarity between the rotated third contour and the first contour, which is denoted as the second similarity.

[0267] Multiple rotations of the third contour yield multiple second similarity scores.

[0268] The maximum value among the first similarity and multiple second similarities is used as the boundary similarity.

[0269] For example, in order to obtain more accurate boundary similarity, it is necessary to first align the center points of the contours to avoid calculation errors caused by different center points due to similar shapes, thus ensuring the accuracy of the calculation.

[0270] In one possible implementation, determining boundary similarity based on the first and third contours can include:

[0271] The images corresponding to the first contour and the third contour are binarized to obtain the first binarized image and the second binarized image.

[0272] By using bit matching technology, the first binarized image and the second binarized image are XORed to obtain the third binarized image;

[0273] Boundary similarity is obtained based on the third binarized image.

[0274] Specifically, in order to obtain the third binarized image, the specific steps are as follows: for each pixel in the third binarized image, take the corresponding pixel in the first binarized image and the corresponding pixel in the second binarized image respectively. If the pixel values ​​of the two corresponding pixels are the same, the pixel value is 0. If the pixel values ​​of the two corresponding pixels are different, the pixel value is 1 (following the principle of 0 for the same and 1 for different).

[0275] Therefore, the formula for calculating boundary similarity can be:

[0276]

[0277] Where R(x,y) represents the boundary similarity, I(x',y') represents any pixel in the third binarized image, W is the width of the third binarized image, and H is the height of the third binarized image. The specific explanation of this formula is as follows: if the boundary similarity between two images is high enough, then the value of each pixel in the corresponding third binarized image should be 0. The formula first calculates the proportion of non-zero pixels in the entire image, and then subtracts this proportion from 1. The closer the result is to 1, the higher the boundary similarity between the two images; the closer the result is to 0, the lower the boundary similarity between the two images. Simply put, it judges the magnitude of boundary similarity by the "proportion of non-zero pixels to all pixels in the image".

[0278] For example, traditional 2D contour analysis (such as edge detection and Hu moments) can only describe planar projection features, while the Boundary Dilatation Matching (BDM) algorithm associates 2D contours with 3D shapes in the following way:

[0279] Directional expansion simulates the three-dimensional structure: The contour is directionally expanded along the growth axis of the walnut (expansion coefficient ranging from 0.1 to 0.3), simulating the three-dimensional surface changes of the walnut through local expansion. For example, expansion of the belly reflects the actual thickness, while expansion of the edges reflects differences in curvature. This allows the expanded contour to encompass the three-dimensional features of the walnut, resulting in more accurate calculations compared to contours represented only by two-dimensional features.

[0280] Local structure encoding: The expanded contour is divided into 12 key segments (corresponding to the belly, edge, and tip, etc.), and the local three-dimensional differences are quantified by calculating the Hausdorff distance between segments. For example, the difference in the expanded contour of the tip segment can directly reflect the three-dimensional difference in the height of the tip.

[0281] Three-dimensional features refer to the differences in the three-dimensional geometric parameters of a walnut, which are quantified into calculable indicators through contour expansion and algorithms. These mainly include:

[0282] 1. Three-dimensional parameters of belly height, side width, and protrusion.

[0283] Belly height: The thickness of the walnut's base (belly), characterized by the maximum vertical distance difference after the outline expands. Edge width: The curvature of the walnut's edge (side), reflected by the difference in lateral expansion of the expanded outline. Tip: The sharpness of the tip (point), quantified by the Hausdorff distance of the tip segment.

[0284] 2. Asymmetry and curvature differences

[0285] The three-dimensional characteristics of irregularly shaped walnuts, such as the unilateral pointed protrusion of an eagle's beak and the curvature of the three ridges, are captured through directional expansion and local structural coding to capture their asymmetry. For example, the difference in the amount of expansion between the left and right contours after expansion can distinguish the direction of the eagle's beak's curvature.

[0286] 3. Indirect manifestation of surface optical properties

[0287] Transparency of the patina layer: The difference in patina thickness can be inferred by combining the expansion profile with color features (such as HSV space histogram). For example, a smaller expansion in dark areas may correspond to a thicker patina.

[0288] Step 106: Based on the texture complexity, contour variability, and chromaticity dispersion of the second image, determine the texture similarity weight, boundary similarity weight, and color similarity weight.

[0289] In one possible implementation, step 106 may include:

[0290] The second result is obtained by calculating the reciprocal of the sum of the texture complexity, contour variability, and chromaticity dispersion of the second image.

[0291] The texture similarity weight is obtained by multiplying the texture complexity of the first preset range, the second result, and the second image.

[0292] The boundary similarity weight is obtained by multiplying the second preset range, the second result, and the contour variability of the second image.

[0293] The color similarity weight is obtained by calculating the product of the third preset range, the second result, and the color dispersion of the second image.

[0294] For example, the formulas for calculating texture similarity weight, boundary similarity weight, and color similarity weight can be:

[0295]

[0296] Where TCI represents texture complexity, CVI represents contour variability, CDI represents chromaticity dispersion, and w t w represents the texture similarity weight. c w represents the boundary similarity weight. h Indicates color similarity weight. The value range is 0.4 to 0.6. The value range is 0.25 to 0.45. The value range is 0.15 to 0.25.

[0297] In one possible implementation, step 106 may also include:

[0298] The third result is obtained by multiplying the first preset parameter by the texture complexity of the second image.

[0299] The difference between the third result and the second preset parameter is calculated to obtain the fourth result.

[0300] Substituting the fourth result as the independent variable into the Sigmoid function yields the fifth result.

[0301] The product of the third preset parameter and the fifth result is calculated to obtain the sixth result.

[0302] The sum of the fourth preset parameter and the sixth result is used as the texture similarity weight.

[0303] The product of the fifth preset parameter and the contour variation of the second image is calculated to obtain the seventh result.

[0304] Calculate the difference between the sixth preset parameter and the seventh power of e to obtain the eighth result.

[0305] The product of the seventh preset parameter and the eighth result is denoted as the boundary similarity weight.

[0306] The product of the eighth preset parameter, the chromaticity dispersion of the second image, and the walnut variety coefficient is used as the color similarity weight.

[0307] For example, the first preset parameter can be 5, the second preset parameter can be 3, the third preset parameter can be 0.2, the fourth preset parameter can be 0.4, the fifth preset parameter can be -2.5, the sixth preset parameter can be 1, the seventh preset parameter can be 0.45, and the eighth preset parameter can be 0.25. Based on the specific values ​​of these preset parameters, the calculation formulas for texture similarity weight, boundary similarity weight, and color similarity weight can be obtained as follows:

[0308]

[0309] Among them, w t w represents the texture similarity weight. c w represents the boundary similarity weight. h This represents the weight of color similarity.

[0310] Step 107: Based on texture similarity, texture similarity weight, boundary similarity, boundary similarity weight, color similarity, and color similarity weight, determine the first collectible walnut that is most similar to the target collectible walnut.

[0311] In one possible implementation, step 107 may include:

[0312] The sum of the product of texture similarity and texture similarity weight, the product of boundary similarity and boundary similarity weight, and the product of color similarity and color similarity weight is used as the similarity between the first and the target ornamental walnuts.

[0313] The first walnut with the highest similarity between the first walnut and the target walnut is considered the first walnut most similar to the target walnut.

[0314] For example, in order to better match the target collectible walnuts, the similarity threshold will be adjusted to determine whether the first most similar collectible walnut identified above meets the requirements. When matching irregularly shaped walnuts, the similarity threshold is adjusted to 0.85-0.1×CVI based on the contour variability (CVI). Only when the similarity threshold is exceeded will it be used as the final walnut that matches the target collectible walnut.

[0315] In addition, a manual review mechanism was introduced to facilitate adjustments to the robustness and applicability of the above scheme. When TCI>0.7 and CVI>0.5, the most similar first ornamental walnut is further judged by humans to determine whether it can be used as a "pair" of the target ornamental walnut.

[0316] Experimental verification shows that this method can not only more comprehensively reflect the differences between walnuts, but also maintain high stability under various complex environments. The walnut pairing accuracy rate is improved to 98.7% (23% higher than the single feature method), and the robustness index under complex working conditions reaches 0.92. This method reduces the cost of manual pairing by 76%, and the processing time for a single pair of walnuts is shortened from 45 minutes to 8 seconds. This method supports the establishment of a digital ID system for collectible walnuts, promoting the construction of an industry traceability and certification system. The related technology can be extended to the intelligent identification of collectible items such as bodhi seeds and olive pit carvings.

[0317] The aforementioned method for pairing ornamental walnuts not only comprehensively considers texture similarity, boundary similarity, and color similarity, evaluating the similarity between walnuts from multiple dimensions to make the evaluation results more accurate, but more importantly, in calculating boundary similarity, it does not simply calculate the two-dimensional similarity between two contours. Instead, it uses a dilation process to expand the contours into three-dimensional data to conduct similarity evaluation. This process achieves a dimensionality upgrade of features, elevating the simple two-dimensional feature similarity calculation to a three-dimensional feature similarity calculation. For example, the expanded contours can reflect the "belly, edge, and tip" of the walnut, as well as the three-dimensional features such as the curvature and thickness of the edge, and the fullness and symmetry of the belly, which are difficult to achieve with traditional two-dimensional contour similarity calculation methods. This solution cleverly integrates three-dimensional features into two-dimensional calculation through the design of this application. Therefore, the calculation results of this solution are more accurate, the matching success rate is higher, and it can match suitable "pairs" for target ornamental walnuts, thereby meeting the needs of users.

[0318] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0319] The following are device embodiments of the present invention. For details not described in detail, please refer to the corresponding method embodiments described above.

[0320] Figure 2 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. For example... Figure 2 As shown, the electronic device 2 in this embodiment includes a processor 20 and a memory 21. The memory 21 stores a computer program 22. When the processor 20 executes the computer program 22, it implements the steps in the various method embodiments described above. Alternatively, when the processor 20 executes the computer program 22, it implements the functions of each module / unit in the various device embodiments described above.

[0321] For example, computer program 22 may be divided into one or more modules / units, which are stored in memory 21 and executed by processor 20 to complete the present invention. The one or more modules / units may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of computer program 22 in electronic device 2.

[0322] Electronic device 2 may include, but is not limited to, processor 20 and memory 21. Those skilled in the art will understand that... Figure 2This is merely an example of electronic device 2 and does not constitute a limitation on electronic device 2. It may include more or fewer components than shown, or combine certain components, or different components. For example, electronic device 2 may also include input / output devices, network access devices, buses, etc.

[0323] The processor 20 can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.

[0324] The memory 21 can be an internal storage unit of the electronic device 2, such as a hard disk or RAM. The memory 21 can also be an external storage device of the electronic device 2, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, the memory 21 can include both internal and external storage units of the electronic device 2. The memory 21 is used to store the computer program 22 and other programs and data required by the electronic device 2. The memory 21 can also be used to temporarily store data that has been output or will be output.

[0325] For the sake of simplicity and clarity, only the above-described functional modules / units are used as examples. In practical applications, the functions described above can be assigned to different functional modules / units as needed. These modules / units can be implemented in hardware, software, or a combination of both.

[0326] This invention also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the methods described in the above-described method embodiments.

[0327] This invention also provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the methods described in the above-described method embodiments.

[0328] Computer programs include computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. Computer-readable media can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc.

[0329] In the above embodiments, the descriptions of each embodiment have their own emphasis. Parts not detailed or described in a particular embodiment can be referred to in the relevant descriptions of other embodiments. Unless otherwise specified or in conflict with logic, the terminology and / or descriptions between different embodiments are consistent and can be referenced interchangeably. Technical features in different embodiments can be combined to form new embodiments based on their inherent logical relationships.

[0330] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.

Claims

1. A method for pairing collectible walnuts, characterized in that, include: Based on the walnut classification algorithm, multiple walnuts are classified to obtain walnuts of the same type as the target walnut, which is denoted as the first set; wherein, the target walnut is the walnut that needs to be paired. The collectible walnuts in the first set are designated as the first collectible walnut. Acquire an image of the target ornamental walnut, denoted as the first image; acquire an image of the first ornamental walnut, denoted as the second image; and acquire the texture complexity, contour variability, and chromaticity dispersion of the second image. Based on the first image and the second image, calculate texture similarity and color similarity; Edges are extracted from the first image and the second image using an edge detection algorithm to obtain a first contour and a second contour, respectively; the second contour is subjected to boundary dilation processing to obtain a third contour; and the boundary similarity is determined based on the first contour and the third contour. Based on the texture complexity, contour variability, and chromaticity dispersion of the second image, the texture similarity weight, boundary similarity weight, and color similarity weight are determined. Based on the texture similarity, texture similarity weight, boundary similarity, boundary similarity weight, color similarity, and color similarity weight, the first collectible walnut most similar to the target collectible walnut is determined.

2. The method for pairing collectible walnuts according to claim 1, characterized in that, The step of performing boundary expansion on the second contour to obtain the third contour includes: The second image is converted into a grayscale image, and the grayscale image is subjected to Gaussian filtering and contrast enhancement to obtain the third image; The horizontal and vertical gradients of each pixel in the third image are calculated using the Sobel algorithm. Calculate the gradient direction of each pixel in the third image based on the horizontal and vertical gradients of each pixel in the third image; The gradient direction of each pixel is converted into a unit direction vector to obtain the vector direction of each pixel. The second contour is smoothed using a B-spline fitting algorithm to obtain a smooth contour. Calculate the Euclidean distance field from each pixel on the smooth contour to all pixels inside the smooth contour; For each pixel on the smooth contour, calculate the product of the pixel value, the preset dilation step size, and the vector direction of the pixel, and record it as the first result. Then, calculate the sum of the Euclidean distance field from the pixel to all pixels inside the smooth contour and the first result to obtain the dilated pixel corresponding to the pixel. The third contour is obtained based on the dilated pixels corresponding to all pixels.

3. The method for pairing collectible walnuts according to claim 1, characterized in that, The step of determining boundary similarity based on the first contour and the third contour includes: Align the center points of the first contour and the third contour, and calculate the similarity between the first contour and the third contour, which is denoted as the first similarity. The third contour is rotated around its center point to obtain the rotated third contour. The similarity between the rotated third contour and the first contour is calculated and denoted as the second similarity. The third contour is rotated multiple times to obtain multiple second similarities; The maximum value among the first similarity and the plurality of second similarities is taken as the boundary similarity.

4. The method for pairing collectible walnuts according to claim 1, characterized in that, The determination of texture similarity weights, boundary similarity weights, and color similarity weights based on the texture complexity, contour variability, and chromaticity dispersion of the second image includes: The second result is obtained by calculating the reciprocal of the sum of the texture complexity, contour variability and chromaticity dispersion of the second image; The texture similarity weight is obtained by multiplying the texture complexity of the first preset range, the second result, and the second image. The boundary similarity weight is obtained by multiplying the second preset range, the second result, and the contour variability of the second image. The color similarity weight is obtained by calculating the product of the third preset range, the second result, and the color dispersion of the second image.

5. The method for pairing collectible walnuts according to claim 1, characterized in that, The determination of texture similarity weights, boundary similarity weights, and color similarity weights based on the texture complexity, contour variability, and chromaticity dispersion of the second image includes: Calculate the product of the first preset parameter and the texture complexity of the second image to obtain the third result; The difference between the third result and the second preset parameter is calculated to obtain the fourth result; Substituting the fourth result as the independent variable into the Sigmoid function, we obtain the fifth result; Calculate the product of the third preset parameter and the fifth result to obtain the sixth result; The sum of the fourth preset parameter and the sixth result is used as the texture similarity weight; The product of the fifth preset parameter and the contour variation of the second image is calculated to obtain the seventh result; Calculate the difference between the sixth preset parameter and the seventh power of e to obtain the eighth result; The product of the seventh preset parameter and the eighth result is denoted as the boundary similarity weight; The product of the eighth preset parameter, the chromaticity dispersion of the second image, and the walnut variety coefficient is used as the color similarity weight.

6. The method for pairing collectible walnuts according to claim 1, characterized in that, The step of obtaining the texture complexity, contour variability, and chromaticity dispersion of the second image includes: The LBP feature variance is calculated based on the second image using the LBP variance map; The number of edge points and the area of ​​the walnut region are obtained based on the second image using the Canny algorithm; The maximum pixel gradient is calculated based on the second image using the Sobel operator; Calculate the ratio of the number of edge points to the area of ​​the walnut region, and record it as the ninth result; The sum of the ninth preset parameter and the maximum value of the pixel gradient is recorded as the tenth result; The logarithm of the tenth result to the base 2 is denoted as the eleventh result; The product of the LBP feature variance, the ninth result, and the eleventh result is taken as the texture complexity. The second contour is divided into multiple segments, and the curvature of the second contour and the curvature of each segment are calculated. The difference between the curvature of the second contour and the inversion of the curvature of the second contour is denoted as the first difference. Let the L2 norm of the first difference be denoted as the first norm; The ratio of the diameter of the first function to the diameter of the second contour is denoted as the twelfth result; The difference between the tenth preset parameter and the twelfth result is denoted as the axial symmetry index. The product of the eleventh preset parameter and the axial symmetry index is recorded as the thirteenth result; The sum of the standard deviation of the curvature of the multiple segments and the thirteenth result is taken as the contour variability. Convert the second image into an HSV image; Calculate the standard deviation of pixels in the H channel based on the H channel of the HSV image; Based on the S channel in the HSV image, calculate the saturation entropy; Calculate the product of the twelfth preset parameter and the aroma entropy, and record it as the fourteenth result; The number of spots was obtained by connecting component analysis based on the V channel in the HSV image. The ratio of the number of color spots to the area of ​​the walnut region is calculated to obtain the color spot density; Calculate the product of the thirteenth preset parameter and the color spot density, and record it as the fifteenth result; The sum of the standard deviation of the pixels in the H channel, the fourteenth result, and the fifteenth result is taken as the chromaticity dispersion.

7. The method for pairing collectible walnuts according to claim 1, characterized in that, The aforementioned walnut classification algorithm categorizes multiple walnuts for collecting and playing with, obtaining walnuts of the same type as the target walnut for collecting and playing with, denoted as the first set, including: The texture complexity, contour variability, and color dispersion of each of the multiple collectible walnuts are obtained, as well as the texture complexity, contour variability, and color dispersion of the target collectible walnut. Based on the texture complexity, contour variability, and color dispersion of the target collectible walnut, a collectible walnut classification algorithm is used to determine whether the texture complexity, contour variability, and color dispersion of each of the multiple collectible walnuts correspond to the texture complexity, contour variability, and color dispersion of the target collectible walnut. For each of the plurality of collectible walnuts, if the texture complexity, contour variability, and color dispersion of the collectible walnut correspond to the texture complexity, contour variability, and color dispersion of the target collectible walnut, then the collectible walnut is added to the first set.

8. The method for pairing collectible walnuts according to claim 1, characterized in that, The acquisition of the image of the target collectible walnut, denoted as the first image, includes: The original image of the target ornamental walnut is obtained, and the original image of the target ornamental walnut is processed by illumination normalization and noise suppression. The main body of the walnut is separated by GrabCut algorithm, and the target ornamental walnut in the processed image is separated to obtain the first image. The acquisition of the image of the first collectible walnut, denoted as the second image, includes: The original image of the first ornamental walnut is obtained, and the original image of the first ornamental walnut is processed by illumination normalization and noise suppression. The main body of the walnut is separated by GrabCut algorithm, and the first ornamental walnut in the processed image is separated to obtain the second image.

9. The method for pairing collectible walnuts according to claim 1, characterized in that, The process of determining the first collectible walnut most similar to the target collectible walnut based on texture similarity, texture similarity weight, boundary similarity, boundary similarity weight, color similarity, and color similarity weight includes: The sum of the product of texture similarity and texture similarity weight, the product of boundary similarity and boundary similarity weight, and the product of color similarity and color similarity weight is taken as the similarity between the first collectible walnut and the target collectible walnut. The first walnut with the highest similarity between the first walnut and the target walnut is taken as the first walnut most similar to the target walnut.

10. A device for matching walnuts for collecting and playing with, characterized in that, It includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the method as described in any one of claims 1 to 9.

Citation Information

Cited By

  • Glass bead defect detection method and system based on visual detection

    CN121696142A