A digital image processing method and apparatus

By employing a multi-scale edge feature weighted extraction and neighborhood pixel gradient direction fusion method, the problem of image edge detail loss in existing technologies is solved, achieving clear presentation of fine and coarse edges and regional smoothness consistency in images, thus improving processing efficiency.

CN122156007APending Publication Date: 2026-06-05ZHEJIANG SHUYUN CULTURE COMMUNICATION CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
ZHEJIANG SHUYUN CULTURE COMMUNICATION CO LTD
Filing Date
2026-01-20
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Existing technologies cannot effectively distinguish between fine edges such as tiny patterns and minor cracks and coarse edges such as object outlines and large-area boundaries when processing images, resulting in the loss of key edge details in the output image and low processing efficiency.

Method used

A multi-scale edge feature weighted extraction and neighborhood pixel gradient direction fusion method is adopted. By constructing Gaussian smoothing kernels of different scales for convolution operation, combined with adaptive weight allocation and gradient direction angle calculation, fine edges and coarse edges in the image are distinguished and enhanced, and image contrast adjustment and binarization processing are performed.

Benefits of technology

It achieves clear rendering of both fine and coarse edges in images, reduces the loss of weak edges, improves regional smoothness consistency and edge preservation, and enhances processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122156007A_ABST
    Figure CN122156007A_ABST
Patent Text Reader

Abstract

The application discloses a kind of digital image processing method, comprising the following steps: S1, image gray scale;S2, image noise filtering;S3, multi-scale edge feature weighted extraction;S4, image contrast adjustment;S5, neighborhood pixel gradient direction fusion;S6, image binarization;A kind of digital image processing device includes the following modules: scale kernel generation module;Hierarchical response acquisition module;Dynamic weight regulation module;Neighborhood direction identification module;Region fusion processing module;The present application is different degree of smoothing processing to image by using different scale Gaussian kernel, small scale Gaussian kernel retains fine edge details, large scale Gaussian kernel captures rough edge contour, then according to the relative size of each scale edge response value distribution weight, improve the proportion of weak edge region in fusion result, ensure that weak edge feature is not covered by strong edge, enhance the hierarchical relationship that image can clearly present fine edge and rough edge, reduce the problem of weak edge loss.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and more particularly to a digital image processing method and apparatus. Background Technology

[0002] Image processing is an interdisciplinary field based on optics, mathematics, and computer technology. It involves the acquisition, conversion, analysis, and optimization of image signals to enhance, extract, and reconstruct image information. It is widely used in various fields such as target recognition, medical image analysis, industrial inspection, and security monitoring.

[0003] The digital image processing method and digital image processing device disclosed in patent publication number "CN102509253B" can overcome the shortcomings of the prior art, such as excessive memory resource consumption and low processing efficiency, by optimizing the processing of images or video images.

[0004] However, in actual use, when traversing and processing pixels, only the brightness attribute of a single pixel is judged, without capturing the grayscale change relationship between pixels. It is unable to distinguish between fine edges such as small patterns and tiny cracks and coarse edges such as object outlines and large area boundaries, which can easily lead to the loss of key edge details in the output image.

[0005] Accordingly, this application proposes a digital image processing method and apparatus. Summary of the Invention

[0006] The purpose of this invention is to address the shortcomings of existing technologies by proposing a digital image processing method and apparatus.

[0007] To achieve the above objectives, the present invention adopts the following technical solution:

[0008] A digital image processing method includes the following steps:

[0009] S1, Image Grayscale Conversion

[0010] Input a 24-bit color image. Based on the visual characteristics that the human eye is most sensitive to green, followed by red, and least sensitive to blue, set the weight coefficient of the red channel to 0.299, the weight coefficient of the green channel to 0.587, and the weight coefficient of the blue channel to 0.114. Calculate the gray value of each pixel using a weighted average formula.

[0011] Its weighting formula is:

[0012] A color image containing red, green, and blue channels is converted into an 8-bit single-channel grayscale image while preserving the core brightness information of the image.

[0013] S2, Image Noise Filtering

[0014] A mean filter with a fixed-size 3×3 window is used to denoise the grayscale image. The average grayscale value of all pixels within the window is calculated as the target pixel grayscale value. For pixels at the image boundaries, a mirror filling strategy is used to supplement missing neighboring pixels to ensure that the filtering effect is consistent between boundary and non-boundary areas.

[0015] S3, Multi-scale Edge Feature Weighted Extraction

[0016] Three Gaussian smoothing kernels with scale parameters of 1.0, 2.0, and 3.0 are constructed. The three Gaussian kernels are convolved with the noise-filtered grayscale image to obtain three smooth images at different scales. The difference image between the smooth images at adjacent scales is calculated to obtain the Gaussian difference image.

[0017] The edge response value of each pixel in the difference image is extracted, and an adaptive weight is assigned according to the relative size of the edge response value. The weaker edge region with the lower response value has a higher weight coefficient. The difference images at different scales are multiplied with the corresponding weight coefficients and then weighted and fused to output an edge-enhanced image, so as to clearly present the hierarchical relationship between fine edges and coarse edges and reduce the problem of weak edge loss.

[0018] S4, Image Contrast Adjustment

[0019] The gamma transform is used to adjust the grayscale distribution of an image. The transformation formula is as follows:

[0020]

[0021] The transformation coefficients range from 0.5 to 1.5, and the power operation enhances the visibility of details in the dark areas of the image and improves the overall contrast of the image.

