Image enhancement method and device and electronic device

Through histogram analysis and frequency domain enhancement technology, the problem of dark images in X-ray detection is solved, significantly enhance the structure and texture details of the image, and realize a clear display of the internal structure and defects of the automobile parts.

CN120198338AActive Publication Date: 2025-06-24SHENZHEN XINRUN FULIAN DIGITAL TECH CO LTD

Patent Information

Application Number
CN202510656996.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-21
Publication Date
2025-06-24
Estimated Expiration
2045-05-21

AI Technical Summary

Technical Problem

In the production process of automotive parts, the images generated by X-ray detection are dark due to the wide window and low window positions, and the prior art is difficult to effectively enhance the structure and texture details of the image.

Method used

By generating a histogram of the image to be enhanced, the noise area is found and denoised, converted into a color image, and detail enhancement is performed in the frequency domain, and finally inversely converting it to an enhanced grayscale image.

Benefits of technology

It significantly enhances the structure and texture details in the image, solves the problem of poor image enhancement effect, and can clearly display the internal structure and defects of automotive parts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120198338A_ABST
    Figure CN120198338A_ABST
Patent Text Reader

Abstract

The invention provides an image enhancement method and device and an electronic device.The method comprises the steps that a histogram of an initial gray-scale image to be enhanced is generated, the horizontal axis of the histogram is a gray-scale value, and the longitudinal axis of the histogram is the number of pixels; searching a noise region in the initial gray scale image according to the histogram; denoising the noise area in the initial gray-scale image to obtain an intermediate gray-scale image; converting the middle gray scale image into a middle color image; enhancing the intermediate color image to obtain a target color image; according to the embodiment of the invention, the technical problem that the enhancement effect of the gray-scale image is poor in the related technology is solved, and the structure and texture details in the image are enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of industrial control, and in particular, to an image enhancement method and device, and an electronic device. Background Art

[0002] During the production process of auto parts, X-ray is used to detect internal structure defects. The total number of pixels of a 16-bit high-dynamic range digital flat panel detector is 1024×1024, and the pixel size is 200μm×200μm. Since there are both thin and thick parts in auto parts, and the thick parts are dominant, the window width is set very wide and the window level is low, resulting in the overall X-ray image being too dark. Using functions such as positive / negative film transformation, brightness / contrast transformation, and magnification transformation cannot present the structure in auto parts and the details of shrinkage porosity, shrinkage cavity, crack, air hole, slag inclusion, etc. in them, resulting in poor detection effect and accuracy of auto parts.

[0003] In view of the above problems existing in the related art, no efficient and accurate solution has been found yet. Summary of the Invention

[0004] The present invention provides an image enhancement method and device, and an electronic device to solve the above technical problems existing in the related art.

[0005] According to an embodiment of the present invention, an image enhancement method is provided, including: generating a histogram of an initial grayscale image to be enhanced, where the horizontal axis of the histogram is the grayscale value and the vertical axis is the number of pixels; finding a noise region in the initial grayscale image according to the histogram; denoising the noise region in the initial grayscale image to obtain an intermediate grayscale image; converting the intermediate grayscale image into an intermediate color image; enhancing the intermediate color image to obtain a target color image; and inversely converting the target color image into a target grayscale image.

[0006] Optionally, finding a noise region in the initial grayscale image according to the histogram includes: dividing the histogram into a peak segment and a valley segment; and positioning the pixel region corresponding to the valley segment as the noise region in the initial grayscale image.

[0007] Optionally, denoising the noise region in the initial grayscale image to obtain an intermediate grayscale image includes: reading the initial grayscale value of each pixel in the noise region; for each pixel, determining the grayscale section to which the initial grayscale value belongs; finding a denoised grayscale value matching the grayscale section and replacing the initial grayscale value with the denoised grayscale value; and after all the initial grayscale values of the pixels in the noise region are replaced, obtaining an intermediate grayscale image.

[0008] Optionally, enhance the intermediate color image to obtain a target color image, including: parsing the luminance value of the first channel in the intermediate color image; denoising the intermediate color image based on the luminance value to obtain a first color image; converting the first color image from the spatial domain to the frequency domain, and extracting the frequency domain matrix of the first color image; enhancing the details of the first color image based on the frequency domain matrix to obtain a target color image.

[0009] Optionally, denoise the intermediate color image based on the luminance value to obtain a first color image, including: obtaining an initial weight matrix; traversing the pixels of the intermediate color image, and extracting the neighborhood matrix of each pixel pixel by pixel; for each pixel, iteratively execute the following steps until the error is less than the threshold or the number of iterations reaches the preset number: performing a dot product of the weight of the current cycle and the neighborhood matrix to obtain a target pixel value; calculating the difference between the target pixel value and the original pixel value of the pixel; determining whether the difference is less than the threshold; if the difference is greater than or equal to the threshold, adjusting the weight matrix of the next cycle based on the difference.

