A visual image enhancement processing method for workpiece defect feature points
By constructing a structural tensor field and a local texture direction field, and decomposing and applying differentiated gain control, the problem of difficulty in distinguishing background texture from defects in existing technologies is solved, achieving accurate detection of workpiece defects and improvement of signal-to-noise ratio.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHAANXI QINCHUAN GRINDING MASCH CO LTD
- Filing Date
- 2026-03-19
- Publication Date
- 2026-06-23
AI Technical Summary
Existing industrial vision inspection systems struggle to distinguish between background textures and actual defects when processing workpieces with strong textures or complex curvature backgrounds, resulting in low signal-to-noise ratios and a high risk of false detections.
By acquiring grayscale images of the workpiece surface, a structural tensor field is constructed and feature decomposition is performed to generate a local texture direction field. The local texture direction field is then used for smoothing and regularization, and the gradient field is decomposed and differential gain control is applied to generate an enhanced image that highlights defect features.
It achieves accurate removal of weak defect signals under strong texture interference, improves the signal-to-noise ratio, reduces the false detection rate, and ensures the accuracy of image enhancement and the natural smoothness of the background.
Smart Images

Figure CN121903902B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of machine vision and image processing technology, specifically to a method for visual image enhancement processing of workpiece defect feature points. Background Technology
[0002] In existing industrial vision inspection systems, image acquisition devices are typically used to obtain grayscale images of the workpiece surface, and image processing algorithms are combined to analyze pixel grayscale distribution in order to identify minute defects on the workpiece surface.
[0003] Traditional image enhancement processing mainly relies on frequency domain filtering or spatial domain thresholding. By setting fixed filtering operators or grayscale thresholds, images are globally smoothed or edge enhanced in an attempt to separate background textures from defect signals. However, when processing workpieces with strong textures or complex curvature backgrounds, fixed processing parameters are difficult to distinguish between background textures and real defects, resulting in the background interference being incorrectly amplified or weak defects being over-smoothed. This leads to a low detection signal-to-noise ratio and a high risk of false detections. Summary of the Invention
[0004] To address the aforementioned technical problems, this invention provides a method for visual image enhancement processing of workpiece defect feature points. Specifically, the technical solution of this invention includes:
[0005] Acquire a grayscale image of the surface of the workpiece to be inspected, and perform gradient calculation on the grayscale image to generate an original gradient field that characterizes the direction and intensity of pixel grayscale changes.
[0006] A structural tensor field is constructed based on the original gradient field, and the structural tensor field is decomposed into features to obtain a local texture direction field that represents the local texture extension direction.
[0007] The local texture direction field is smoothed and regularized to generate a background flow field that characterizes the overall texture direction of the workpiece surface;
[0008] The original gradient field is projected onto the background flow field and its orthogonal direction to decompose it into the along-texture gradient component and the inverse-texture gradient component.
[0009] Differential gain control is applied to the parallel and inverse gradient components and then reconstructed to generate an enhanced image that highlights the defect features.
[0010] Preferably, acquiring the grayscale image of the surface of the workpiece to be inspected and performing gradient calculation includes the following sub-steps: acquiring the original image data of the surface of the workpiece to be inspected through an industrial camera and converting it into a single-channel grayscale matrix; performing convolution operation on the single-channel grayscale matrix using a preset differential operator to calculate the partial derivatives of each pixel in the horizontal and vertical directions; constructing a two-dimensional vector based on the partial derivatives to generate the original gradient field.
[0011] Preferably, constructing a structural tensor field based on the original gradient field and performing eigenvalue decomposition includes the following sub-steps: calculating the outer product matrix of the gradient of each pixel in the original gradient field to obtain the initial structural tensor; performing spatial convolution smoothing on the initial structural tensor using a Gaussian kernel function to generate a structural tensor field; performing eigenvalue decomposition on each tensor matrix in the structural tensor field to extract the eigenvector corresponding to the smallest eigenvalue; and normalizing the eigenvector to generate a local texture direction field representing the dominant extension direction of the texture.
[0012] Preferably, the smoothing and regularization of the local texture direction field includes the following sub-steps: constructing an anisotropic diffusion equation or Gaussian smoothing model for the vector field; taking the local texture direction field as input and performing iterative smoothing calculations using the diffusion equation or Gaussian smoothing model; and determining the smoothed vector field as the background flow field characterizing the inherent texture direction of the workpiece surface.
[0013] Preferably, projecting the original gradient field onto the background flow field and its orthogonal direction includes the following sub-steps: calculating the dot product of corresponding vectors in the original gradient field and the background flow field to obtain a projection scalar; multiplying the projection scalar by the unit vector of the background flow field to obtain a along-texture gradient component, wherein the along-texture gradient component represents the gray-level abrupt change generated along the texture extension direction; calculating the dot product of the orthogonal vectors of the original gradient field and the background flow field, and multiplying by the orthogonal vector to obtain an inverse-texture gradient component, wherein the inverse-texture gradient component represents the gray-level abrupt change generated along the texture normal direction.
[0014] Preferably, applying differentiated gain control to the along-texture gradient component and the inverse-texture gradient component and reconstructing them includes the following sub-steps: using a nonlinear amplification function to perform gain processing on the along-texture gradient component to enhance the defect signal that cuts off the background texture; using an attenuation coefficient to suppress the inverse-texture gradient component to weaken the background texture signal distributed along the texture normal direction; and vector superimposing the processed along-texture gradient component and the inverse-texture gradient component to generate the target gradient field.
[0015] Preferably, the steps of reconstructing and generating the enhanced image further include: calculating the divergence field of the target gradient field; constructing the Poisson equation based on the divergence field; and solving the Poisson equation to reconstruct the image grayscale distribution to obtain the enhanced image.
[0016] Preferably, the nonlinear amplification function adopts The function or piecewise linear function is configured to: determine the numerical relationship between the magnitude of the gradient component along the texture and a preset noise threshold; if the magnitude of the gradient component along the texture is greater than the preset noise threshold, output a first gain coefficient; if the magnitude of the gradient component along the texture is less than or equal to the preset noise threshold, output a second gain coefficient; wherein the value of the first gain coefficient is greater than the value of the second gain coefficient.
[0017] Preferably, the method further includes: performing binarization thresholding on the enhanced image; extracting the area features and aspect ratio features of the segmented connected regions; if the area features are greater than a preset area threshold and the aspect ratio features are greater than a preset aspect ratio threshold, then it is determined that the workpiece surface region corresponding to the connected region has scratches or cracks; otherwise, the connected region is determined to be a non-defect region.
[0018] Compared with the prior art, the present invention has the following beneficial effects:
[0019] 1. This invention generates a background flow field by constructing a structural tensor field and combining it with anisotropic diffusion equations, thereby achieving the effect of adaptively acquiring the complex texture direction of the workpiece surface. Compared with the limitations of existing technologies that rely on fixed filtering operators to process curved or rotated textures, this invention utilizes the statistical characteristics and regularized smoothing of the local texture direction field to effectively establish a defect-free ideal reference coordinate system, solving the problem of not being able to accurately define the defect direction in the background of non-uniform or complex curvature textures.
[0020] 2. This invention achieves precise removal of weak defect signals under strong texture interference by projecting the original gradient field onto the background flow field and its orthogonal direction for geometric separation and applying differentiated gain control. Compared with the shortcomings of existing technologies such as frequency domain filtering or spatial thresholding, which are difficult to distinguish between the background and defects, this invention utilizes the physical characteristics of defects cutting off textures to generate forward texture components while the background is mainly concentrated in reverse texture components. This achieves decoupling of signal and noise and solves the problem of low signal-to-noise ratio and easy submersion of low-contrast defects by the background.
[0021] 3. This invention reconstructs images by calculating the divergence field of the target gradient field and constructing the Poisson equation, achieving the effect of recovering grayscale distribution from a non-conservative gradient field without artifacts. Compared with the ringing effect that may be caused by directly cutting the gradient in traditional image enhancement, the use of symmetric filling and backward difference scheme combined with frequency domain solution ensures that the reconstructed image maintains a smooth and natural background while enhancing the contrast of defects, and solves the problem of image distortion caused by non-integrability after gradient field modification.
[0022] 4. This invention achieves robust suppression of sensor thermal noise and accurate determination of linear defects in any direction by using noise threshold judgment based on statistical principles and feature extraction by inertial ellipse fitting. Compared with the risk of missed detection in the simple circumscribed rectangle method in the prior art when detecting oblique cracks, this invention uses the second-order central moment to calculate the aspect ratio feature, which has rotational invariance and effectively eliminates false defects with inconsistent shapes. This solves the problems of high false detection rate and distortion in the description of slender crack morphology in traditional methods. Attached Figure Description
[0023] The present invention will be further explained below with reference to the accompanying drawings and embodiments:
[0024] Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments.
[0026] Example 1:
[0027] Please see Figure 1 A method for visual image enhancement of workpiece defect feature points includes the following steps:
[0028] S1. Acquire a grayscale image of the surface of the workpiece to be inspected, and perform gradient calculation on the grayscale image to generate an original gradient field that characterizes the direction and intensity of pixel grayscale changes.
[0029] S2. Construct a structural tensor field based on the original gradient field, and perform eigenvalue decomposition on the structural tensor field to obtain the local texture direction field that represents the local texture extension direction.
[0030] S3. Smooth and regularize the local texture direction field to generate a background flow field that characterizes the overall texture direction of the workpiece surface;
[0031] S4. Project the original gradient field onto the background flow field and its orthogonal direction respectively to decompose it into the gradient components along the texture and the gradient components in the opposite texture.
[0032] S5. Apply differential gain control to the parallel and inverse gradient components and reconstruct them to generate an enhanced image that highlights the defect features.
[0033] This embodiment details the mathematical construction logic for extracting subtle defects against a strong texture background. The system executes the generation step of the original gradient field, which transforms the light reflection information of the workpiece surface in the physical world into a two-dimensional vector field in mathematics. Each vector corresponds to the gray-level change rate of a pixel in the image, aiming to capture all edge information in the image, including the edges of the background texture and the edges of defects. The system introduces a structure tensor field as a descriptor and utilizes its ability to distinguish the local geometric structure, i.e., flatness, edges, or corners, to obtain the local texture direction field through feature decomposition. This field represents the dominant extension direction of the texture in each tiny region of the image.
[0034] To address the disruption of texture continuity caused by scratches or cracks on the surface of actual workpieces, the system performs smoothing and regularization processing to forcibly restore texture continuity, thereby constructing an idealized background flow field that removes local disturbances and establishing a defect-free reference coordinate system. Based on this, the system uses differential geometry principles to perform geometric separation of the signal, decomposing the original gradient field projection. It utilizes the physical characteristic that regular texture grayscale changes mainly occur in the reverse texture direction while defects cut the texture, causing grayscale jumps in the forward texture direction, to achieve decoupling of signal and noise. The system applies differential gain to the forward texture component representing defects and the reverse texture component representing the background and reconstructs the image, outputting an enhanced image.
[0035] Example 2:
[0036] S1 includes the following sub-steps:
[0037] S11. Acquire raw image data of the surface of the workpiece to be inspected using an industrial camera and convert it into a single-channel grayscale matrix;
[0038] S12. Perform convolution operation on the single-channel grayscale matrix using the preset differential operator, and calculate the partial derivatives of each pixel in the horizontal and vertical directions.
[0039] S13. Construct a two-dimensional vector based on partial derivatives to generate the original gradient field.
[0040] This embodiment further defines the physical acquisition and calculation path of the original gradient field; the system acquires photoelectric signals through an industrial camera and converts the original color data into a single-channel grayscale matrix using a weighted averaging algorithm, such as weighting based on human eye sensitivity. This matrix serves as the fundamental mathematical object for image processing. To suppress high-frequency thermal noise introduced by the sensor while preserving edge information, the system selects a preset differential operator with a smoothing effect, preferably... The operator performs a convolution operation on a single-channel grayscale matrix; the specific operation logic is as follows:
[0041]
[0042] in, : Derived from a single-channel grayscale matrix acquired and converted by a camera, its physical meaning is the light intensity distribution on the surface of the workpiece; The horizontal convolutional kernels are derived from the preset storage, and the specific configuration is as follows:
[0043]
[0044] Used to detect vertical edges; The vertical convolution kernels are derived from the preset storage, and the specific configuration is as follows:
[0045] Used for detecting horizontal edges; : The mathematically defined convolution operator; the system is based on the calculated horizontal partial derivative. and vertical partial derivatives Construct a two-dimensional vector field for any coordinate point in the image. Generate the original gradient field ;
[0046] This embodiment uses a specific differential operator for convolution calculation instead of simple difference, which effectively smooths out random thermal noise during image acquisition and ensures that the generated original gradient field mainly reflects the physical structure changes of the workpiece surface, providing a high signal-to-noise ratio input data foundation for subsequent structural tensor calculation.
[0047] S2 includes the following sub-steps:
[0048] S21. Calculate the outer product matrix of the gradient of each pixel in the original gradient field to obtain the initial structure tensor;
[0049] S22. Use a Gaussian kernel function to perform spatial convolution smoothing on the initial structure tensor to generate a structure tensor field;
[0050] S23. Perform eigenvalue decomposition on each tensor matrix in the structural tensor field and extract the eigenvector corresponding to the smallest eigenvalue;
[0051] S24. Normalize the feature vectors to generate a local texture direction field that represents the dominant extension direction of the texture.
[0052] This embodiment details the process of extracting local texture directions using a structure tensor; the system calculates the outer product of the gradient at each point in the original gradient field to construct the initial structure tensor. The matrix is A symmetric positive semidefinite matrix is used to capture the correlation of local gradients. To obtain statistical features within the neighborhood rather than single-point features, the system uses a Gaussian kernel function to perform spatial convolution smoothing on the initial structure tensor, generating a structure tensor field. :
[0053]
[0054] in, : Derived from the preset Gaussian kernel function, its physical meaning is the integral scale weight of local texture analysis; Derived from preset parameters, the physical meaning of which is the standard deviation of the integral scale, it determines the smoothing range of local texture analysis; specifically, the parameters... The settings must follow the principle of texture feature scale matching to ensure the repeatability of the technical solution; in order to eliminate the uncertainty of manual estimation, this embodiment constructs an automated parameter configuration module based on spectrum analysis: the system extracts the center of the original gradient field. The region is subjected to a two-dimensional fast Fourier transform and the power spectrum is calculated; the coordinates of the maximum energy peak excluding the DC component are searched in the frequency domain plane. ; Calculate the main period of texture on the workpiece surface using the formula:
[0055]
[0056] Among them, 128 is Calculate the side length of the window. The frequency radius corresponding to the maximum energy peak value excluding the DC component;
[0057] The system will parameters Automatically set to The adaptive computation logic ensures that the integration window covers a sufficient amount of texture period to extract the statistical principal direction, while avoiding blurring of local curvature changes in the texture flow direction due to an excessively large window; the system calculates the matrix for each pixel. Perform eigenvalue decomposition to obtain eigenvalues. And the corresponding eigenvectors; based on this, the system selects the corresponding minimum eigenvalue. eigenvectors That is, the direction of least gradient change, which corresponds to the texture extension direction;
[0058] The inherent sign uncertainty in eigenvalue decomposition, namely and Mathematically equivalent but in opposite directions, to prevent the zero-vector phenomenon of adjacent pixel vectors canceling each other out during the smoothing process in the subsequent S3 step, which violates the principle of vector field continuity, the system performs half-plane constraint correction here: detecting feature vectors. horizontal components ,like Then perform a flip operation. ;like and The same flipping process is then performed; this step forces all local texture vectors to point to the right half-plane and normalizes them to generate a geometrically continuous local texture orientation field. ; Here it is clarified that the local texture direction field At each pixel The value at that point is equal to the eigenvector corresponding to that point. That is, take This ensures the consistency of physical quantities from feature extraction to field construction;
[0059] This embodiment introduces integral-scale structural tensor smoothing and eigenvalue decomposition to robustly extract the dominant texture direction from messy gradient information. Compared with directly using the gradient vertical direction, this method utilizes neighborhood statistical properties to effectively resist the interference of local noise and minor texture breaks, and accurately reflects the true texture flow direction of the workpiece surface.
[0060] S3 includes the following sub-steps:
[0061] S31. Construct an anisotropic diffusion equation or Gaussian smoothing model for vector fields;
[0062] S32. Take the local texture direction field as input and perform iterative smoothing calculations using the diffusion equation or Gaussian smoothing model;
[0063] S33. The smoothed vector field is determined as the background flow field characterizing the inherent texture direction of the workpiece surface.
[0064] In this embodiment, an anisotropic diffusion equation is used to regularize the vector field; the system constructs the following diffusion equation model:
[0065]
[0066] in, : Derived from the vector field calculated in the previous stage, its physical meaning is the texture direction field to be smoothed; here it is clarified that the input variables of the equation At the initial moment, that is At that time, it is the local texture direction field output in step S2. ,Right now ; : Derived from system clock control, its physical meaning is the iteration time step; The diffusion coefficient is derived from a preset baseline; in the continuous medium theory model, it has the physical dimension of length squared per time; however, in the discrete numerical implementation of this embodiment, the system normalizes the image space grid step size to a unit pixel, i.e. This transforms the parameter into a dimensionless diffusion rate constant, used to control the smoothing intensity in each iteration. In actual code implementation, to balance smoothing speed and numerical stability, it is recommended to set [the value of the parameter]. ;
[0067] To clearly illustrate the numerical solution mechanism, the system decomposes the above vector field diffusion equation into components. Two coupled scalar equations:
[0068]
[0069] The key point here is that the two equations share the same diffusion conductivity coefficient. This coefficient is determined by the global Jacobian norm of the vector field, thus ensuring that and The synchronicity of components during the smoothing process avoids directional drift; : Derived from a preset dimensionless diffusion conduction function; this embodiment specifically adopts - The diffusion model, the function is defined as:
[0070]
[0071] in, This represents the magnitude of the local gradient; to ensure the physical consistency of the vector field smoothness, here... Specifically defined as the Jacobian matrix of a vector field. Norm; In order to eliminate ambiguity in discrete computing, this embodiment explicitly defines Discretization calculation logic: For any pixel in the image A unified central difference template is used to simultaneously calculate the four partial derivatives in the horizontal and vertical directions, i.e. Similarly, calculate Substitute these four spatially aligned scalar values into the formula:
[0072]
[0073] This definition ensures and The gradient changes of the components are fully coupled when calculating the diffusion coefficient, avoiding numerical drift caused by inconsistent difference positions, such as staggered grids. This is the gradient sensitivity constant; to ensure the parameters This embodiment can adapt to the texture roughness of different workpiece surfaces, avoiding undersmoothing or oversmoothing caused by manual settings. It uses a histogram statistical method to dynamically determine the roughness. Value: The system calculates the initial local texture orientation field. For all pixels in the dataset, construct a histogram of the gradient magnitude distribution and calculate its cumulative distribution function. Select The gradient magnitude value corresponding to reaching 90% is assigned to This dynamic setting ensures that approximately 90% of smooth texture areas are subjected to strong smoothing, while 10% of areas with drastic changes, such as inherent edges, are preserved as boundaries.
[0074] The system will use local texture orientation fields Substituting these initial conditions into the above equations, the system iteratively solves the problem. To specifically implement the solution of this continuous partial differential equation on a discrete digital image grid, the system employs the finite difference method for numerical discretization: for any pixel coordinates in the image... , No. Vector values of the next iteration The updated formula is:
[0075]
[0076] in, To satisfy the numerical stability condition, such as This embodiment uses typical values. The time step constant; subscript These represent the neighboring areas in the four directions: north, south, east, and west. Represents the nearest neighbor difference in the corresponding direction, for example In order to strictly implement the aforementioned The coupling-diffusion mechanism defined by the norm, coefficients It is not calculated solely from the difference in the corresponding direction, but rather by mean interpolation based on the diffusion coefficient at the center of the pixel; specifically, the system calculates the mean interpolation for each pixel in the entire image. scalar diffusion coefficient:
[0077]
[0078] in, For the complete Jacobian norm at that point; then calculate the conduction coefficient, for example... This process ensures that if the horizontal component... Dramatic changes occur, and vertical diffusion is also suppressed, thus maintaining the geometric consistency of the vector field. To handle the difference calculation of image edges, the system adopts the Neumann boundary condition, which assumes that the pixel value outside the boundary is equal to the pixel value on the boundary, and mirror reflection, in order to avoid the boundary shrinkage effect during the iteration process.
[0079] In particular, since the diffusion process only applies to the components of the vector. Independent smoothing may lead to vector magnitude decay or drift; therefore, the system must perform a normalization constraint step after each iteration. To prevent division by zero errors caused by local texture loss resulting in a zero vector magnitude, the system introduces a minimum constant. ,like :
[0080]
[0081] This step ensures that the vector field maintains a unit magnitude, thus preserving its physical property as a directional field. During the iteration process, local disturbances in the vector field, such as abrupt directional changes caused by defects, are gradually assimilated by the surrounding dominant directions. In response to the number of iterations reaching a preset value, such as 50, or the rate of change of the vector field being less than a threshold, such as 1e-4, the system stops iterating and determines the final unit vector field as the background flow field. .
[0082] S4 includes the following sub-steps:
[0083] S41. Calculate the dot product of the original gradient field and the corresponding vectors in the background flow field to obtain the projected scalar;
[0084] S42. Multiply the projection scalar by the unit vector of the background flow field to obtain the along-texture gradient component, where the along-texture gradient component represents the gray-level abrupt change generated along the texture extension direction;
[0085] S43. Calculate the dot product of the orthogonal vectors of the original gradient field and the background flow field, and multiply by the orthogonal vector to obtain the inverse texture gradient component, where the inverse texture gradient component represents the gray-level abrupt change generated along the texture normal direction.
[0086] This embodiment details the signal separation process based on manifold geometry; the system calculates the original gradient vector. With background flow field vector The dot product yields the projected scalar. This scalar reflects the magnitude of the gradient projection onto the texture flow direction; the system multiplies the projected scalar with the unit vector of the background flow field to generate the in-texture gradient component. :
[0087]
[0088] in, : It originates from the dot product calculation result, its mathematical essence is a scalar, and its physical meaning is the projection magnitude of the original gradient in the texture direction; The background flow field output from S3 is physically represented as the unit vector of the workpiece's inherent texture direction. It is hereby clarified that the operators in the formula... Scalar multiplication of a quantity and a vector; symbol Unified reference to scalar For unit vectors The parallel texture gradient component reconstructed after linear scaling is defined throughout the processing steps of subsequent embodiments to ensure the uniqueness of the symbol usage.
[0089] The system constructs orthogonal basis vectors for the background flow field; for any vector in the background flow field:
[0090]
[0091] This is explicitly defined This represents the projection component of the background flow field unit vector onto the horizontal axis, i.e., the x-axis, in the image coordinate system. The projection component of this component onto the vertical axis, i.e., the y-axis, together determine the dominant local texture direction at this pixel; the system defines its orthogonal vector according to the geometric rule of rotating 90 degrees counterclockwise:
[0092]
[0093] Based on this determined geometric reference, the system calculates the original gradient field. Orthogonal vectors The dot product yields the signed second projected scalar. ,Right now This scalar explicitly indicates the magnitude and direction of the gradient projection along the texture normal direction, i.e., positive or negative; the system multiplies this scalar by an orthogonal vector, i.e., performs scalar multiplication. Thus, the inverse texture gradient components are obtained. This step clarifies that the construction of the inverse texture component depends on the scalar result of the dot product, ensuring that the direction of the component vector is strictly controlled by the projection sign, eliminating the directional ambiguity that may exist in direct projection, and providing a clear input variable for gain control of the scalar magnitude in the subsequent S5 step.
[0094] S5 includes the following sub-steps: S51. Use a nonlinear amplification function to perform gain processing on the gradient component along the texture to enhance the defect signal of cutting off the background texture;
[0095] S52. Use the attenuation coefficient to suppress the inverse texture gradient component in order to weaken the background texture signal distributed along the texture normal direction;
[0096] S53. The processed gradient components along the texture and the gradient components inverse are vector-superimposed to generate the target gradient field.
[0097] This embodiment details the logic of differentiated gain control and gradient field reconstruction; the system processes the gradient components along the texture representing defects; to avoid the ambiguity of mathematical definitions caused by directly applying nonlinear functions to vectors, the system specifically executes the following scalar-vector transformation logic: calling the projected scalar calculated in step S41. This scalar is a signed real number representing the magnitude of the projection of the original gradient onto the background texture direction. It is then passed as input to the nonlinear amplification function. The enhanced scalar was calculated. Using formulas The reconstructed and enhanced parallel-texture gradient vector, where, The background flow field is a unit vector; this step ensures that the gain operation is applied accurately to the signal intensity along the texture direction, while strictly maintaining the geometric directionality of the original gradient.
[0098] Meanwhile, the system targets the inverse texture gradient components representing the background. Apply attenuation coefficient To maintain consistency with the parallel texture component processing logic and to clearly define the mathematical operation object for gain control, the system calls the second projection scalar calculated in step S43. Applying linear decay calculations to it yields the following:
[0099]
[0100] Using formula Reconstructing the suppressed inverse texture gradient components; this process clarifies that differential gain control is essentially adjusting the amplitude of the two scalar projection values after orthogonal decomposition, and then synthesizing them into a vector, thus eliminating the ambiguity at the code implementation level regarding the description of multiplying the vector as a whole by coefficients; among which, : Derived from preset configuration, its physical meaning is the background texture retention ratio coefficient, and its value range is usually [value range missing]. The system performs vector superposition of the two processed orthogonal components to generate the target gradient field. The specific superposition formula is as follows:
[0101]
[0102] This formula clarifies the target gradient field. It is constructed by linear recombination of the enhanced tangential component and the suppressed normal component; the generated Although mathematically it may no longer be a conservative field, i.e. However, it retains the most significant edge features, providing high signal-to-noise ratio input data for subsequent searching of least squares solutions using the Poisson equation;
[0103] This embodiment achieves simultaneous background removal and strong defect removal by applying asymmetric gain control to two orthogonal components. Compared with traditional subtractive background removal, this vector synthesis method avoids negative artifacts and improves the visual readability of the image by preserving a small amount of background contour, which facilitates subsequent positioning of the workpiece edge.
[0104] S5 also includes: S54. Calculate the divergence field of the target gradient field;
[0105] S55. Construct the Poisson equation based on the divergence field;
[0106] S56. Solve the Poisson equation to reconstruct the image grayscale distribution and obtain the enhanced image;
[0107] This embodiment addresses the issue of potentially non-integrable gradient fields after modification by introducing the Poisson equation for image reconstruction; the system calculates the target gradient field. divergence field To ensure numerical compatibility with the implicit Laplace operator in the subsequent frequency domain solver, the system strictly employs the backward finite difference method to calculate the divergence.
[0108]
[0109] in, For the target gradient field in and Components of direction; difference calculation at image boundaries, for example when... When needed, call The system implicitly employs von Neumann boundary conditions, which assume that the gradient value outside the boundary is equal to the gradient value inside the boundary. This ensures that the divergence contribution at the boundary is zero, thereby guaranteeing the closure and conservation of the numerical calculation.
[0110] The system constructs the Poisson equation based on the calculated divergence field. In order to overcome The implicit periodic boundary assumption in the algorithm leads to boundary ringing effects, and the system pre-calculates the divergence field. Symmetrical filling is performed, expanding the image to twice its original size. This symmetric filling operation is specifically a mirror copy along the image edges, mathematically transforming the subsequent Fourier series expansion into a cosine series expansion, similar to... The transformation makes the first derivative of the filled image continuous at the boundary, effectively eliminating the boundary Gibbs ringing effect caused by the mismatch between the periodicity assumption of FFT and the actual non-periodic image.
[0111] The system uses the Fast Fourier Transform to solve this partial differential equation; the specific frequency domain solution algorithm is as follows:
[0112] For the filled divergence field Perform a two-dimensional fast Fourier transform to obtain the frequency domain representation. ;
[0113] Constructing the frequency domain transfer function of the discrete Laplace operator:
[0114]
[0115] in, The dimensions of the expanded image;
[0116] Performing division operations using the frequency domain convolution theorem In particular, for Zero-frequency component, forced setting Use a fixed average gray value for the image;
[0117] right Perform a two-dimensional inverse fast Fourier transform and take the real part, then prune the filled region to obtain the numerical solution. This is the preliminary reconstructed image;
[0118] Because the gradient was processed with nonlinear high gain in step S51, the reconstructed image... The numerical dynamic range may far exceed that of the original image; for example, the pixel values may be distributed in... The range, if directly truncated, would lead to severe information loss or image binarization; therefore, the system performs dynamic range matching based on statistical properties: calculating... global standard deviation and the standard deviation of the original image Grayscale recovery is performed using a formula:
[0119]
[0120] in, The numerical stability constant, designed to prevent division by zero errors, is set to a value of [value missing]. Ensure that it is in a flat area, i.e. The calculation does not overflow. The preset contrast retention factor is recommended to be 1.2 to 1.5. The mean of the original image; Cut off to The interval is used to obtain the final enhanced image;
[0121] This embodiment uses precise matching of the difference format, i.e., backward divergence combined with forward gradient, to recover the grayscale distribution without artifacts from an artificially modified non-conservative gradient field. This process has the characteristic of automatically smoothing artifacts, resulting in an enhanced image with extremely high contrast at defects and smooth and natural background, effectively eliminating the ringing effect that may be caused by hard gradient cutoff.
[0122] Nonlinear amplification function adopted A function or a piecewise linear function, configured as follows:
[0123] Determine the numerical relationship between the magnitude of the gradient component along the texture and the preset noise threshold;
[0124] If the magnitude of the gradient component along the texture is greater than the preset noise threshold, then the first gain coefficient is output.
[0125] If the magnitude of the gradient component along the texture is less than or equal to the preset noise threshold, then the second gain coefficient is output.
[0126] The value of the first gain coefficient is greater than the value of the second gain coefficient.
[0127] This embodiment defines in detail the specific form and parameter logic of the gain control function; the system can select according to actual computing power requirements. Function or piecewise linear function;
[0128] When using To achieve a smooth transition from low to high gain during function execution, the system employs the following gain coefficient calculation formula:
[0129]
[0130] Based on this, the output augmented scalar is:
[0131]
[0132] in, : Derived from the signed projected scalar calculated in step S41, i.e., the variable in the formula ; The preset noise threshold is derived from statistically analyzed images of defect-free, high-quality products; the specific parameter acquisition method is as follows: during the system calibration phase, data is collected... Zhang, for example For images of a defect-free standard workpiece, calculate the amplitude distribution of the gradient component along the texture for each image, and statistically analyze the mean amplitude of all samples. and standard deviation ,in accordance with Criterion setting:
[0133]
[0134] This setting ensures that approximately 99.7% of background random texture fluctuations and sensor noise will be judged as being below the threshold; This is derived from a preset first gain coefficient, such as 5.0, which corresponds to the amplification factor of a strong signal; The second gain coefficient, derived from a preset value (e.g., 0.2), corresponds to the noise suppression factor and satisfies the following conditions: ; : Derived from a preset slope coefficient; to ensure that the nonlinear mapping is within the noise threshold To ensure sufficient differentiation in the vicinity while avoiding artifacts caused by the step effect, this embodiment preferably sets... This setting causes the gain curve to rise rapidly at the threshold, achieving a soft threshold effect.
[0135] When using piecewise linear functions, the system executes the following logic to reduce computational overhead:
[0136]
[0137]
[0138] in, The first gain coefficient, This is the second gain coefficient;
[0139] The system execution logic is as follows: Calculate the input amplitude. With noise threshold The relationship is as follows: if the amplitude is greater than the threshold, the function output is close to the value of the first gain coefficient, i.e. The function can output the first gain coefficient directly, i.e., the segmented mode; if the amplitude is less than or equal to the threshold, the function outputs a value close to the second gain coefficient or directly outputs the second gain coefficient.
[0140] This embodiment constructs a soft or hard threshold mechanism by introducing a noise threshold determination based on statistical principles. It suppresses random noise with extremely small amplitude by applying low gain to prevent it from being amplified along with defects, while applying high gain to signals that exceed the noise threshold. This nonlinear mapping significantly improves the robustness of the enhancement algorithm to sensor thermal noise and ambient light interference.
[0141] Step S6: S61. Perform binarization thresholding segmentation on the enhanced image;
[0142] S62. Extract the area features and aspect ratio features of the segmented connected regions. If the area features are greater than the preset area threshold and the aspect ratio features are greater than the preset aspect ratio threshold, then it is determined that there are scratches or cracks on the workpiece surface area corresponding to the connected region; otherwise, the connected region is determined to be a non-defect region.
[0143] This embodiment adds automated defect detection logic to the image enhancement system; the system utilizes The adaptive thresholding method converts the reconstructed enhanced image into a binary image; the system thresholds each connected component in the binary image. Perform feature extraction and calculate its area features. and aspect ratio characteristics ;
[0144] Targeting aspect ratio features To avoid the distortion in aspect ratio calculation caused by excessively large bounding box gaps when processing oblique cracks using the traditional bounding rectangle method (e.g., the bounding rectangle of a 45-degree slender crack is nearly square, leading to missed detection), this embodiment employs an inertial ellipse fitting method based on the second-order central moments of the image: calculating the normalized second-order central moments of the connected components. Let connected components be... Include 1 pixel The center of gravity is The specific calculation formula is as follows:
[0145]
[0146] Construct the covariance matrix And solve for its two eigenvalues. To ensure the feasibility of the calculation process, this embodiment explicitly uses the following analytical formula to calculate the eigenvalues:
[0147]
[0148] Assumption The aspect ratio feature is defined as follows: ,in, To prevent division by zero errors in the minimum value, such as This calculation method is rotationally invariant and can accurately describe the length of cracks in any direction; the system executes the following decision logic:
[0149]
[0150] in, This originates from a system calibration process based on extreme sample statistics; specifically, data is collected during the system calibration phase. For example, 50 samples containing the minimum acceptable defect are processed by S1-S61. The area distribution of the defect connected regions, which are manually verified, is statistically analyzed, and the 10th percentile value of this distribution is taken as... This value serves as the minimum size limit for filtering isolated noise points. Similarly, this is derived from sample statistics; based on the above extreme sample set, the aspect ratio characteristic distribution of all confirmed defects is calculated, and 0.8 times the minimum value of this distribution is taken as... This value serves as a morphological criterion for distinguishing between linear scratches and spot-like stains; in response to a connected region simultaneously satisfying both of the above conditions, the system determines that the region contains scratches or cracks.
[0151] This embodiment combines geometric feature screening to further eliminate pseudo-defects, such as water stains, that are significant in gradient but do not conform to the defect definition in shape. Through the dual constraints of area and aspect ratio, the false detection rate of the system is significantly reduced, realizing a functional closed loop from image enhancement to automatic detection.
[0152] It should be noted that the above 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 preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method for visual image enhancement processing of defect feature points in a workpiece, characterized in that, Includes the following steps: S1. Acquire a grayscale image of the surface of the workpiece to be inspected, and perform gradient calculation on the grayscale image to generate an original gradient field that characterizes the direction and intensity of pixel grayscale changes. S2. Construct a structural tensor field based on the original gradient field, and perform eigenvalue decomposition on the structural tensor field to obtain a local texture direction field that characterizes the local texture extension direction; S3. The local texture direction field is smoothed and regularized to generate a background flow field that characterizes the overall texture direction of the workpiece surface; S4. Project the original gradient field onto the background flow field and its orthogonal direction respectively to decompose it into the gradient component along the texture and the gradient component in the opposite texture. S5. Apply differential gain control to the parallel and inverse gradient components and reconstruct them to generate an enhanced image that highlights the defect features; S5 includes the following sub-steps: S51. The gradient component along the texture is amplified using a nonlinear amplification function to enhance the defect signal of the cut background texture; S52. The inverse texture gradient component is suppressed using an attenuation coefficient to weaken the background texture signal distributed along the texture normal direction; S53. Vector superposition of the processed parallel-texture gradient components and the inverse-texture gradient components to generate the target gradient field; The S5 also includes: S54. Calculate the divergence field of the target gradient field; S55. Construct the Poisson equation based on the divergence field; S56. Solve the Poisson equation to reconstruct the image grayscale distribution and obtain the enhanced image.
2. The visual image enhancement processing method for workpiece defect feature points according to claim 1, characterized in that, S1 includes the following sub-steps: S11. Acquire the original image data of the surface of the workpiece to be inspected using an industrial camera, and convert it into a single-channel grayscale matrix; S12. Perform convolution operation on the single-channel grayscale matrix using a preset differential operator to calculate the partial derivatives of each pixel in the horizontal and vertical directions. S13. Construct a two-dimensional vector based on the partial derivatives to generate the original gradient field.
3. The visual image enhancement processing method for workpiece defect feature points according to claim 1, characterized in that, S2 includes the following sub-steps: S21. Calculate the outer product matrix of the gradient of each pixel in the original gradient field to obtain the initial structure tensor; S22. The initial structure tensor is spatially convolved and smoothed using a Gaussian kernel function to generate the structure tensor field; S23. Perform eigenvalue decomposition on each tensor matrix in the structural tensor field and extract the eigenvector corresponding to the smallest eigenvalue; S24. Normalize the feature vector to generate the local texture direction field that represents the dominant extension direction of the texture.
4. The visual image enhancement processing method for workpiece defect feature points according to claim 1, characterized in that, S3 includes the following sub-steps: S31. Construct an anisotropic diffusion equation or Gaussian smoothing model for vector fields; S32. Using the local texture direction field as input, perform iterative smoothing calculations using the diffusion equation or Gaussian smoothing model; S33. The smoothed vector field is determined as the background flow field that characterizes the inherent texture direction of the workpiece surface.
5. The visual image enhancement processing method for workpiece defect feature points according to claim 1, characterized in that, S4 includes the following sub-steps: S41. Calculate the dot product of the original gradient field and the corresponding vector in the background flow field to obtain the projection scalar; S42. Multiply the projection scalar by the unit vector of the background flow field to obtain the parallel-texture gradient component, wherein the parallel-texture gradient component represents the gray-level abrupt change generated along the texture extension direction; S43. Calculate the dot product of the orthogonal vectors of the original gradient field and the background flow field, and multiply by the orthogonal vectors to obtain the inverse texture gradient component, wherein the inverse texture gradient component represents the gray-level abrupt change generated along the texture normal direction.
6. The visual image enhancement processing method for workpiece defect feature points according to claim 1, characterized in that, The nonlinear amplification function adopts A function or a piecewise linear function, configured as follows: Determine the numerical relationship between the magnitude of the gradient component along the texture and a preset noise threshold; If the magnitude of the gradient component along the texture is greater than the preset noise threshold, then the first gain coefficient is output. If the magnitude of the gradient component along the texture is less than or equal to the preset noise threshold, then the second gain coefficient is output. The value of the first gain coefficient is greater than the value of the second gain coefficient.
7. The visual image enhancement processing method for workpiece defect feature points according to claim 1, characterized in that, It also includes step S6: S61. Perform binarization thresholding segmentation on the enhanced image; S62. Extract the area features and aspect ratio features of the segmented connected regions. If the area features are greater than a preset area threshold and the aspect ratio features are greater than a preset aspect ratio threshold, then it is determined that there are scratches or cracks on the workpiece surface area corresponding to the connected region; otherwise, it is determined that the connected region is a non-defect region.