[0022] S5, Neighborhood Pixel Gradient Direction Fusion

[0023] The Sobel operator is used to calculate the horizontal and vertical gradients of each pixel in the gamma-transformed image. The gradient direction angle of each pixel is then calculated based on the gradient values. The formula for calculating the direction angle is:

[0024]

[0025] A 5×5 fixed-size neighborhood window is selected, and the orientation angle difference between each neighboring pixel and the center pixel is calculated. The orientation angle difference threshold is set to 15°. Pixels with a difference less than the threshold are classified as homogeneous pixels with the same orientation and are assigned a high weight coefficient. Pixels with a difference greater than the threshold are classified as edge or noise pixels and are assigned a low weight coefficient.

[0026] S6, Image Binarization

[0027] A fixed threshold method is used to convert grayscale images that have undergone contrast adjustment or gradient fusion into binary images containing only black and white. The grayscale threshold is set to a range of 100-150. Pixels with grayscale values ​​greater than or equal to the threshold are assigned a value of 255, and pixels with grayscale values ​​less than the threshold are assigned a value of 0, thus simplifying image information to meet the needs of subsequent processing.

[0028] Preferably, in step S1, after calculating the pixel grayscale value using the weighted average formula, grayscale value normalization processing is added to map the grayscale value to the standard range of 0-255.

[0029] At the same time, abnormal grayscale values ​​that exceed this range need to be removed to avoid abnormal values ​​interfering with subsequent filtering and edge extraction steps.

[0030] Preferably, in step S2, the mean filtering window adopts a pixel-by-pixel traversal method with a sliding step size of 1, and before calculating the average gray value of pixels in the window, extreme noise pixels in the window are removed by median preprocessing to further improve the noise reduction effect.

[0031] Preferably, in step S3, during adaptive weight allocation, an edge confidence determination mechanism is introduced. By judging the continuity of edge response values, true weak edges are selected, and the weight coefficient is increased only for true weak edge regions to avoid misassigning high weights to isolated noise points.

[0032] Preferably, in step S4, the gamma transform coefficients An adaptive adjustment method is adopted. By calculating the mean of the grayscale histogram of the image, if the mean is lower than the preset threshold, a transformation coefficient of 0.5-0.8 is selected, and if the mean is higher than the preset threshold, a transformation coefficient of 1.2-1.5 is selected, so as to achieve accurate adaptation to images with different brightness.

[0033] Preferably, in step S5, for pixels determined to be edges, their gradient magnitude is further calculated, and only strong edge pixels with gradient magnitude greater than a preset threshold are retained and their original grayscale values ​​are maintained. For weak edge pixels with small gradient magnitude, low-intensity smoothing processing is performed to achieve differentiated protection at the edge level.

[0034] At the same time, weighted average smoothing is only performed on pixels in homogeneous areas, while pixels in edge areas retain their original grayscale values. This achieves targeted smoothing of image areas, preserves edge sharpness, avoids the image edge blurring problem caused by traditional global filtering, and improves the smoothness consistency of homogeneous areas and the contour clarity of edge areas.

[0035] Preferably, in step S6, a fixed threshold is used. The threshold is determined adaptively using the Otsu algorithm. First, the inter-class variance of the image's gray-level histogram is calculated, and the gray-level value corresponding to the maximum inter-class variance is selected as the threshold. This improves the accuracy of dividing the target area into the background area.

[0036] A digital image processing apparatus includes the following modules:

[0037] Scale kernel generation module

[0038] Configured to construct filtering kernels with at least three different scale parameters, by adjusting the size and distribution parameters of the kernels, targeted capture of different width features such as weak edges, regular edges and thick edges in the image is achieved, providing a basic filtering unit for subsequent layered processing;

[0039] Layered response acquisition module

[0040] Each scale filter kernel is convolved with the input image independently to avoid mutual interference between features of different scales during processing. The image edge feature response result map at the corresponding scale is output independently, and the original signal information of each type of edge is preserved.

[0041] Dynamic weight adjustment module

[0042] Based on the feature signal intensity of pixels in the edge response map at each scale, the weight ratio of features at different scales in the subsequent fusion process is adaptively adjusted in real time, prioritizing the enhancement of the feature signal ratio of weak edge regions and avoiding the coverage of weak edges by strong edge signals.

[0043] Neighborhood direction recognition module

[0044] Calculate the horizontal and vertical gradient information and the corresponding gradient direction angle of each pixel in the image. Through a neighborhood window of a preset size, determine the matching degree of the direction angle of each pixel in the window and distinguish the pixels in the edge region from the pixels in the homogeneous region.

[0045] Regional fusion processing module

[0046] Based on the neighborhood orientation recognition results, homogeneous pixel regions with matching orientation angles are selected, and a weighted fusion smoothing operation is performed on them to improve region consistency while maintaining the feature integrity of pixels in image edge regions and avoiding edge blurring during the smoothing process.

[0047] The present invention has the following beneficial effects:

[0048] First, a multi-scale edge feature weighted extraction step is used to extract and enhance edge features at multiple scales. Different scale Gaussian kernels are used to smooth the image to varying degrees. Small-scale Gaussian kernels preserve fine edge details, while large-scale Gaussian kernels capture coarse edge contours. Weights are then assigned based on the relative magnitude of the edge response values ​​at each scale to increase the proportion of weak edge regions in the fusion result. This ensures that weak edge features are not covered by strong edges, and the enhanced image can clearly present the hierarchical relationship between fine and coarse edges, reducing the problem of weak edge loss.