[0010] Optionally, enhance the details of the first color image based on the frequency domain matrix to obtain a target color image, including: locating the zero-frequency component in the frequency domain matrix, and transferring the zero-frequency component to the center of the frequency spectrum; for each pixel of the first color image, calculating the distance value from the frequency domain coordinate to the center of the frequency spectrum; calculating the filter mask of the frequency domain matrix based on the distance value, where the filter mask is used to balance the sharpening intensity and the transitional smoothness during image enhancement; multiplying the frequency domain matrix by the filter mask to obtain a frequency domain enhancement matrix; inverse-converting the frequency domain enhancement matrix to the spatial domain to obtain a target color image.

[0011] Optionally, calculating the filter mask of the frequency domain matrix based on the distance value includes: configuring the adjustment order n of the Butterworth high-pass filter; calculating the filter mask of the frequency domain matrix using the following formula : ; where is the distance value from the frequency domain coordinate of the pixel point to the center of the frequency spectrum, is the cut-off frequency.

[0012] Optionally, generating a histogram of the initial grayscale image to be enhanced includes: reading the grayscale value of each pixel in the initial grayscale image; counting the number of pixels corresponding to each grayscale value; generating a histogram of the initial grayscale image with the grayscale value as the abscissa and the number of pixels as the ordinate.

[0013] According to another embodiment of the present invention, there is provided an image enhancement device, including: a generation module for generating a histogram of an initial grayscale image to be enhanced, wherein the horizontal axis of the histogram is the grayscale value and the vertical axis is the number of pixels; a lookup module for looking up a noise region in the initial grayscale image according to the histogram; a denoising module for denoising the noise region in the initial grayscale image to obtain an intermediate grayscale image; a conversion module for converting the intermediate grayscale image into an intermediate color image; an enhancement module for enhancing the intermediate color image to obtain a target color image; an inverse conversion module for inversely converting the target color image into a target grayscale image.

[0014] Optionally, the lookup module includes: a division unit for dividing the histogram into a peak segment and a valley segment; a positioning unit for positioning the pixel region corresponding to the valley segment as the noise region in the initial grayscale image.

[0015] Optionally, the denoising module includes: a reading unit for reading the initial grayscale value of each pixel in the noise region; a determination unit for determining, for each pixel, the grayscale section to which the initial grayscale value belongs; a replacement unit for looking up a denoised grayscale value matching the grayscale section and replacing the initial grayscale value with the denoised grayscale value; a processing unit for obtaining an intermediate grayscale image after all the initial grayscale values of the pixels in the noise region have been replaced.

[0016] Optionally, the enhancement module includes: an analysis unit for analyzing the brightness value of the first channel in the intermediate color image; a denoising unit for denoising the intermediate color image based on the brightness value to obtain a first color image; a conversion unit for converting the first color image from the spatial domain to the frequency domain and extracting the frequency domain matrix of the first color image; an enhancement unit for enhancing the details of the first color image based on the frequency domain matrix to obtain a target color image.

[0017] Optionally, the denoising unit includes: an acquisition subunit for acquiring an initial weight matrix; a traversal subunit for traversing the pixels of the intermediate color image and extracting the neighborhood matrix of each pixel pixel by pixel; an iteration subunit for, for each pixel, iteratively performing the following steps until the error is less than a threshold or the number of iterations reaches a preset number: taking the dot product of the weight of the current cycle and the neighborhood matrix to obtain a target pixel value; calculating the difference between the target pixel value and the original pixel value of the pixel; determining whether the difference is less than the threshold; if the difference is greater than or equal to the threshold, adjusting the weight matrix of the next cycle based on the difference.

[0018] Optionally, the enhancement unit includes: a processing subunit, configured to locate the zero-frequency component in the frequency-domain matrix and transfer the zero-frequency component to the spectrum center; a first calculation subunit, configured to calculate, for each pixel of the first color image, a distance value from the frequency-domain coordinate to the spectrum center; a second calculation subunit, configured to calculate a filter mask of the frequency-domain matrix based on the distance value, where the filter mask is used to balance the sharpening intensity and the transition smoothness during image enhancement; an operation subunit, configured to multiply the frequency-domain matrix by the filter mask to obtain a frequency-domain enhanced matrix; and an inverse conversion subunit, configured to inversely convert the frequency-domain enhanced matrix into the spatial domain to obtain a target color image.

[0019] Optionally, the second calculation subunit is further configured to: configure an adjustment order n of a Butterworth high-pass filter; and calculate the filter mask of the frequency-domain matrix by using the following formula : ; where is the distance value from the frequency-domain coordinate of the pixel point to the spectrum center, and is the cut-off frequency.

[0020] Optionally, the generation module includes: a reading unit, configured to read the gray-scale value of each pixel in the initial grayscale image; a statistics unit, configured to count the number of pixels corresponding to each gray-scale value; and a generation unit, configured to generate a histogram of the initial grayscale image with the gray-scale value as the abscissa and the number of pixels as the ordinate.

