Image processing method, image processing device, electronic device, and storage medium
By performing nonlinear sharpening spatial filtering on the dark channel of grayscale images, the problem of unclear features of interest caused by changes in illumination is solved, brightness adjustment and contrast enhancement are achieved, and the stability and recognition rate of defect detection are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-25
- Publication Date
- 2026-04-07
AI Technical Summary
In the detection of surface defects in industrial products, changes in illumination within the image can make the features of interest less obvious, thus reducing the defect recognition rate.
A nonlinear sharpening spatial filter is used to filter the dark channel image of the grayscale image. The minimum grayscale value of the segmented region is determined and the kernel function of the nonlinear sharpening spatial filter is used to enhance the image.
While eliminating the effects of changes in lighting, it achieves brightness adjustment and contrast enhancement, thereby improving the stability and robustness of target recognition.
Smart Images

Figure CN116485754B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to an image processing method, an image processing apparatus, an electronic device, and a storage medium. Background Technology
[0002] In the industrial sector, surface defects in industrial products such as steel plates, films, and glass can negatively impact product safety and usability. Therefore, manufacturers need to inspect product surfaces to detect and control defects promptly. Machine vision inspection technology uses images of the product surface to detect surface defects. However, when using images for surface defect detection, variations in lighting within the image can make features of interest less prominent, thus reducing the defect recognition rate. Summary of the Invention
[0003] This invention provides an image processing method, an image processing device, an electronic device, and a storage medium. When using images for surface defect detection, changes in illumination within the image can make the features of interest less obvious, thereby reducing the defect recognition rate.
[0004] To solve the above-mentioned technical problems, the present invention is implemented as follows:
[0005] In a first aspect, embodiments of the present invention provide an image processing method, comprising:
[0006] Obtain the grayscale image to be processed;
[0007] Obtain the dark channel image of the grayscale image to be processed;
[0008] The dark channel image is filtered using a nonlinear sharpening spatial filter to obtain the processed image.
[0009] Optionally, obtaining the dark channel image of the grayscale image to be processed includes:
[0010] Define a scanning window with a size of m×n, where m and n are both integers greater than or equal to 1;
[0011] The grayscale image to be processed is scanned by sliding the scanning window to obtain a block region of size m×n;
[0012] For each of the aforementioned block regions, determine the minimum average grayscale value of the three RGB channels;
[0013] The region dark channel image of the segmented region is determined based on the minimum value;
[0014] The dark channel image of the grayscale image to be processed is obtained based on the dark channel images of all the block regions.
[0015] Optional, m and n are equal, both being 3.
[0016] Optionally, for each of the said segmented regions, the minimum average grayscale value of the three RGB channels is determined, including:
[0017] For each of the block regions, the sum of the gray values of the three RGB channels is calculated, and the average gray value of the three RGB channels is obtained by dividing the sum of the gray values by the number of pixels in the block region.
[0018] Select the minimum value from the average grayscale values of the three RGB channels.
[0019] Optionally, determining the region dark channel image of the segmented region based on the minimum value includes:
[0020] The minimum grayscale value is assigned to all pixels within the segmented region to obtain the dark channel image of the segmented region.
[0021] Optionally, a nonlinear sharpening spatial filter is used to filter the dark channel image to obtain a processed image, including:
[0022] The processed image is obtained using the following formula:
[0023]
[0024]
[0025] Where, F(I) p The processed image, This refers to the nonlinear sharpening spatial filter. Let I be the kernel function of the nonlinear sharpening spatial filter. q For the dark channel image, μ k For the dark channel image in the kernel window ω k The mean, For the dark channel image in the kernel window ω k The variance, |ω| is the variance of the kernel window ω. k The size of the convolution kernel is v = 0.000001, where k is the kernel size and G is the kernel size. p Let q be the grayscale value of pixel p in the grayscale image to be processed, and let q be the pixel point corresponding to pixel p in the grayscale image to be processed in the dark channel image. q Let q be the grayscale value of pixel q in the dark channel image.
[0026] Secondly, embodiments of the present invention provide an image processing apparatus, comprising:
[0027] The first acquisition module is used to acquire the grayscale image to be processed;
[0028] The second acquisition module is used to acquire the dark channel image of the grayscale image to be processed;
[0029] The filtering module is used to filter the dark channel image using a nonlinear sharpening spatial filter to obtain the processed image.
[0030] Optionally, the second acquisition module is used to define a scanning window, the size of which is m×n, where m and n are both integers greater than or equal to 1; to slide and scan the grayscale image to be processed using the scanning window to obtain block regions of size m×n; to determine the minimum value of the average grayscale value of the three RGB channels for each block region; to determine the region dark channel image of the block region based on the minimum value; and to obtain the dark channel image of the grayscale image to be processed based on the region dark channel images of all the block regions.
[0031] Optionally, the filtering module is used to obtain the processed image using the following formula:
[0032]
[0033]
[0034] Where, F(I) p The processed image, This refers to the nonlinear sharpening spatial filter. Let I be the kernel function of the nonlinear sharpening spatial filter. q For the dark channel image, μ k For the dark channel image in the kernel window ω k The mean, For the dark channel image in the kernel window ω k The variance, |ω| is the variance of the kernel window ω. k The size of G, ε=0.000001. p Let be the intensity value of pixel p in the grayscale image to be processed, and q be the pixel point corresponding to pixel p in the grayscale image to be processed in the dark channel image. q Let q be the intensity value of pixel q in the dark channel image.
[0035] Thirdly, embodiments of the present invention provide an electronic device, including: a processor, a memory, and a program stored in the memory and executable on the processor, wherein when the program is executed by the processor, it implements the steps of the image processing method described in the first aspect above.
[0036] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the image processing method described in the first aspect above.
[0037] In this embodiment of the invention, the dark channel image of the grayscale image to be processed is first determined, and nonlinear sharpening spatial filtering is performed on the dark channel image to eliminate the influence of illumination changes in the image to a certain extent, while simultaneously achieving brightness adjustment and contrast enhancement, thereby improving the stability and robustness of target recognition. Attached Figure Description
[0038] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:
[0039] Figure 1 This is one of the flowcharts illustrating the image processing method according to an embodiment of the present invention;
[0040] Figure 2 This is a second schematic flowchart of the image processing method according to an embodiment of the present invention;
[0041] Figure 3 This is a schematic diagram of the sine function curve used in the nonlinear sharpening spatial filter of this invention.
[0042] Figure 4 , Figure 5 and Figure 6 This is a schematic diagram comparing the image before and after processing in an embodiment of the present invention.
[0043] Figure 7 This is a schematic diagram of the image processing apparatus according to an embodiment of the present invention;
[0044] Figure 8 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0045] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0046] In the process of surface defect detection of products, we may encounter situations where the dynamic range of image grayscale values is very large, but the grayscale of the part of interest is very dark, and the image details cannot be identified.
[0047] The human eye can distinguish the grayscale of an image not only because of the illumination function (irradiation component), but also because of the reflection function (reflection component), which reflects the specific content of the image. Illumination intensity is generally uniform and usually changes slowly in space, manifesting as low-frequency components in the frequency domain. However, different materials have significantly different reflectivities, often causing abrupt changes in reflected light, thus altering the grayscale values of the image. This change is related to both high- and low-frequency components.
[0048] In this embodiment of the invention, nonlinear sharpening spatial filtering of the image is used. This is a special method for enhancing image contrast and compressing the image brightness range in the frequency domain. Its function is to adjust the grayscale range of the image, eliminate the problem of uneven illumination on the image, and effectively enhance the features of interest.
[0049] Please refer to Figure 1 This invention provides an image processing method, comprising:
[0050] Step 11: Obtain the grayscale image to be processed;
[0051] If the input image is an RGB image, then the input RGB image will be converted to a grayscale image.
[0052] Step 12: Obtain the dark channel image of the grayscale image to be processed;
[0053] Step 13: The dark channel image is filtered using a nonlinear sharpening spatial filter to obtain the processed image.
[0054] In this embodiment of the invention, the dark channel image of the grayscale image to be processed is first determined, and nonlinear sharpening spatial filtering is performed on the dark channel image to eliminate the influence of illumination changes in the image to a certain extent, while simultaneously achieving brightness adjustment and contrast enhancement, thereby improving the stability and robustness of target recognition.
[0055] Please refer to Figure 2 In this embodiment of the invention, optionally, obtaining the dark channel image of the grayscale image to be processed includes:
[0056] Step 121: Define a scanning window, the size of which is m×n, where m and n are both integers greater than or equal to 1;
[0057] Step 122: Use the scanning window to slide and scan the grayscale image to be processed to obtain a block region of size m×n;
[0058] Step 123: For each of the segmented regions, determine the minimum average grayscale value of the three RGB channels;
[0059] For example, the average grayscale value of the three RGB channels within a block area is calculated as follows:
[0060] R ave =S R / N;
[0061] G ave =S G / N;
[0062] B ave =S B / N;
[0063] Among them, R ave G is the average gray value of the R channel. ave The average gray value of the G channel, B ave S represents the average grayscale value of channel B. R S is the sum of the gray values of the pixels in the R channel. G S is the sum of the grayscale values of the pixels in the G channel. B The sum of the gray values of the pixels in the B channel is denoted as N, and N is the number of pixels in the m×n block region.
[0064] Then take R ave G ave and B ave The minimum value.
[0065] Step 124: Determine the dark channel image of the segmented region based on the minimum value;
[0066] Step 125: Obtain the dark channel image of the grayscale image to be processed based on the dark channel images of all the block regions.
[0067] Optionally, m and n are equal, both being 3. That is, a 3×3 scanning window is defined, and the grayscale image to be processed can be scanned by sliding with a step size of 3. Each slide results in a 3×3 partition region, and the dark channel image of the partition region is determined. Finally, after the grayscale image to be processed is scanned, all the 3×3 dark channel images are stitched together to obtain the dark channel image of the grayscale image to be processed.
[0068] Optionally, for each of the segmented regions, determining the minimum average grayscale value of the three RGB channels includes: for each of the segmented regions, calculating the sum of the grayscale values of the three RGB channels, dividing the sum of the grayscale values by the number of pixels in the segmented region to obtain the average grayscale value of the three RGB channels; and selecting the minimum value from the average grayscale values of the three RGB channels.
[0069] Optionally, determining the region dark channel image of the segmented region based on the minimum value includes: assigning the grayscale value of all pixels in the segmented region to the minimum value to obtain the region dark channel image of the segmented region.
[0070] That is: if R in the block region ave Less than G ave and B ave Then the grayscale value of all pixels within this block area is assigned to R. ave .
[0071] If G is in the block region ave Less than R ave and B ave Then the grayscale value of all pixels within this block area is assigned to G. ave .
[0072] If B is in the block region ave Less than R ave and G ave Then the grayscale value of all pixels within this block area is assigned to G. ave .
[0073] In this embodiment of the invention, the nonlinear sharpening spatial filter directly employs a spatial filter compared to existing filters, such as... Figure 3 As shown, a sine function curve can be used for design.
[0074] In this embodiment of the invention, optionally, a nonlinear sharpening spatial filter is used to filter the dark channel image to obtain a processed image, including:
[0075] The processed image is obtained using the following formula:
[0076]
[0077]
[0078] Where, F(I) p The processed image, This refers to the nonlinear sharpening spatial filter. Let I be the kernel function of the nonlinear sharpening spatial filter. qFor the dark channel image, μ k For the dark channel image in the kernel window ω k The mean, For the dark channel image in the kernel window ω k The variance, |ω| is the variance of the kernel window ω. k The size of the convolution kernel is given by ε = 0.000001, where k is the kernel size and G is the kernel size. p Let q be the grayscale value of pixel p in the grayscale image to be processed, and let q be the pixel point corresponding to pixel p in the grayscale image to be processed in the dark channel image. q Let q be the grayscale value of pixel q in the dark channel image.
[0079] Please refer to Figure 4 , Figure 5 and Figure 6 These are three different grayscale images to be processed. After processing them using the image processing method in this embodiment of the invention, the corresponding processed images are obtained. Figure 4 , Figure 5 and Figure 6 It can be seen that the original image can be made to eliminate the changes in illumination to a certain extent, while simultaneously adjusting the brightness and enhancing the contrast, thereby improving the stability and robustness of target recognition.
[0080] Please refer to Figure 7 The present invention also provides an image processing apparatus, comprising:
[0081] The first acquisition module 61 is used to acquire the grayscale image to be processed;
[0082] The second acquisition module 62 is used to acquire the dark channel image of the grayscale image to be processed;
[0083] The filtering module 63 is used to filter the dark channel image using a nonlinear sharpening spatial filter to obtain the processed image.
[0084] In this embodiment of the invention, the dark channel image of the grayscale image to be processed is first determined, and nonlinear sharpening spatial filtering is performed on the dark channel image to eliminate the influence of illumination changes in the image to a certain extent, while simultaneously achieving brightness adjustment and contrast enhancement, thereby improving the stability and robustness of target recognition.
[0085] In this embodiment of the invention, optionally, the second acquisition module 62 is used to define a scanning window, the size of which is m×n, where m and n are both integers greater than or equal to 1; the scanning window is used to slide and scan the grayscale image to be processed to obtain a block region of size m×n; for each block region, the minimum value of the average grayscale value of the three RGB channels is determined; the dark channel image of the block region is determined based on the minimum value; and the dark channel image of the grayscale image to be processed is obtained based on the dark channel images of all the block regions.
[0086] In this embodiment of the invention, m and n are optionally equal, both being 3.
[0087] In this embodiment of the invention, optionally, the second acquisition module 62 is used to calculate the sum of gray values of the three RGB channels for each of the block regions, divide the sum of gray values by the number of pixels in the block region to obtain the average gray value of the three RGB channels, and select the minimum value from the average gray values of the three RGB channels.
[0088] In this embodiment of the invention, optionally, the second acquisition module 62 is used to determine the region dark channel image of the segmented region based on the minimum value by: assigning the grayscale value of all pixels in the segmented region to the minimum value to obtain the region dark channel image of the segmented region.
[0089] Optionally, the filtering module 63 is used to obtain the processed image using the following formula:
[0090]
[0091]
[0092] Where, F(I) p The processed image, This refers to the nonlinear sharpening spatial filter. Let I be the kernel function of the nonlinear sharpening spatial filter. q For the dark channel image, μ k For the dark channel image in the kernel window v k The mean, For the dark channel image in the kernel window ω k The variance, |ω| is the variance of the kernel window ω. k The size of the convolution kernel is given by ε = 0.000001, where k is the kernel size and G is the kernel size. p Let q be the grayscale value of pixel p in the grayscale image to be processed, and let q be the pixel point corresponding to pixel p in the grayscale image to be processed in the dark channel image. qLet q be the grayscale value of pixel q in the dark channel image.
[0093] Please refer to Figure 8 The present invention also provides an electronic device 70, including a processor 71, a memory 72, and a computer program stored in the memory 72 and executable on the processor 71. When the computer program is executed by the processor 71, it implements the various processes of the above-described image processing method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0094] This invention also provides a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements the various processes of the above-described method embodiments and achieves the same technical effects. To avoid repetition, these will not be described again here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0095] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0096] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this 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 disk), and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0097] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of the present invention.
Claims
1. An image processing method, characterized in that, include: Obtain the grayscale image to be processed; Obtain the dark channel image of the grayscale image to be processed; The dark channel image is filtered using a nonlinear sharpening spatial filter to obtain the processed image. The step of filtering the dark channel image using a nonlinear sharpening spatial filter to obtain the processed image includes: The processed image is obtained using the following formula: Where, F(I) p The processed image, This refers to the nonlinear sharpening spatial filter. Let I be the kernel function of the nonlinear sharpening spatial filter. q For the dark channel image, μ k For the dark channel image in the kernel window ω k The mean, For the dark channel image in the kernel window ω k The variance, |ω| is the variance of the kernel window ω. k The size of the convolution kernel is given by ε = 0.000001, where k is the kernel size and G is the kernel size. p Let q be the grayscale value of pixel p in the grayscale image to be processed, and let q be the pixel point corresponding to pixel p in the grayscale image to be processed in the dark channel image. q Let q be the grayscale value of pixel q in the dark channel image.
2. The method according to claim 1, characterized in that, The step of obtaining the dark channel image of the grayscale image to be processed includes: Define a scanning window with a size of m×n, where m and n are both integers greater than or equal to 1; The grayscale image to be processed is scanned by sliding the scanning window to obtain a block region of size m×n; For each of the aforementioned block regions, determine the minimum average grayscale value of the three RGB channels; The region dark channel image of the segmented region is determined based on the minimum value; The dark channel image of the grayscale image to be processed is obtained based on the dark channel images of all the block regions.
3. The method according to claim 2, characterized in that, For each of the aforementioned block regions, determine the minimum average grayscale value of the three RGB channels, including: For each of the block regions, the sum of the gray values of the three RGB channels is calculated, and the average gray value of the three RGB channels is obtained by dividing the sum of the gray values by the number of pixels in the block region. Select the minimum value from the average grayscale values of the three RGB channels.
4. The method according to claim 2, characterized in that, The step of determining the region dark channel image of the segmented region based on the minimum value includes: The minimum grayscale value is assigned to all pixels within the segmented region to obtain the dark channel image of the segmented region.
5. An image processing apparatus, characterized in that, include: The first acquisition module is used to acquire the grayscale image to be processed; The second acquisition module is used to acquire the dark channel image of the grayscale image to be processed; The filtering module is used to filter the dark channel image using a nonlinear sharpening spatial filter to obtain the processed image. The filtering module is used to obtain the processed image using the following formula: Where, F(I) p The processed image, This refers to the nonlinear sharpening spatial filter. Let I be the kernel function of the nonlinear sharpening spatial filter. q For the dark channel image, μ k For the dark channel image in the kernel window ω k The mean, For the dark channel image in the kernel window ω k The variance, |ω| is the variance of the kernel window ω. k The size of G, ε=0.000001. p Let be the intensity value of pixel p in the grayscale image to be processed, and q be the pixel point corresponding to pixel p in the grayscale image to be processed in the dark channel image. q Let q be the intensity value of pixel q in the dark channel image.
6. The apparatus according to claim 5, characterized in that, The second acquisition module is used to define a scanning window of size m×n, where m and n are both integers greater than or equal to 1; to slide and scan the grayscale image to be processed using the scanning window to obtain block regions of size m×n; to determine the minimum average grayscale value of the three RGB channels for each block region; to determine the dark channel image of the block region based on the minimum value; and to obtain the dark channel image of the grayscale image to be processed based on the dark channel images of all the block regions.
7. An electronic device, characterized in that, include: A processor, a memory, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements the steps of the image processing method as described in any one of claims 1 to 4.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the image processing method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Low-illumination image processing method and device
WO2016206087A1