[0049] Second, through the neighboring pixel gradient direction fusion step, the horizontal and vertical gradients are first calculated by the difference between adjacent pixels, and then the gradient direction angle is calculated based on the gradient value to determine the direction of gray-level change of the pixel. The difference in direction angle between neighboring pixels and the center pixel is calculated, and pixels in the same area are distinguished from edge or noise pixels based on the difference. Pixels with the same direction are given high weight, and pixels with abrupt changes in direction are given low weight. Smoothing is only performed on pixels in the same area, and the original gray-level value of pixels in the edge area is retained. This achieves a balance between area smoothing and edge preservation, solves the edge blurring problem of traditional smoothing methods, and improves the smoothness consistency of image areas.

[0050] Third, the edge-enhanced image output by the multi-scale edge feature weighted extraction step provides a precise edge location reference for the neighborhood pixel gradient direction fusion step, enabling the neighborhood fusion step to quickly distinguish between real edges and homogeneous regions, avoiding misjudgment of edges during the smoothing process. At the same time, when smoothing homogeneous regions, the neighborhood pixel gradient direction fusion step identifies and eliminates false edges caused by noise interference in the multi-scale edge extraction step, and inversely optimizes the quality of the edge-enhanced image. They support and correct each other, forming a complete error correction closed loop from edge extraction to region optimization, solving the problem that edge extraction and region smoothing are independent and errors accumulate in traditional techniques. The final output image has purer edges and more uniform regions. Attached Figure Description

[0051] Figure 1 This is a flowchart of a digital image processing method proposed in this invention;

[0052] Figure 2 This is a sub-flowchart of a digital image processing method proposed in this invention, which involves multi-scale edge feature weighted extraction and fusion of neighboring pixel gradient directions.

[0053] Figure 3 This is a diagram of the core node interaction architecture of a digital image processing device proposed in this invention. Detailed Implementation

[0054] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.

[0055] Example 1:

[0056] Method implementation:

[0057] S1, Image Grayscale Conversion

[0058] Input a 24-bit color image with a resolution of 1920×1080 pixels. The image content is a mechanical part in an industrial scene (including details such as metal outlines and faint scratches). The red (R), green (G), and blue (B) channels of each pixel range from 0 to 255. For any pixel at coordinates (x, y) in the image, convert it to a grayscale value using a weighted average method that conforms to the characteristics of human vision. The specific formula is as follows:

[0059]

[0060] During the calculation, the brightness values ​​of the three channels are first multiplied by their corresponding weighting coefficients, and then summed to obtain the original grayscale value. This result is then rounded to the nearest integer and subjected to amplitude limiting (0 if the result is <0, 255 if >255) to avoid abnormal grayscale values ​​exceeding the display range. The final output is a 1920×1080 pixel single-channel grayscale image that fully preserves the core brightness distribution of the original color image, clearly revealing the contrast characteristics of the metal parts.

[0061] S2, Image Noise Filtering

[0062] Because industrial image acquisition is susceptible to ambient light and sensor noise, grayscale images are often mixed with Gaussian noise (mean 0, variance 15) and salt-and-pepper noise (density 0.02), causing blurring and interference with image details. To address this issue, a mean filter with a 3×3 fixed-size window is used for noise reduction. Specific operation: [The text abruptly ends here, likely due to an incomplete sentence or missing information.] Centered on the target, a 3×3 window is selected, containing itself and its 8 surrounding pixels. The filtering formula is as follows:

[0063] in These are the original grayscale values ​​of each pixel within the window. This represents the grayscale value of the target pixel after filtering.

[0064] S4, Image Contrast Adjustment

[0065] Gamma transformation is used to adjust the overall contrast, with a gamma coefficient of 1.2 selected. The transformation formula is as follows:

[0066] The calculation first normalizes the grayscale values ​​of the denoised image to the range of 0 to 1, then performs exponentiation, and finally restores the result to the grayscale range of 0 to 255. This process can effectively improve the visibility of details in the dark areas of the image and output a contrast-optimized grayscale image.

[0067] S6, Image Binarization

[0068] To simplify the subsequent contour extraction process for mechanical parts, a fixed threshold method is used to convert the contrast-optimized grayscale image into a black-and-white binary image. A threshold is selected by analyzing the image's grayscale histogram. The specific formula used to distinguish the target (part) from the background is as follows:

[0069]

[0070] During implementation, the grayscale value of each pixel is compared with the threshold: pixels with a grayscale value ≥ 128 (such as the main body of the metal part) are assigned a value of 255 (white), and pixels with a grayscale value < 128 (such as the background and gaps) are assigned a value of 0 (black). The final output is a binary image of 1920×1080 pixels. The outline edges of the metal parts in the image are clearly separated, without obvious adhesion or breakage, and can be directly used for subsequent contour detection and size measurement.

[0071] Example 2:

[0072] Method implementation:

[0073] S1, Image Grayscale Conversion

[0074] Same as Example 1

[0075] S2, Image Noise Filtering

[0076] Same as Example 1

[0077] S3, Multi-scale Edge Feature Weighted Extraction

[0078] First, three Gaussian kernels with different scales are selected, with the scale parameters being as follows: 1.0 2.0 3.0, the Gaussian kernel formula is:

[0079] Based on the properties of the Gaussian function, the kernel size is To ensure the effective coverage of the kernel, the values ​​at each position within each kernel are normalized so that the sum of all elements within the kernel is 1, thus avoiding distortion of the image grayscale values ​​after convolution.