[0021] According to another embodiment of the present invention, there is also provided a storage medium storing a computer program, where the computer program is configured to execute the steps in any one of the above device embodiments when running.

[0022] According to another embodiment of the present invention, there is also provided an electronic device including a memory and a processor, where the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above device embodiments.

[0023] Through the embodiments of the present invention, a histogram of an initial grayscale image to be enhanced is generated, where the horizontal axis of the histogram is the grayscale value and the vertical axis is the number of pixels; the noise regions in the initial grayscale image are found according to the histogram; the noise regions in the initial grayscale image are denoised to obtain an intermediate grayscale image; the intermediate grayscale image is converted into an intermediate color image; the intermediate color image is enhanced to obtain a target color image; the target color image is inversely converted into a target grayscale image. Through grayscale denoising, irrelevant details can be removed, and by enhancing the image in the frequency domain, while enhancing the large-scale structure of the image, fine features such as edges and textures can be enhanced, solving the technical problem of poor enhancement effect of grayscale images in the related art and enhancing the structure and texture details in the image. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation to the present invention. In the drawings: Figure 1 is a block diagram of the hardware structure of a computer according to an embodiment of the present invention; Figure 2 is a flowchart of a method for enhancing an image according to an embodiment of the present invention; Figure 3 is a schematic diagram of a histogram in an embodiment of the present invention; Figure 4 is an overall flowchart of image enhancement in an embodiment of the present invention; Figure 5 is a schematic diagram of the effects before and after image enhancement in an embodiment of the present invention; Figure 6 is a block diagram of the structure of an image enhancement device according to an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0025] In order to enable those skilled in the art to better understand the solutions of this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the drawings in the embodiments of this application. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this application. It should be noted that, without conflict, the embodiments in this application and the features in the embodiments can be combined with each other.

[0026] It should be noted that the terms "first", "second", etc. in the description, claims and the above-mentioned drawings of this application are used to distinguish similar objects, and do not necessarily describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances, so that the embodiments of this application described here can be implemented in an order other than those illustrated or described here. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0027] Embodiment 1 The method embodiment provided by the first embodiment of this application can be executed in an operation device such as a server, a computer, or a camera. Taking running on a computer as an example, Figure 1 is a hardware structure block diagram of a computer according to an embodiment of the present invention. As Figure 1 shown, the computer may include one or more ( Figure 1 only one is shown in the figure) processors 102 (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. Optionally, the above computer may further include a transmission device 106 for communication functions and an input / output device 108. Those of ordinary skill in the art can understand that Figure 1 the structure shown is only schematic and does not limit the structure of the above computer. For example, the computer may further include more or fewer components than Figure 1 shown in the figure, or have a different configuration from Figure 1 shown in the figure.

[0028] The memory 104 can be used to store computer programs. For example, software programs and modules of application software, such as the computer program corresponding to an image enhancement method in an embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implements the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some instances, the memory 104 may further include a memory remotely disposed relative to the processor 102, and these remote memories can be connected to the computer through a network. Examples of the above network include, but are not limited to, the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.

[0029] The transmission device 106 is used to receive or send data via a network. Specific examples of the above network may include a wireless network provided by a communication provider of a computer. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, abbreviated as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a Radio Frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0030] In this embodiment, an image enhancement method is provided. Figure 2 It is a flowchart of an image enhancement method according to an embodiment of the present invention, as Figure 2 shown, and the process includes the following steps: Step S202, generating a histogram of the initial grayscale image to be enhanced, where the horizontal axis of the histogram is the grayscale value and the vertical axis is the number of pixels; Optionally, the initial grayscale image can be an 8-bit grayscale or a 16-bit grayscale. For example, the grayscale image generated by an X-ray detection device is a 16-bit grayscale image, and the grayscale value range of the 16-bit grayscale is 0 - 65535.

[0031] Optionally, the shooting object of the initial grayscale image can be a workpiece such as an automotive part, such as a wheel hub.

[0032] Step S204, finding the noise area in the initial grayscale image according to the histogram; Step S206, denoising the noise area in the initial grayscale image to obtain an intermediate grayscale image; Step S208, converting the intermediate grayscale image into an intermediate color image; Step S210, enhancing the intermediate color image to obtain a target color image; Step S212, inversely converting the target color image into a target grayscale image.

[0033] Through the above steps, a histogram of the initial grayscale image to be enhanced is generated, where the horizontal axis of the histogram is the grayscale value and the vertical axis is the number of pixels; the noise region in the initial grayscale image is found according to the histogram; the noise region in the initial grayscale image is denoised to obtain an intermediate grayscale image; the intermediate grayscale image is converted into an intermediate color image; the intermediate color image is enhanced to obtain a target color image; the target color image is inversely converted into a target grayscale image. Through grayscale denoising, irrelevant details can be removed. By enhancing the image in the frequency domain, while enhancing the large-scale structure of the image, fine features such as edges and textures can be enhanced, solving the technical problem of poor enhancement effect of grayscale images in the related art and enhancing the structure and texture details in the image.