[0080] The denoised image is convolved with three normalized Gaussian kernels in two dimensions to obtain three images with different smoothing levels. The convolution operation is implemented by calculating the sum of the products of kernel elements and corresponding image pixels pixel by pixel using a sliding window. Then, the difference between smoothed images of adjacent scales is calculated using the following formula:

[0081] * indicates a two-dimensional convolution operation. During the convolution process, the image boundaries are mirrored to ensure that the output image size is consistent with the input, ultimately resulting in two Gaussian difference images.

[0082] For each Gaussian difference image, calculate the gradient magnitude and use it as the edge response value. The formula is as follows:

[0083] The directional gradient is:

[0084] The directional gradient is:

[0085] Adaptive weights are assigned based on the relative magnitudes of the edge response values ​​at each scale, using the following formula: This ensures that the sum of the weights for all scales is 1, thereby increasing the weight of weak edge regions.

[0086] The two Gaussian difference images are weighted and summed according to the calculated adaptive weights, as shown in the formula: After fusion, the image is normalized to map the grayscale values ​​to the range of 0~255, and finally outputs a grayscale image with enhanced edge features.

[0087] S4, Image Contrast Adjustment

[0088] Same as Example 1

[0089] S6, Image Binarization

[0090] Same as Example 1

[0091] Device Applications:

[0092] Scale kernel generation module

[0093] The system receives preset scale parameters of 1.0, 2.0, and 3.0, generates corresponding scale filter kernels based on a Gaussian function model, and determines the effective size of the kernel according to the distribution characteristics of the Gaussian function to ensure coverage adaptability for edges of different widths. Then, the normalization processing unit is started to perform normalization operations on the elements in each filter kernel so that the sum of the elements in the kernel is 1, avoiding image grayscale value distortion caused by subsequent convolution operations. Finally, three standardized multi-scale filter kernels are output, providing the core operation unit for hierarchical response extraction.

[0094] Layered response acquisition module

[0095] The module loads the denoised image and the multi-scale filtering kernel output from the scale kernel generation module. Through the built-in multi-channel convolution unit, it performs independent two-dimensional convolution operations on the denoised image and each scale filtering kernel to obtain images with different smoothness levels. Then, the difference between adjacent scale smoothed images is calculated through the difference operation unit to generate a Gaussian difference image. To address the issue of missing boundary pixels during the convolution process, the module automatically enables a mirror filling mechanism to supplement missing pixels, ensuring that the output image size is consistent with the input, realizing the layered extraction of edge features at different scales, and avoiding feature interference between scales.

[0096] Dynamic weight adjustment module

[0097] This module receives the Gaussian difference image output by the hierarchical response acquisition module, calculates the horizontal and vertical gradients of each image through the gradient calculation unit, and obtains the gradient magnitude as the edge response value. Based on the relative magnitude of the edge response values ​​at each scale, the weight ratio of each scale is calculated through an adaptive weight allocation algorithm to ensure that the sum of the weights is 1, and to focus on enhancing the weight of weak edge regions. Finally, the weighted fusion unit sums the Gaussian difference images at each scale according to the weights, and after normalization, outputs a grayscale image with enhanced edge features, realizing weak edge enhancement and full-scale edge integration.

[0098] Example 3

[0099] Method implementation:

[0100] S1, Image Grayscale Conversion

[0101] Same as Example 1

[0102] S2, Image Noise Filtering

[0103] Same as Example 1

[0104] S4, Image Contrast Adjustment

[0105] Same as Example 1

[0106] S5, Neighborhood Pixel Gradient Direction Fusion

[0107] The formulas for calculating the horizontal and vertical gradients of the contrast-adjusted image are as follows:

[0108]

[0109] The gradient value reflects the trend of pixel grayscale value changes. For boundary pixels, mirroring is used to fill in missing adjacent pixels to ensure the completeness of gradient calculation, ultimately yielding... , Gradient image of the orientation.

[0110] according to , The gradient direction angle of each pixel is calculated using the following formula: The range of the direction angle is .

[0111] when At that time, if Then the direction angle is ,like Then the direction angle is Finally, the gradient direction angle image is obtained.

[0112] A 5×5 neighborhood window is used for fusion processing. The window is formed by selecting 24 neighboring pixels centered on the target pixel. The absolute difference in orientation angle between each pixel in the neighborhood and the center pixel is calculated using the following formula: A threshold of 15° is set to distinguish pixels in the same area from edge or noise pixels.

[0113] Weights are assigned based on the directional consistency determination results, using the following formula:

[0114]

[0115] Pixels with consistent orientation are assigned high weights, while pixels with abrupt changes in orientation are assigned low weights. Then, using the formula:

[0116]

[0117] A weighted average calculation is performed, and the grayscale values ​​of the merged images are corrected to the range of 0~255, resulting in a smooth grayscale image output.

[0118] S6, Image Binarization

[0119] Same as Example 1

[0120] Device Applications:

[0121] Neighborhood direction recognition module

[0122] The system loads a contrast-adjusted grayscale image and calculates the horizontal and vertical gradients of each pixel using a gradient calculation unit to reflect the trend of pixel grayscale changes. To address the issue of missing adjacent pixels at boundary pixels, a mirror filling mechanism is enabled to supplement missing pixels, ensuring the integrity of gradient calculation across the entire image and outputting horizontal and vertical gradient images. Subsequently, the orientation angle calculation unit calculates the gradient orientation angle of each pixel based on the gradient value and handles special cases (such as orientation angle determination when the gradient is 0) using preset rules to constrain the orientation angle within a reasonable range. Finally, the system outputs a gradient orientation angle image, providing directional feature basis for region differentiation.

[0123] Regional fusion processing module

[0124] The system receives the gradient orientation angle image output by the neighborhood orientation recognition module, activates a 5×5 neighborhood window unit, and constructs a neighborhood range centered on each pixel. The orientation consistency determination unit calculates the orientation angle difference between pixels in the neighborhood and the center pixel, and distinguishes homogeneous region pixels from edge / noise pixels with a threshold of 15°. Subsequently, the weight allocation unit assigns high weights to homogeneous region pixels with consistent orientations and low weights to pixels with abrupt orientation changes. Finally, the weighted averaging unit corrects the grayscale value of the center pixel, and after grayscale value range correction, outputs a smooth grayscale image of the region, achieving smooth noise reduction in homogeneous regions and accurate preservation of edge regions.

[0125] Example 4

[0126] Method implementation:

[0127] S1, Image Grayscale Conversion

[0128] Same as Example 1

[0129] S2, Image Noise Filtering

[0130] Same as Example 1

[0131] S3, Multi-scale Edge Feature Weighted Extraction

[0132] Same as Example 2

[0133] S4, Image Contrast Adjustment

[0134] Same as Example 1

[0135] S5, Neighborhood Pixel Gradient Direction Fusion

[0136] Using the contrast-adjusted edge-enhanced image as input, the formula is: +

[0137] calculate , For directional gradients, mirror-padding is used to fill in missing pixels at the boundary to ensure the completeness of gradient calculation. Then, using the formula: The gradient direction angle is calculated, and the range of values ​​and special case handling are the same as in Example 3. The gradient direction angle image is output.

[0138] Using a 5×5 neighborhood window, with the target pixel Select 24 neighboring pixels around the center using the formula The difference in orientation angles is calculated, and orientation consistency is determined with a threshold of 15°. At this point, the input image has undergone edge enhancement, and the gradient orientation angles can more accurately reflect the edge direction, making it easier to distinguish between edge regions and smooth regions.

[0139] Through formula Assign weights.

[0140] Through formula The weighted average calculation is performed. This process constrains the fusion range based on the edge features extracted by the multi-scale edge feature step. Weighted fusion is only performed on smooth regions, completely avoiding smoothing of edge regions. At the same time, it eliminates the false edge noise introduced by the multi-scale edge feature step. After fusion, the gray value is corrected to the range of 0~255, and the output is a grayscale image with both clear edges and smooth regions.

[0141] S6, Same as Example 1

[0142] Device Applications:

[0143] Scale kernel generation module

[0144] The system receives preset scale parameters of 1.0, 2.0, and 3.0, generates corresponding scale filter kernels based on a Gaussian function model, and determines the effective size of the kernel according to the distribution characteristics of the Gaussian function to ensure coverage adaptability for edges of different widths. Then, the normalization processing unit is started to perform normalization operations on the elements in each filter kernel so that the sum of the elements in the kernel is 1, avoiding image grayscale value distortion caused by subsequent convolution operations. Finally, three standardized multi-scale filter kernels are output, providing the core operation unit for hierarchical response extraction.

[0145] Layered response acquisition module

[0146] The module loads the denoised image and the multi-scale filtering kernel output from the scale kernel generation module. Through the built-in multi-channel convolution unit, it performs independent two-dimensional convolution operations on the denoised image and each scale filtering kernel to obtain images with different smoothness levels. Then, the difference between adjacent scale smoothed images is calculated through the difference operation unit to generate a Gaussian difference image. To address the issue of missing boundary pixels during the convolution process, the module automatically enables a mirror filling mechanism to supplement missing pixels, ensuring that the output image size is consistent with the input, realizing the layered extraction of edge features at different scales, and avoiding feature interference between scales.

[0147] Dynamic weight adjustment module

[0148] This module receives the Gaussian difference image output by the hierarchical response acquisition module, calculates the horizontal and vertical gradients of each image through the gradient calculation unit, and obtains the gradient magnitude as the edge response value. Based on the relative magnitude of the edge response values ​​at each scale, the weight ratio of each scale is calculated through an adaptive weight allocation algorithm to ensure that the sum of the weights is 1, and to focus on enhancing the weight of weak edge regions. Finally, the weighted fusion unit sums the Gaussian difference images at each scale according to the weights, and after normalization, outputs a grayscale image with enhanced edge features, realizing weak edge enhancement and full-scale edge integration.

[0149] Neighborhood direction recognition module

[0150] The system loads a contrast-adjusted grayscale image and calculates the horizontal and vertical gradients of each pixel using a gradient calculation unit to reflect the trend of pixel grayscale changes. To address the issue of missing adjacent pixels at boundary pixels, a mirror filling mechanism is enabled to supplement missing pixels, ensuring the integrity of gradient calculation across the entire image and outputting horizontal and vertical gradient images. Subsequently, the orientation angle calculation unit calculates the gradient orientation angle of each pixel based on the gradient value and handles special cases (such as orientation angle determination when the gradient is 0) using preset rules to constrain the orientation angle within a reasonable range. Finally, the system outputs a gradient orientation angle image, providing directional feature basis for region differentiation.

[0151] Regional fusion processing module