[0034] In this embodiment, generating a histogram of the initial grayscale image to be enhanced includes: reading the grayscale value of each pixel in the initial grayscale image; counting the number of pixels corresponding to each grayscale value; and generating a histogram of the initial grayscale image with the grayscale value as the abscissa and the number of pixels as the ordinate.

[0035] Taking the initial grayscale image with 16-bit grayscale as an example, the possible grayscale values of each pixel in the initial grayscale image are 0 - 65535. For example, the number of pixels with a grayscale value of 9000 is 350, and the coordinate point in the histogram is (9000, 350).

[0036] In an implementation manner of this embodiment, finding the noise region in the initial grayscale image according to the histogram includes: dividing the histogram into a peak segment and a valley segment; positioning the pixel region corresponding to the valley segment as the noise region in the initial grayscale image.

[0037] When dividing into a peak segment and a valley segment, the grayscale with at least 30 consecutive pixels is used as the demarcation point. If there are at least 30 consecutive pixels with the same grayscale, it is the peak segment; otherwise, it is the valley segment.

[0038] Figure 3 This is a schematic diagram of the histogram in the embodiment of the present invention. Determine the number of peaks. The number of peaks of the workpiece shown in the histogram is 3. According to the number of pixels, find the demarcation point between the peak segment and the non-peak segment in the histogram, and the non-peak segment (valley segment) can be separated.

[0039] In one example, denoising the noise region in the initial grayscale image to obtain an intermediate grayscale image includes: reading the initial grayscale value of each pixel in the noise region; for each pixel, determining the grayscale section to which the initial grayscale value belongs; looking up the denoised grayscale value that matches the grayscale section, and replacing the initial grayscale value with the denoised grayscale value; after the initial grayscale values of all pixels in the noise region have been replaced, an intermediate grayscale image is obtained.

[0040] In one implementation scenario, 0.17% (example, can be flexibly selected) of the grayscale pixels are used to replace the grayscale values in the trough section, and 8 (example, can be flexibly selected) denoised grayscale values are used to replace the initial grayscale values of the pixels for all grayscales below 4671 (example, can be flexibly selected). The range from 0 to 4671 is pre-divided into 8 grayscale sections, and each grayscale section corresponds to a denoised grayscale value. The histogram of the intermediate grayscale image after replacement is as Figure 3 shown.

[0041] In this embodiment, in the process of converting the intermediate grayscale image into an intermediate color image, through grayscale conversion, the intermediate grayscale image is converted into an intermediate color image in the Lab color space. The conversion process includes: The following formula is used for grayscale conversion: = ; where g is the single-channel matrix of pixels of the intermediate grayscale image after grayscale replacement.

[0042] A = ; B = 500(f(x) - f(y)) + 32768 C = 200(f(y) - f(z)) + 32768 where f(t) = ; [A, B, C] are the three channels of the intermediate color image obtained by grayscale conversion.

[0043] In the intermediate color image after conversion to the Lab color space, the first channel represents brightness, and the second and third channels represent color. By enhancing the first channel, the detailed texture of the image can be enhanced.

[0044] In this embodiment, enhancing the intermediate color image to obtain a target color image includes: parsing the luminance value of the first channel in the intermediate color image; denoising the intermediate color image based on the luminance value to obtain a first color image; converting the first color image from the spatial domain to the frequency domain, and extracting the frequency domain matrix of the first color image; enhancing the details of the first color image based on the frequency domain matrix to obtain a target color image.

[0045] In one example, denoising the intermediate color image based on the luminance value to obtain a first color image includes: obtaining an initial weight matrix; traversing the pixels of the intermediate color image, and extracting the neighborhood matrix of each pixel pixel by pixel; for each pixel, iteratively execute the following steps until the error is less than the threshold or the number of iterations reaches the preset number of times: performing a dot product of the weight of the current cycle and the neighborhood matrix to obtain a target pixel value; calculating the difference between the target pixel value and the original pixel value of the pixel; determining whether the difference is less than the threshold; if the difference is greater than or equal to the threshold, adjusting the weight matrix of the next cycle based on the difference.

[0046] In this example, the initialization parameters include randomly initializing to obtain an initial weight matrix, including setting a step factor and a neighborhood size. Traverse the image pixels: extract the neighborhood matrix as the input signal pixel by pixel. Calculate the output and the error: the output is the dot product of the weight and the neighborhood pixels, and the error is the difference between the original pixel value of the pixel and the output target pixel value. Dynamically adjust the weight matrix according to the error. Repeat until the error is stable or the preset number of iterations is reached, generally set to 5 times, to achieve iterative convergence.

[0047] Adopt the denoising and removal of irrelevant details in this example, and open the weight adjustment parameter. A larger value makes the image smoother, eliminating more noise and irrelevant details, and a smaller parameter value retains more details and eliminates less noise.

[0048] Subsequently, when enhancing the intermediate color image to obtain a target color image, horizontally connect the updated luminance value after enhancing the first channel with the original second and third channel values in the intermediate color image to obtain a target color image.