[0152] The system receives the gradient orientation angle image output by the neighborhood orientation recognition module, activates a 5×5 neighborhood window unit, and constructs a neighborhood range centered on each pixel. The orientation consistency determination unit calculates the orientation angle difference between pixels in the neighborhood and the center pixel, and distinguishes homogeneous region pixels from edge / noise pixels with a threshold of 15°. Subsequently, the weight allocation unit assigns high weights to homogeneous region pixels with consistent orientations and low weights to pixels with abrupt orientation changes. Finally, the weighted averaging unit corrects the grayscale value of the center pixel, and after grayscale value range correction, outputs a smooth grayscale image of the region, achieving smooth noise reduction in homogeneous regions and accurate preservation of edge regions.

[0153] It should be noted that, comparing the various embodiments, Comparative Example 1 uses the Canny edge detection algorithm, which first removes image noise through Gaussian filtering, then calculates the image gradient magnitude and direction, uses non-maximum suppression to filter edge pixels, and finally uses a double thresholding method to determine strong and weak edges and complete edge connection; Comparative Example 2 uses a 5×5 Gaussian filtering algorithm, which performs overall image smoothing through a single-scale Gaussian kernel to eliminate abrupt changes in local pixel gradients. Specific experimental parameters are shown in Table 1.

[0154] Table 1: Comparison of Core Performance Indicators of Digital Image Processing Methods

[0155] Comparison Projects Weak edge detection coverage (%) Image region smoothness consistency (%) Isolated noise points in a binary image (number of points) Edge contour overlap with the original image (%) Total image processing time (ms) Example 1 52.3 61.5 128 76.4 18.2 Example 2 94.7 63.2 112 92.5 22.5 Example 3 55.6 92.8 23 78.3 24.3 Example 4 97.2 95.3 10 98.1 27.6 Comparative Example 1 47.8 57.6 156 71.9 35.8 Comparative Example 2 50.4 88.7 31 74.6 32.4

[0156] Specifically, Example 1, as the basic scheme, achieved a weak edge recognition coverage rate of 52.3%, which is 4.5 percentage points higher than the 47.8% of the traditional Canny edge detection method in Comparative Example 1, and 1.9 percentage points higher than the 50.4% of the traditional 5×5 Gaussian smoothing method in Comparative Example 2. The core reason for this is that the grayscale step in Example 1 allocates channel weights based on the characteristics of human visual perception, which can more accurately preserve the brightness difference information in low-contrast areas. In contrast, the dual-threshold screening mechanism of the traditional Canny algorithm easily filters weak edge signals, and the traditional Gaussian smoothing method directly blurs weak edge details. Regarding the number of isolated noise points, Example 1 has 128, far lower than the 156 in Comparative Example 1. This is because the mean filtering combined with mirror filling boundary processing strategy in Example 1 avoids the filtering distortion caused by pixel loss in boundary areas in traditional methods, reducing noise amplification. Meanwhile, the overall image processing time of Example 1 is only 18.2ms, which is 17.6ms and 14.2ms shorter than that of Comparative Example 1 (35.8ms) and Comparative Example 2 (32.4ms), respectively. This is mainly attributed to the fact that the steps in Example 1 are more streamlined, without redundant computational steps such as non-maximum suppression and edge connection in the traditional Canny algorithm, and without the large-size kernel convolution operation of the traditional Gaussian smoothing algorithm. This comprehensively proves that the basic process of the present invention has significant technical advantages.

[0157] Furthermore, after introducing step S3 in Example 2, the weak edge recognition coverage rate increased from 52.3% in Example 1 to 94.7%, an increase of 42.4 percentage points. In-depth analysis of the data changes reveals that this step, by constructing Gaussian kernels of different scales (1.0, 2.0, and 3.0), can capture fine, medium, and coarse edge information in the image respectively, overcoming the technical limitation of traditional edge detection methods that can only identify strong edges with a single-scale kernel. Simultaneously, the adaptive weight allocation mechanism dynamically adjusts the weights according to the magnitude of edge response values ​​at different scales, prioritizing the retention of feature signals in weak edge regions and preventing weak edges from being covered by strong edges. In terms of the overlap between edge contours and the original image, Example 2 achieved 92.5%, an improvement of 16.1 percentage points compared to 76.4% in Example 1. This is because the edge features after weighted fusion are closer to the true edge contours of the original image, effectively reducing false edge interference caused by improper threshold settings in traditional algorithms. Furthermore, the number of isolated noise points in Example 2 was reduced to 112, a decrease of 16 compared to Example 1. This indicates that while enhancing edge features, this step also filtered out some noise signals through Gaussian difference operations, further verifying the independent technical value of this step.

[0158] After introducing a neighborhood pixel gradient direction fusion step in Example 3, the smoothness consistency of the image region improved from 61.5% in Example 1 to 92.8%, an increase of 31.3 percentage points. The core principle is that this step, by calculating the horizontal and vertical gradients and gradient direction angles of pixels, can accurately distinguish between homogeneous region pixels and edge pixels. Using a 5×5 neighborhood window combined with direction consistency judgment, only homogeneous region pixels with a direction angle difference ≤15° are weighted and fused, avoiding the indiscriminate smoothing of the entire image by traditional Gaussian smoothing algorithms. Regarding the number of isolated noise points, Example 3 sharply reduced it from 128 in Example 1 to 23, a decrease of 82.0%. This is because this step can specifically eliminate noise caused by local gradient abrupt changes, while traditional smoothing algorithms have limited noise suppression effects. Meanwhile, the edge contour overlap rate in Example 3 remained at 78.3%, only slightly lower than Example 1 by 2.1 percentage points, far better than the 74.6% caused by over-smoothing in Comparative Example 2, proving that this step efficiently smooths noise without causing excessive blurring of edges.

[0159] Example 4, by combining multi-scale edge feature weighted extraction and neighborhood pixel gradient direction fusion, achieved the best performance across all metrics, demonstrating a synergistic effect. Regarding weak edge recognition coverage, Example 4 reached 97.2%, a 2.5 percentage point improvement over Example 2. In-depth analysis revealed that the neighborhood pixel gradient direction fusion step accurately identified and eliminated pseudo-edge noise introduced by the multi-scale edge feature weighted extraction step, further refining the edge signal and improving weak edge recognition accuracy. In terms of image region smoothness consistency, Example 4 reached 95.3%, a 2.5 percentage point improvement over Example 3. This is because the accurate edge position reference provided by the multi-scale edge feature weighted extraction step makes the smoothing process of the neighborhood pixel gradient direction fusion step more targeted, avoiding erroneous smoothing of edge regions. Regarding the number of isolated noise points, Example 4 had only 10, the lowest value in the group, reflecting the combined effect of the two-step synergistic noise reduction. Regarding edge contour overlap, Example 4 reached 98.1%, a 5.6 percentage point improvement over Example 2 and a 19.8 percentage point improvement over Example 3, proving that the two-step synergy achieved bidirectional optimization of edge enhancement and region smoothing. In terms of processing time, Example 4 takes 27.6ms, which is higher than the previous three examples, but much lower than Comparative Example 1 (35.8ms) and Comparative Example 2 (32.4ms). It achieves a balance between high precision and high efficiency, fully verifying the technical innovation and practicality of the present invention.

[0160] Specifically, such as Figure 2As shown, this process represents a technological breakthrough in achieving accurate weak edge recognition through multi-scale edge feature weighted extraction. First, three Gaussian kernels of different scales (1.0, 2.0, and 3.0) are constructed. The small-scale kernel captures fine edge details, the medium-scale kernel adapts to regular medium-width edges, and the large-scale kernel extracts coarse edge contours, overcoming the limitations of traditional single-scale methods. Then, hierarchical convolutional filtering yields three independent edge response maps, preventing interference between features of different scales and preventing strong edge signals from overshadowing weak edge signals. Subsequently, the edge response values ​​of each response map are calculated, and weights are dynamically allocated based on these values. The weight of the corresponding scale kernel is increased for weak edge regions, while the weight of strong edge regions is appropriately reduced. Finally, weighted fusion and low-threshold filtering are used to obtain a complete edge map. Based on data from Example 2, this sub-process increases the weak edge recognition coverage from 52.3% to 94.7% and the edge contour overlap from 76.4% to 92.5%, fundamentally solving the technical pain points of traditional edge detection, which easily misses weak edges and misjudges false edges.

[0161] Specifically, such as Figure 2 As shown, the core of neighborhood pixel gradient direction fusion is to first distinguish pixel types and then perform directional smoothing and noise reduction, thus resolving the contradiction that traditional smoothing algorithms cannot simultaneously achieve smoothing and edge preservation. The first step of the process calculates the horizontal and vertical gradients and gradient direction angles of each pixel. Gradient parameters are used to quantify and distinguish edge pixels from pixels in homogeneous regions—edge pixels have larger gradient values ​​and significantly different direction angles, while pixels in homogeneous regions have smaller gradient values ​​and more consistent direction angles. Next, a 5×5 neighborhood window is used, with a threshold of ≤15° for selecting homogeneous regions. Only pixels meeting this condition are subjected to weighted fusion smoothing, while edge pixels are directly retained and not included in the calculation, unlike the traditional global filtering mode that smooths indiscriminately. Performance data from Example 3 shows that this sub-process improves image region smoothing consistency from 61.5% to 92.8%, reduces the number of isolated noise points from 128 to 23, and only slightly decreases the edge contour overlap to 78.3%, ensuring both smoothing and noise reduction effects in homogeneous regions and maximizing the preservation of edge integrity.

[0162] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.

Claims

1. A digital image processing method, characterized in that, Includes the following steps: S1, Image Grayscale Conversion Input a 24-bit color image. Based on the visual characteristics that the human eye is most sensitive to green, followed by red, and least sensitive to blue, set the weight coefficient of the red channel to 0.299, the weight coefficient of the green channel to 0.587, and the weight coefficient of the blue channel to 0.

114. Calculate the gray value of each pixel using a weighted average formula. Its weighting formula is: A color image containing red, green, and blue channels is converted into an 8-bit single-channel grayscale image while preserving the core brightness information of the image. S2, Image Noise Filtering A mean filter with a fixed-size 3×3 window is used to denoise the grayscale image. The average grayscale value of all pixels within the window is calculated as the target pixel grayscale value. For pixels at the image boundaries, a mirror filling strategy is used to supplement missing neighboring pixels to ensure that the filtering effect is consistent between boundary and non-boundary areas. S3, Multi-scale Edge Feature Weighted Extraction Three Gaussian smoothing kernels with scale parameters of 1.0, 2.0, and 3.0 are constructed. The three Gaussian kernels are convolved with the noise-filtered grayscale image to obtain three smooth images at different scales. The difference image between the smooth images at adjacent scales is calculated to obtain the Gaussian difference image. The edge response value of each pixel in the difference image is extracted, and an adaptive weight is assigned according to the relative size of the edge response value. The weaker edge region with the lower response value has a higher weight coefficient. The difference images at different scales are multiplied with the corresponding weight coefficients and then weighted and fused to output an edge-enhanced image, so as to clearly present the hierarchical relationship between fine edges and coarse edges and reduce the problem of weak edge loss. S4, Image Contrast Adjustment The gamma transform is used to adjust the grayscale distribution of an image. The transformation formula is as follows: Where the transformation coefficients The value ranges from 0.5 to 1.