[0049] In this embodiment, the spatial domain refers to the representation form of an image in a two-dimensional space. In the spatial domain, an image is composed of pixel points, and each pixel point has its specific position and grayscale value (or color value). The image processing methods in the spatial domain mainly focus on the local features of the image, such as edges, textures, shapes, etc. The frequency domain refers to the representation form of an image in the frequency space. In this embodiment, through Fourier transform, the image in the spatial domain is converted to the frequency domain. In the frequency domain, the image is represented by a combination of sine waves and cosine waves of different frequencies. The image processing methods in the frequency domain mainly focus on the global features of the image, such as image smoothing, enhancement, filtering, etc. In the frequency domain, u and v are frequency variables used to represent the coordinates of the image in the frequency space, corresponding to the frequencies in the horizontal and vertical directions respectively.

[0050] When converting the first color image from the spatial domain to the frequency domain, the fast Fourier transform (FFT) is used to convert the image from the spatial domain to the frequency domain, generating a frequency domain matrix in complex form : = .

[0051] In one example, based on the frequency domain matrix, detail enhancement is performed on the first color image to obtain a target color image, including: locating the zero-frequency component in the frequency domain matrix and transferring the zero-frequency component to the center of the frequency spectrum; for each pixel of the first color image, calculating the distance value from the frequency domain coordinate to the center of the frequency spectrum; calculating the filter mask of the frequency domain matrix based on the distance value, where the filter mask is used to balance the sharpening intensity and transitional smoothness during image enhancement; multiplying the frequency domain matrix by the filter mask to obtain a frequency domain enhancement matrix; and inverse-converting the frequency domain enhancement matrix to the spatial domain to obtain the target color image.

[0052] Moving the zero-frequency component to the center of the frequency spectrum facilitates visualization and subsequent data processing, and calculating the frequency domain enhancement matrix : = * ; is the filter mask. By multiplying the filter mask with the frequency domain matrix, the high-frequency components are enhanced, and the coefficients in the high-frequency region are non-linearly amplified to further strengthen the details.

[0053] Optionally, in the process of inverse-converting the processed frequency domain enhancement matrix back to the spatial domain to obtain the target color image, the modulus value of the inverse transform result is taken and normalized to the grayscale range of [0, 65535], and the Laplacian operator is superimposed on the result image, which can further enhance the local details.

[0054] The filter mask (also known as mask or window) of this embodiment is a two-dimensional array used to define local neighborhood operations in image processing operations. It contains a set of coefficients that are convolved or correlated with the pixel values of the image during the filtering process, thereby achieving operations such as image smoothing, sharpening, and edge detection.

[0055] In this embodiment, a Butterworth high-pass filter is selected. The Butterworth high-pass filter includes a smoothing filter and a sharpening filter. The smoothing filter expects the sum of the filter coefficients to be 1 to maintain the overall brightness of the image. The sharpening filter expects the central coefficient of the filter to be greater than the surrounding coefficients to enhance the edges. The smoothing filter can further select a mean filter and a Gaussian filter. The sharpening filter can further select a Laplace filter and a high-pass filter.

[0056] Optionally, calculating the filter mask of the frequency domain matrix based on the distance value includes: configuring the adjustment order n of the Butterworth high-pass filter; calculating the filter mask of the frequency domain matrix using the following formula : ; where is the distance value from the frequency domain coordinates of the pixel point to the spectrum center, is the cut-off frequency.

[0057] By applying the Butterworth high-pass filter and configuring the adjustable order n, the sharpening intensity and transition smoothness can be balanced.

[0058] The solution of this embodiment proposes a method capable of enhancing the structure and texture details of 16-bit X-ray images. Taking the enhancement of X-ray images of automotive parts as an example, if a histogram of an X-ray image of automotive parts is drawn, it will be found that there are only 1-3 peaks in the histogram, and there are few pixels in the non-peak areas. In this embodiment, a large number of image gray-scale pixels in the non-peak areas are removed and replaced with a small number of gray-scale pixels; after converting the gray-scale image into a color image through a gray-scale conversion function, the three channels of the color image are separated, and the first channel is taken out and converted into a 32-bit floating-point type to eliminate noise and irrelevant details. After enhancing the image in the frequency domain, it is converted into a 16-bit integer type, and then merged with the remaining second and third channels, and then converted back into a gray-scale image through the inverse function of the gray-scale conversion function, which is the enhanced image. This gray-scale image can clearly display the fine features such as the structure, edges, and textures of automotive parts in the image.

[0059] Figure 4 is the overall flowchart of image enhancement in the embodiment of the present invention, including the following steps: Step 1: Count the number of pixels of each gray scale, and draw a histogram of the input image with the gray scale 0-65535 as the x-axis and the number of pixels as the y-axis; Step 2: Determine the number of peaks according to the workpiece and steps of the photographed automotive parts. The number of peaks of the workpiece shown in the above histogram is 3; Step 3: According to the number of pixels, find the demarcation point between the peak segment and the non-peak segment in the histogram, and separate the non-peak segment; Step 4: Use 0.17% of the grayscale pixels to replace the grayscale of the non-peak segment, and use 8 grayscales to replace all grayscales below 4671: Step 5: Grayscale conversion: =