5. It enhances the visibility of details in dark areas of the image and improves the overall contrast of the image through exponentiation. S5, Neighborhood Pixel Gradient Direction Fusion The Sobel operator is used to calculate the horizontal and vertical gradients of each pixel in the gamma-transformed image. The gradient direction angle of each pixel is then calculated based on the gradient values. The formula for calculating the direction angle is: Select a 5×5 fixed-size neighborhood window and calculate the difference in orientation angle between each neighboring pixel and the center pixel within the window; The orientation angle difference threshold is set to 15°. Pixels with a difference less than the threshold are identified as homogeneous regions with the same orientation and are assigned a high weight coefficient. Pixels with a difference greater than the threshold are identified as edge or noise pixels and are assigned a low weight coefficient. S6, Image Binarization A fixed threshold method is used to convert grayscale images that have undergone contrast adjustment or gradient fusion into binary images containing only black and white. A grayscale threshold is set. The value range is 100-150. Pixels with gray values ​​greater than or equal to the threshold are assigned a value of 255, and pixels with gray values ​​less than the threshold are assigned a value of 0, simplifying image information to adapt to subsequent processing needs.

2. The digital image processing method according to claim 1, characterized in that, In step S1, after calculating the pixel grayscale value using the weighted average formula, grayscale value normalization processing is added to map the grayscale value to the standard range of 0-255. At the same time, abnormal grayscale values ​​that exceed this range need to be removed to avoid abnormal values ​​interfering with subsequent filtering and edge extraction steps.

3. The digital image processing method according to claim 1, characterized in that, In step S2, the mean filtering window adopts a pixel-by-pixel traversal method with a sliding step size of 1. Before calculating the average gray value of pixels within the window, extreme noise pixels within the window are removed through median preprocessing to further improve the noise reduction effect.

4. The digital image processing method according to claim 1, characterized in that, In step S3, during adaptive weight allocation, an edge confidence determination mechanism is introduced. By judging the continuity of edge response values, true weak edges are selected, and the weight coefficient is increased only for true weak edge regions to avoid misassigning high weights to isolated noise points.

5. The digital image processing method according to claim 1, characterized in that, In step S4, the gamma transform coefficients An adaptive adjustment method is adopted. By calculating the mean of the grayscale histogram of the image, if the mean is lower than the preset threshold, a transformation coefficient of 0.5-0.8 is selected, and if the mean is higher than the preset threshold, a transformation coefficient of 1.2-1.5 is selected, so as to achieve accurate adaptation to images with different brightness.

6. The digital image processing method according to claim 1, characterized in that, In step S5, for pixels determined to be edges, their gradient magnitude is further calculated. Only strong edge pixels with gradient magnitude greater than a preset threshold are retained and their original grayscale values ​​are maintained. For weak edge pixels with small gradient magnitude, low-intensity smoothing processing is performed to achieve differentiated protection at the edge level. At the same time, weighted average smoothing is only performed on pixels in homogeneous areas, while pixels in edge areas retain their original grayscale values. This achieves targeted smoothing of image areas, preserves edge sharpness, avoids the image edge blurring problem caused by traditional global filtering, and improves the smoothness consistency of homogeneous areas and the contour clarity of edge areas.

7. The digital image processing method according to claim 1, characterized in that, In step S6, the fixed threshold is... The threshold is determined adaptively using the Otsu algorithm. First, the inter-class variance of the image's gray-level histogram is calculated, and the gray-level value corresponding to the maximum inter-class variance is selected as the threshold. This improves the accuracy of dividing the target area into the background area.

8. A digital image processing apparatus, used based on the digital image processing method according to any one of claims 1-7, characterized in that, Includes the following modules: Scale kernel generation module Configured to construct filtering kernels with at least three different scale parameters, by adjusting the size and distribution parameters of the kernels, targeted capture of different width features such as weak edges, regular edges and thick edges in the image is achieved, providing a basic filtering unit for subsequent layered processing; Layered response acquisition module Each scale filter kernel is convolved with the input image independently to avoid mutual interference between features of different scales during processing. The image edge feature response result map at the corresponding scale is output independently, and the original signal information of each type of edge is preserved. Dynamic weight adjustment module Based on the feature signal intensity of pixels in the edge response map at each scale, the weight ratio of features at different scales in the subsequent fusion process is adaptively adjusted in real time, prioritizing the enhancement of the feature signal ratio of weak edge regions and avoiding the coverage of weak edges by strong edge signals. Neighborhood direction recognition module Calculate the horizontal and vertical gradient information and the corresponding gradient direction angle of each pixel in the image. Through a neighborhood window of a preset size, determine the matching degree of the direction angle of each pixel in the window and distinguish the pixels in the edge region from the pixels in the homogeneous region. Regional fusion processing module Based on the neighborhood orientation recognition results, homogeneous region pixels with matching orientation angles are selected, and a weighted fusion smoothing operation is performed on them to improve regional consistency while maintaining the feature integrity of pixels in the image edge region and avoiding edge blurring during the smoothing process.