[0060] where g is the single-channel matrix of the pixels of the image after grayscale replacement in Step 4.

[0061] A = ; B = 500(f(x) - f(y)) + 32768 C = 200(f(y) - f(z)) + 32768 where f(t) =

[0062] [A, B, C] are the three channels of the resulting image after grayscale conversion.

[0063] Step 6: Convert the matrix A in Step 5 to 32-bit floating point type so that the precision is not easily lost in the subsequent processing steps; Step 7: Denoise and remove irrelevant details, and open the weight adjustment parameter. A larger value makes the image smoother, eliminating more noise and irrelevant details, while a smaller parameter value retains more details and eliminates less noise; 7.1 Initialize parameters: Set the step factor, neighborhood size, and randomly initialize the weight matrix.

[0064] 7.2 Traverse the image pixels: Extract the neighborhood matrix pixel by pixel as the input signal.

[0065] 7.3 Calculate the output and error: The output is the dot product of the weights and the neighborhood pixels, and the error is the difference between the original value and the output.

[0066] 7.4 Dynamically update the weights: Adjust the weight matrix according to the error.

[0067] 7.5 Iterative convergence: Repeat until the error is stable or the preset number of iterations is reached, usually set to 5 times.

[0068] Step 8: Enhance the image in the frequency domain and open the weight adjustment parameter. A smaller value enhances the low-frequency details, i.e., the large-scale structure of the image; a larger value enhances the high-frequency details, such as fine features like edges and textures. 8.1 Use the Fast Fourier Transform (FFT) to transform the image from the spatial domain to the frequency domain, generating a complex-valued frequency-domain matrix: =

[0069] 8.2 Move the zero-frequency component to the center of the spectrum for easier visualization and processing.

[0070] 8.3 Apply a Butterworth high-pass filter, where the order n can be adjusted to balance the sharpening intensity and transition smoothness:

[0071] where is the distance from the point to the center of the spectrum, and is the cut-off frequency.

[0072] 8.4 Multiply the filter mask with the frequency-domain matrix to enhance the high-frequency components, non-linearly amplify the coefficients in the high-frequency region, and further strengthen the details: = *

[0073] 8.5 Convert the processed frequency-domain matrix back to the spatial domain, take the modulus of the inverse transform result, and normalize it to the gray scale range of [0, 65535]. Apply the Laplacian operator to the resulting image to further enhance the local details.

[0074] Step 9: Convert the data result in Step 8 back to 16-bit integer type. After horizontally concatenating it with matrices B and C obtained in Step 5, apply the inverse process of gray-scale conversion to obtain the enhanced image.

[0075] Figure 5 is a schematic diagram of the effects before and after image enhancement in the embodiment of the present invention. By adopting the solution of this embodiment, the structure and texture details in the 16-bit x-ray input image are significantly enhanced.

[0076] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases, the former is a better implementation. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc) and includes several instructions to enable a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in various embodiments of the present invention.

[0077] Embodiment 2 In this embodiment, an image enhancement device is further provided. This device is used to implement the above embodiments and preferred implementation manners, and those that have been described will not be repeated. As used hereinafter, the term "module" can be a combination of software and hardware that can implement a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementations in hardware, or a combination of software and hardware, can also be conceived.

[0078] Figure 6 is a structural block diagram of an image enhancement device according to an embodiment of the present invention. As Figure 6 shown, the device includes: A generation module 60, configured to generate a histogram of an initial grayscale image to be enhanced, where the horizontal axis of the histogram is the grayscale value and the vertical axis is the number of pixels; A search module 61, configured to search for a noise area in the initial grayscale image according to the histogram; A denoising module 62, configured to denoise the noise area in the initial grayscale image to obtain an intermediate grayscale image; A conversion module 63, configured to convert the intermediate grayscale image into an intermediate color image; An enhancement module 64, configured to enhance the intermediate color image to obtain a target color image; An inverse conversion module 65, configured to inversely convert the target color image into a target grayscale image.

[0079] Optionally, the search module includes: a division unit, configured to divide the histogram into a peak segment and a valley segment; a positioning unit, configured to position the pixel area corresponding to the valley segment as the noise area in the initial grayscale image.

[0080] Optionally, the denoising module includes: a reading unit configured to read the initial gray-scale value of each pixel in the noise region; a determining unit configured to determine, for each pixel, the gray-scale section to which the initial gray-scale value belongs; a replacing unit configured to find a denoising gray-scale value matching the gray-scale section and replace the initial gray-scale value with the denoising gray-scale value; and a processing unit configured to obtain an intermediate gray-scale image after the initial gray-scale values of all pixels in the noise region have been replaced.

[0081] Optionally, the enhancement module includes: a parsing unit configured to parse the luminance value of the first channel in the intermediate color image; a denoising unit configured to denoise the intermediate color image based on the luminance value to obtain a first color image; a conversion unit configured to convert the first color image from the spatial domain to the frequency domain and extract the frequency-domain matrix of the first color image; and an enhancement unit configured to enhance the details of the first color image based on the frequency-domain matrix to obtain a target color image.

[0082] Optionally, the denoising unit includes: an obtaining subunit configured to obtain an initial weight matrix; a traversing subunit configured to traverse the pixels of the intermediate color image and extract the neighborhood matrix of each pixel pixel by pixel; and an iterative subunit configured to, for each pixel, iteratively perform the following steps until the error is less than a threshold or the number of iterations reaches a preset number: perform a dot product of the weight of the current cycle and the neighborhood matrix to obtain a target pixel value; calculate the difference between the target pixel value and the original pixel value of the pixel; determine whether the difference is less than the threshold; and if the difference is greater than or equal to the threshold, adjust the weight matrix of the next cycle based on the difference.

[0083] Optionally, the enhancement unit includes: a processing subunit configured to locate the zero-frequency component in the frequency-domain matrix and transfer the zero-frequency component to the center of the frequency spectrum; a first calculating subunit configured to calculate, for each pixel of the first color image, the distance value from the frequency-domain coordinate to the center of the frequency spectrum; a second calculating subunit configured to calculate the filter mask of the frequency-domain matrix based on the distance value, where the filter mask is used to balance the sharpening intensity and the transition smoothness during image enhancement; an operating subunit configured to multiply the frequency-domain matrix by the filter mask to obtain a frequency-domain enhancement matrix; and an inverse conversion subunit configured to inversely convert the frequency-domain enhancement matrix to the spatial domain to obtain a target color image.

[0084] Optionally, the second calculating subunit is further configured to: configure the adjustment order n of the Butterworth high-pass filter; and calculate the filter mask of the frequency-domain matrix using the following formula : ; where is the distance value from the frequency-domain coordinate of the pixel point to the center of the frequency spectrum, is the cut-off frequency.

[0085] Optionally, the generating module includes: a reading unit configured to read the grayscale value of each pixel in the initial grayscale image; a statistical unit configured to count the number of pixels corresponding to each grayscale value; and a generating unit configured to generate a histogram of the initial grayscale image with the grayscale value as the abscissa and the number of pixels as the ordinate.

[0086] It should be noted that the above-mentioned modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited thereto: all the above-mentioned modules are located in the same processor; or, the above-mentioned modules are separately located in different processors in any combination form.

[0087] Embodiment 3 An embodiment of the present invention further provides a storage medium, in which a computer program is stored, and the computer program is configured to execute the steps in any one of the above method embodiments when running.

[0088] Optionally, in this embodiment, the above storage medium can be configured to store a computer program for execution: S1, generating a histogram of the initial grayscale image to be enhanced, where the abscissa of the histogram is the grayscale value and the ordinate is the number of pixels; S2, finding the noise region in the initial grayscale image according to the histogram; S3, denoising the noise region in the initial grayscale image to obtain an intermediate grayscale image; S4, converting the intermediate grayscale image into an intermediate color image; S5, enhancing the intermediate color image to obtain a target color image; S6, inversely converting the target color image into a target grayscale image.

[0089] Optionally, in this embodiment, the above storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM for short), a random access memory (RAM for short), a mobile hard disk, a magnetic disk, or an optical disc, etc., various media that can store computer programs.

[0090] An embodiment of the present invention further provides an electronic device, including a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0091] Optionally, the above-mentioned electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the above-mentioned processor, and the input / output device is connected to the above-mentioned processor.

[0092] Optionally, in this embodiment, the above-mentioned processor may be configured to perform the following steps by a computer program: S1, generate a histogram of the initial grayscale image to be enhanced, wherein the horizontal axis of the histogram is the grayscale value and the vertical axis is the number of pixels; S2, find the noise region in the initial grayscale image according to the histogram; S3, denoise the noise region in the initial grayscale image to obtain an intermediate grayscale image; S4, convert the intermediate grayscale image into an intermediate color image; S5, enhance the intermediate color image to obtain a target color image; S6, inversely convert the target color image into a target grayscale image.

[0093] Optionally, specific examples in this embodiment may refer to the examples described in the above-mentioned embodiment and optional implementation manners, and will not be elaborated herein.

[0094] The serial numbers of the above-mentioned embodiments of the present application are only for description and do not represent the advantages or disadvantages of the embodiments.

[0095] In the above-mentioned embodiments of the present application, the descriptions of the respective embodiments have their own emphases. For parts not elaborated in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.

[0096] In several embodiments provided by the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some interfaces. The indirect coupling or communication connection of units or modules can be in an electrical or other form.

[0097] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0098] In addition, in each embodiment of the present application, the functional units may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or in the form of a software functional unit.

[0099] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, may be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods in the various embodiments of the present application. The foregoing storage medium includes: various media such as USB flash drives, read-only memory (ROM), random access memory (RAM), mobile hard disks, magnetic disks, or optical discs that can store program codes.

[0100] The above are only the preferred embodiments of the present application. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present application, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present application.

Claims

1. A method for enhancing an image, characterized in that: include: Generate a histogram of the initial grayscale image to be enhanced, wherein the horizontal axis of the histogram is the grayscale value and the vertical axis is the number of pixels; Finding a noise area in the initial grayscale image according to the histogram; De-noising the noise area in the initial grayscale image to obtain an intermediate grayscale image; Converting the intermediate grayscale image into an intermediate color image; enhancing the intermediate color image to obtain a target color image; The target color image is inversely converted into a target grayscale image.

2. The method according to claim 1, characterized in that Finding the noise area in the initial grayscale image according to the histogram includes: Dividing the histogram into peak segments and trough segments; The pixel area corresponding to the trough segment is located as the noise area in the initial grayscale image.

3. The method according to claim 2, characterized in that Denoising the noise region in the initial grayscale image to obtain an intermediate grayscale image, comprising: Reading an initial grayscale value of each pixel in the noise area; For each pixel, determining the grayscale segment to which the initial grayscale value belongs; Finding a denoised grayscale value matching the grayscale segment, and replacing the initial grayscale value with the denoised grayscale value; After the initial grayscale values ​​of all pixels in the noise area are replaced, an intermediate grayscale image is obtained.

4. The method according to claim 1, characterized in that: The intermediate color image is enhanced to obtain a target color image, comprising: Analyzing the brightness value of the first channel in the intermediate color image; De-noising the intermediate color image based on the brightness value to obtain a first color image; converting the first color image from a spatial domain to a frequency domain, and extracting a frequency domain matrix of the first color image; The first color image is enhanced in detail based on the frequency domain matrix to obtain a target color image.

5. The method according to claim 4, characterized in that Denoising the intermediate color image based on the brightness value to obtain a first color image, comprising: Get the initial weight matrix; Traversing the pixels of the intermediate color image, and extracting a neighborhood matrix of each pixel one by one; For each pixel, the following steps are iterated until the error is less than a threshold or the number of iterations reaches a preset number: dot product the weight of the current cycle with the neighborhood matrix to obtain a target pixel value; calculate the difference between the target pixel value and the original pixel value of the pixel; determine whether the difference is less than a threshold; if the difference is greater than or equal to the threshold, adjust the weight matrix of the next cycle based on the difference.

6. The method according to claim 4, characterized in that Performing detail enhancement on the first color image based on the frequency domain matrix to obtain a target color image includes: Locating a zero-frequency component in the frequency domain matrix and transferring the zero-frequency component to the center of the spectrum; For each pixel of the first color image, calculating the distance value from the frequency domain coordinate to the center of the spectrum; Calculating a filter mask of the frequency domain matrix based on the distance value, wherein the filter mask is used to balance sharpening intensity and transition smoothness during image enhancement; Multiplying the frequency domain matrix by the filter mask to obtain a frequency domain enhancement matrix; The frequency domain enhancement matrix is ​​inversely transformed into the spatial domain to obtain a target color image.

7. The method according to claim 6, characterized in that Calculating a filter mask of the frequency domain matrix based on the distance value includes: Configure the adjustment order n of the Butterworth high-pass filter; The filter mask of the frequency domain matrix is ​​calculated using the following formula: : ; in, is the distance value from the frequency domain coordinate of the pixel point to the center of the spectrum, is the cut-off frequency.

8. The method according to claim 1, characterized in that Generate a histogram of the initial grayscale image to be enhanced, including: Reading the grayscale value of each pixel in the initial grayscale image; Count the number of pixels corresponding to each grayscale value; A histogram of the initial grayscale image is generated with the grayscale value as the horizontal coordinate and the number of pixels as the vertical coordinate.

9. An image enhancement device, characterized in that: include: A generating module, used for generating a histogram of the initial grayscale image to be enhanced, wherein the horizontal axis of the histogram is the grayscale value and the vertical axis is the number of pixels; A search module, used for searching the noise area in the initial grayscale image according to the histogram; A denoising module, used for denoising the noise area in the initial grayscale image to obtain an intermediate grayscale image; A conversion module, used for converting the intermediate grayscale image into an intermediate color image; An enhancement module, used for enhancing the intermediate color image to obtain a target color image; The inverse conversion module is used to inversely convert the target color image into a target grayscale image.

10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Imaging apparatus, high frequency component detection circuit, high frequency component detection method and computer program product

    CN101047781A

  • Image enhancement algorithm based on wavelet transform and fusing high-frequency and low-frequency information

    CN111583123A

  • Intelligent denoising method for leather fiber MCT tomography image and application

    CN113313647A

  • Image denoising method and apparatus, electronic device, and computer readable storage medium

    WO2024217278A1

Cited By

  • Ocean detection image processing method and device

    CN121391684A