Image enhancement methods, apparatus, devices and readable storage media
By processing, enhancing, and resetting the grayscale values of the images, the problem of inaccurate defect detection caused by insufficient ROI visibility was solved, thus achieving ROI prominence and improving the accuracy of defect detection.
Patent Information
- Application Number
- CN202211193645.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-28
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2042-09-28
AI Technical Summary
In existing technologies, insufficient ROI leads to inaccurate defect detection.
The image to be processed is obtained by processing the image to obtain a positive image; the maximum gray value is selected according to the gray-level histogram of the positive image, the expansion ratio is calculated, and the image is enhanced based on this ratio; finally, the gray value is reset to obtain the enhanced image.
Highlighting the ROI improves the accuracy of defect detection.
Smart Images

Figure CN115578275B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to an image enhancement method, apparatus, device, and readable storage medium. Background Technology
[0002] The defective region in an image is called the ROI (Region of Interest).
[0003] In some cases, when the Region of Interest (ROI) in an image is not obvious enough, the ROI extraction may not be accurate enough, resulting in inaccurate defect detection. Summary of the Invention
[0004] The main objective of this invention is to provide an image enhancement method, apparatus, device, and readable storage medium, aiming to solve the technical problem that defect detection is not accurate enough when the ROI is not obvious in the prior art.
[0005] In a first aspect, the present invention provides an image enhancement method, the image enhancement method comprising:
[0006] The image to be processed is processed to obtain a positive value image;
[0007] Select the maximum gray value based on the gray-level histogram corresponding to the positive value image;
[0008] The expansion ratio is obtained based on the maximum grayscale value;
[0009] The positive value image is enhanced based on the expansion ratio to obtain an enhanced positive value image.
[0010] The enhanced positive image is then resized to obtain the enhanced image.
[0011] Optionally, the step of processing the image to be processed to obtain a positive value image includes:
[0012] If the number of channels of the image to be processed is greater than 1, then the image to be processed is converted into a single-channel byte type image;
[0013] The single-channel byte-type image is converted to a real-type image;
[0014] Convert the real-type image to a positive value image.
[0015] Optionally, the step of selecting the maximum gray value based on the gray-level histogram corresponding to the positive image includes:
[0016] Remove the lowest grayscale region and the highest grayscale region at a preset ratio from the grayscale histogram corresponding to the positive image, and select the maximum grayscale value from the remaining part.
[0017] Optionally, the step of obtaining the expansion ratio based on the maximum grayscale value includes:
[0018] Substituting the maximum grayscale value and the first non-zero value in the decimal part of the maximum grayscale value into the expansion ratio calculation formula, we obtain the expansion ratio. The expansion ratio calculation formula is as follows:
[0019]
[0020] Where S is the expansion ratio, F is the first non-zero value in the decimal part of the maximum grayscale value, and M is the maximum grayscale value.
[0021] Optionally, the step of enhancing the positive image based on the expansion ratio to obtain the enhanced positive image includes:
[0022] The positive image is enhanced based on the enhancement equation and the expansion ratio to obtain an enhanced positive image. The enhancement equation is:
[0023] g′=g*S+T
[0024] Where g′ is the enhanced positive image, g is the positive image, and T is the preset grayscale value.
[0025] Optionally, the step of resetting the grayscale value of the enhanced positive image:
[0026] In the enhanced positive image, the gray values of pixels whose gray values are less than the first threshold are reset to the first preset gray value.
[0027] In the enhanced positive image, the gray values of pixels with gray values greater than the second threshold are reset to the second preset gray value;
[0028] The gray values of pixels in the enhanced positive image within a first preset range are linearly stretched to a second preset range, wherein the lower limit of the first preset range is the first threshold and the upper limit is the second threshold, and the lower limit of the second preset range is the first preset gray value and the upper limit is the second preset gray value.
[0029] Optionally, the first preset grayscale value is 0, and the second preset grayscale value is 255.
[0030] In a second aspect, the present invention also provides an image enhancement apparatus, the image enhancement apparatus comprising:
[0031] The processing module is used to process the image to be processed and obtain a positive value image;
[0032] The selection module is used to select the maximum gray value based on the gray-level histogram corresponding to the positive image.
[0033] The calculation module is used to obtain the expansion ratio based on the maximum gray value;
[0034] An enhancement module is used to enhance the positive image based on the expansion ratio to obtain an enhanced positive image.
[0035] The reset module is used to reset the grayscale value of the enhanced positive image to obtain the enhanced image.
[0036] Thirdly, the present invention also provides an image enhancement device, the image enhancement device including a processor, a memory, and an image enhancement program stored in the memory and executable by the processor, wherein when the image enhancement program is executed by the processor, it implements the steps of the image enhancement method as described above.
[0037] Fourthly, the present invention also provides a readable storage medium storing an image enhancement program, wherein when the image enhancement program is executed by a processor, it implements the steps of the image enhancement method described above.
[0038] In this invention, the image to be processed is processed to obtain a positive value image; the maximum gray value is selected based on the gray-level histogram corresponding to the positive value image; an expansion ratio is obtained based on the maximum gray value; the positive value image is enhanced based on the expansion ratio to obtain an enhanced positive value image; and the gray values of the enhanced positive value image are reset to obtain an enhanced image. This invention enables the enhancement of the image to be processed, thereby highlighting the region of interest (ROI) in the image and improving the accuracy of defect detection. Attached Figure Description
[0039] Figure 1 This is a schematic diagram of the hardware structure of the image enhancement device involved in the embodiment of the present invention;
[0040] Figure 2 This is a schematic flowchart of an embodiment of the image enhancement method of the present invention;
[0041] Figure 3 This is a schematic diagram of the original image captured by the camera in one embodiment;
[0042] Figure 4 This is a schematic diagram of the image to be processed in one embodiment;
[0043] Figure 5 This is a schematic diagram of a real-type image in one embodiment;
[0044] Figure 6This is a schematic diagram of a positive value image in one embodiment;
[0045] Figure 7 This is a schematic diagram of an enhanced positive value image in one embodiment;
[0046] Figure 8 This is a schematic diagram of an enhanced image in one embodiment;
[0047] Figure 9 This is a schematic diagram of the functional modules of an embodiment of the image enhancement device of the present invention.
[0048] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0049] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0050] In a first aspect, embodiments of the present invention provide an image enhancement device, which may be a device with data processing capabilities such as a personal computer (PC), a laptop computer, or a server.
[0051] Reference Figure 1 , Figure 1 This is a schematic diagram of the hardware structure of the image enhancement device involved in the embodiment of the present invention. In this embodiment, the image enhancement device may include a processor 1001 (e.g., a Central Processing Unit, CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to realize communication between these components; the user interface 1003 may include a display screen or an input unit such as a keyboard; the network interface 1004 may optionally include a standard wired interface or a wireless interface (e.g., Wireless Fidelity, Wi-Fi interface); the memory 1005 may be high-speed random access memory (RAM) or stable memory (non-volatile memory), such as a disk storage device. The memory 1005 may also optionally be a storage device independent of the aforementioned processor 1001. Those skilled in the art will understand that… Figure 1 The hardware structure shown does not constitute a limitation of the invention and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0052] Continue to refer to Figure 1 , Figure 1The memory 1005, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an image enhancement program. The processor 1001 can call the image enhancement program stored in the memory 1005 and execute the image enhancement method provided in this embodiment of the invention.
[0053] Secondly, embodiments of the present invention provide an image enhancement method.
[0054] In one embodiment, reference is made to Figure 2 , Figure 2 This is a schematic flowchart of an embodiment of the image enhancement method of the present invention. Figure 2 As shown, image enhancement methods include:
[0055] Step S10: Process the image to be processed to obtain a positive value image;
[0056] In this embodiment, the original image captured by the camera is first acquired, then the image to be processed is cropped from the original image, and then the image to be processed is processed according to a preset method to obtain a positive value image. (Refer to...) Figure 3 , Figure 3 This is a schematic diagram of the original image captured by the camera in one embodiment. Figure 3 As shown, the display panel is placed on the platform, and the original image obtained by the camera includes the platform (i.e., the display panel is placed on the platform). Figure 3 The image consists of the black portion (in the image) and the display panel (the portion outside the black portion). Then, the image corresponding to the display panel in the original image is cropped to obtain the result shown below. Figure 4 The image to be processed is shown. (Refer to...) Figure 4 , Figure 4 This is a schematic diagram of the image to be processed in one embodiment.
[0057] Further, in one embodiment, step S10 includes:
[0058] Step S101: If the number of channels of the image to be processed is greater than 1, then the image to be processed is converted into a single-channel byte type image.
[0059] In this embodiment, if the number of channels of the image to be processed is greater than 1, the image to be processed is converted, that is, the image to be processed is converted into a single-channel byte type image.
[0060] It should be noted that if the image to be processed is a single-channel byte image, then no conversion is required.
[0061] Step S102: Convert the format of the single-channel byte type image to obtain a real type image;
[0062] In this embodiment, a single-channel image can be converted from a single-channel byte-type image to a real-type image through forward and inverse transformations from the spatial domain to the frequency domain. (Refer to...) Figure 5 , Figure 5 This is a schematic diagram of a real-type image in one embodiment.
[0063] Step S103: Convert the real type image into a positive value image.
[0064] In this embodiment, the real-type image is further converted into a positive-value image, where the grayscale range is 0 to 1. (Refer to...) Figure 6 , Figure 6 This is a schematic diagram of a positive value image in one embodiment.
[0065] Step S20: Select the maximum gray value based on the gray-level histogram corresponding to the positive image;
[0066] In this embodiment, the grayscale histogram corresponding to the positive value image can be obtained using appropriate software, such as Matlab. Then, based on the grayscale histogram, the maximum grayscale value is selected according to a specific selection method.
[0067] Further, in one embodiment, step S20 includes:
[0068] Remove the lowest grayscale region and the highest grayscale region at a preset ratio from the grayscale histogram corresponding to the positive image, and select the maximum grayscale value from the remaining part.
[0069] In this embodiment, the lowest grayscale region and the highest grayscale region of a preset ratio in the grayscale histogram are removed, and then the maximum grayscale value is selected from the remaining portion. For example, if there are 10 pixels with grayscale values evenly distributed between 0 and 1: 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, and the preset ratio is 20%, then the maximum grayscale value after removal is 0.8. It should be noted that the preset ratio can be set according to actual needs and is not limited here.
[0070] Step S30: Obtain the expansion ratio based on the maximum grayscale value;
[0071] In this embodiment, after determining the maximum grayscale value, the expansion ratio is obtained based on the maximum grayscale value using a preset method.
[0072] Further, in one embodiment, step S30 includes:
[0073] Substituting the maximum grayscale value and the first non-zero value in the decimal part of the maximum grayscale value into the expansion ratio calculation formula, we obtain the expansion ratio. The expansion ratio calculation formula is as follows:
[0074]
[0075] Where S is the expansion ratio, F is the first non-zero value in the decimal part of the maximum grayscale value, and M is the maximum grayscale value.
[0076] In this embodiment, the decimal part of the maximum grayscale value has multiple digits and is generally less than 0.0001. Assuming the maximum grayscale value is 0.0007456, the first non-zero digit of its decimal part is 7. Substituting the maximum grayscale value and the first non-zero digit of its decimal part into the expansion ratio calculation formula, we obtain the expansion ratio as follows:
[0077]
[0078] It should be noted that the specific values mentioned above are for illustrative purposes only and do not constitute a limitation on this embodiment.
[0079] Step S40: Enhance the positive image based on the expansion ratio to obtain an enhanced positive image;
[0080] In this embodiment, the enhancement equation is set according to actual conditions. Based on the expansion ratio obtained in step S30 and the preset enhancement equation, the positive image is enhanced to obtain the enhanced positive image. (Refer to...) Figure 7 , Figure 7 This is a schematic diagram of an enhanced positive value image in one embodiment. According to... Figure 6 The direction of the twill can be determined, for example... Figure 6 If the twill is perpendicular, then it can be... Figure 7 Set areas not to be detected, for example Figure 7 The black areas on the left and right sides. It's easy to understand that if the diagonal stripes are horizontal, then... Figure 7 Set non-detection areas at the top and bottom. It should be noted that setting non-detection areas is not a necessary step and can be omitted depending on the actual situation.
[0081] Further, in one embodiment, step S40 includes:
[0082] The positive image is enhanced based on the enhancement equation and the expansion ratio to obtain an enhanced positive image. The enhancement equation is:
[0083] g′=g*S+T
[0084] Wherein, g′ is the enhanced positive image, g is the positive image, and T is the preset grayscale value. Specifically, g′ refers to the grayscale value of each pixel in the positive image, and g specifically refers to the grayscale value of each pixel in the positive image.
[0085] In this embodiment, the value of T is set according to actual needs.
[0086] Step S50: Reset the grayscale value of the enhanced positive image to obtain the enhanced image.
[0087] In this embodiment, the grayscale values of each pixel in the enhanced positive image are graded, and the grayscale values of the corresponding pixels at each grade are reset according to the reset method corresponding to each grade, thus obtaining the enhanced image. (Refer to...) Figure 8 , Figure 8 This is a schematic diagram of an enhanced image in one embodiment. (Comparison) Figure 4 and Figure 8 As can be seen, the ROI is displayed more clearly.
[0088] Furthermore, in one embodiment, the step of resetting the grayscale value of the enhanced positive image includes:
[0089] Step S501: Reset the gray values of pixels in the enhanced positive image whose gray values are less than the first threshold to the first preset gray value;
[0090] In this embodiment, pixels with grayscale values less than a first threshold are found in the enhanced positive image, and the grayscale values of these pixels are reset to a first preset grayscale value. The first threshold is set according to actual needs.
[0091] Step S502: Reset the gray values of pixels in the enhanced positive image whose gray values are greater than the second threshold to the second preset gray value;
[0092] In this embodiment, pixels with grayscale values greater than a second threshold are found in the enhanced positive image, and the grayscale values of these pixels are reset to a second preset grayscale value. The second threshold is set according to actual needs.
[0093] Step S503: Linearly stretch the gray values of pixels in the enhanced positive image within a first preset range to a second preset range, wherein the lower limit of the first preset range is the first threshold and the upper limit is the second threshold, and the lower limit of the second preset range is the first preset gray value and the upper limit is the second preset gray value.
[0094] In this embodiment, for pixels with a first threshold ≤ grayscale value ≤ second threshold, the grayscale value of the pixels of this type is linearly stretched to a second preset range.
[0095] The first threshold and the second threshold are set according to actual needs.
[0096] Furthermore, in one embodiment, the first preset grayscale value is 0, and the second preset grayscale value is 255.
[0097] In this embodiment, the gray values of pixels in the enhanced positive image whose gray values are less than a first threshold are reset to 0; the gray values of pixels in the enhanced positive image whose gray values are greater than a second threshold are reset to 255; and the gray values of other pixels in the enhanced positive image are linearly stretched to 0-255, thereby obtaining the enhanced image. (Comparison) Figure 4 and Figure 8 As can be seen, the ROI is displayed more clearly.
[0098] In this embodiment, the image to be processed is processed to obtain a positive value image; the maximum gray value is selected based on the gray-level histogram corresponding to the positive value image; an expansion ratio is obtained based on the maximum gray value; the positive value image is enhanced based on the expansion ratio to obtain an enhanced positive value image; the gray values of the enhanced positive value image are reset to obtain an enhanced image. This embodiment enables the enhancement of the image to be processed, thereby highlighting the region of interest (ROI) in the image and improving the accuracy of defect detection.
[0099] Thirdly, embodiments of the present invention also provide an image enhancement device.
[0100] In one embodiment, reference is made to Figure 8 , Figure 8 This is a schematic diagram of the functional modules of an embodiment of the image enhancement device of the present invention. Figure 8 As shown, the image enhancement device includes:
[0101] Processing module 10 is used to process the image to be processed to obtain a positive value image;
[0102] Module 20 is used to select the maximum gray value based on the gray-level histogram corresponding to the positive image;
[0103] Calculation module 30 is used to obtain the expansion ratio based on the maximum gray value;
[0104] Enhancement module 40 is used to enhance the positive image based on the expansion ratio to obtain an enhanced positive image;
[0105] The reset module 50 is used to reset the grayscale value of the enhanced positive image to obtain the enhanced image.
[0106] Furthermore, in one embodiment, the processing module 10 is configured to:
[0107] If the number of channels of the image to be processed is greater than 1, then the image to be processed is converted into a single-channel byte type image;
[0108] The single-channel byte-type image is converted to a real-type image;
[0109] Convert the real-type image to a positive value image.
[0110] Furthermore, in one embodiment, module 20 is selected for:
[0111] Remove the lowest grayscale region and the highest grayscale region at a preset ratio from the grayscale histogram corresponding to the positive image, and select the maximum grayscale value from the remaining part.
[0112] Furthermore, in one embodiment, the calculation module 30 is used for:
[0113] Substituting the maximum grayscale value and the first non-zero value in the decimal part of the maximum grayscale value into the expansion ratio calculation formula, we obtain the expansion ratio. The expansion ratio calculation formula is as follows:
[0114]
[0115] Where S is the expansion ratio, F is the first non-zero value in the decimal part of the maximum grayscale value, and M is the maximum grayscale value.
[0116] Furthermore, in one embodiment, the enhancement module 40 is used for:
[0117] The positive image is enhanced based on the enhancement equation and the expansion ratio to obtain an enhanced positive image. The enhancement equation is:
[0118] g′=g*S+T
[0119] Where g′ is the enhanced positive image, g is the positive image, and T is the preset grayscale value.
[0120] Furthermore, in one embodiment, the reset module 50 is used for:
[0121] In the enhanced positive image, the gray values of pixels whose gray values are less than the first threshold are reset to the first preset gray value.
[0122] In the enhanced positive image, the gray values of pixels with gray values greater than the second threshold are reset to the second preset gray value;
[0123] The gray values of pixels in the enhanced positive image within a first preset range are linearly stretched to a second preset range, wherein the lower limit of the first preset range is the first threshold and the upper limit is the second threshold, and the lower limit of the second preset range is the first preset gray value and the upper limit is the second preset gray value.
[0124] Furthermore, in one embodiment, the first preset grayscale value is 0, and the second preset grayscale value is 255.
[0125] The functions of each module in the above-mentioned image enhancement device correspond to the steps in the above-mentioned image enhancement method embodiments, and their functions and implementation processes will not be described in detail here.
[0126] Fourthly, embodiments of the present invention also provide a readable storage medium.
[0127] The present invention provides an image enhancement program stored on a readable storage medium, wherein when the image enhancement program is executed by a processor, it implements the steps of the image enhancement method described above.
[0128] The method implemented when the image enhancement program is executed can be referred to in various embodiments of the image enhancement method of the present invention, and will not be repeated here.
[0129] 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 system 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 system. 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 system that includes that element.
[0130] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0131] 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) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of the present invention.
[0132] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.
Claims
1. An image enhancement method, characterized in that, The image enhancement method includes: The image to be processed is processed to obtain a positive value image; Select the maximum gray value based on the gray-level histogram corresponding to the positive value image; The expansion ratio is obtained based on the maximum grayscale value; The positive value image is enhanced based on the expansion ratio to obtain an enhanced positive value image. The enhanced positive image is then resized to obtain the enhanced image.
2. The image enhancement method as described in claim 1, characterized in that, The steps of processing the image to be processed to obtain a positive value image include: If the number of channels of the image to be processed is greater than 1, then the image to be processed is converted into a single-channel byte type image; The single-channel byte-type image is converted to a real-type image; Convert the real-type image to a positive value image.
3. The image enhancement method as described in claim 1, characterized in that, The step of selecting the maximum gray value based on the gray-level histogram corresponding to the positive image includes: Remove the lowest grayscale region and the highest grayscale region at a preset ratio from the grayscale histogram corresponding to the positive image, and select the maximum grayscale value from the remaining part.
4. The image enhancement method as described in claim 3, characterized in that, The step of obtaining the expansion ratio based on the maximum grayscale value includes: Substituting the maximum grayscale value and the first non-zero value in the decimal part of the maximum grayscale value into the expansion ratio calculation formula, we obtain the expansion ratio. The expansion ratio calculation formula is as follows: Where S is the expansion ratio, F is the first non-zero value in the decimal part of the maximum grayscale value, and M is the maximum grayscale value.
5. The image enhancement method as described in claim 4, characterized in that, The step of enhancing the positive image based on the expansion ratio to obtain the enhanced positive image includes: The positive image is enhanced based on the enhancement equation and the expansion ratio to obtain an enhanced positive image. The enhancement equation is: g′=g*S+T Where g′ is the enhanced positive image, g is the positive image, and T is the preset grayscale value.
6. The image enhancement method as described in claim 1, characterized in that, The step of resetting the grayscale value of the enhanced positive image: In the enhanced positive image, the gray values of pixels whose gray values are less than the first threshold are reset to the first preset gray value. In the enhanced positive image, the gray values of pixels whose gray values are greater than the second threshold are reset to the second preset gray value. The gray values of pixels in the enhanced positive image within a first preset range are linearly stretched to a second preset range, wherein the lower limit of the first preset range is the first threshold and the upper limit is the second threshold, and the lower limit of the second preset range is the first preset gray value and the upper limit is the second preset gray value.
7. The image enhancement method as described in claim 6, characterized in that, The first preset grayscale value is 0, and the second preset grayscale value is 255.
8. An image enhancement device, characterized in that, The image enhancement device includes: The processing module is used to process the image to be processed and obtain a positive value image; The selection module is used to select the maximum gray value based on the gray-level histogram corresponding to the positive image. The calculation module is used to obtain the expansion ratio based on the maximum gray value; An enhancement module is used to enhance the positive image based on the expansion ratio to obtain an enhanced positive image. The reset module is used to reset the grayscale value of the enhanced positive image to obtain the enhanced image.
9. An image enhancement device, characterized in that, The image enhancement device includes a processor, a memory, and an image enhancement program stored in the memory and executable by the processor, wherein when the image enhancement program is executed by the processor, it implements the steps of the image enhancement method as described in any one of claims 1 to 7.
10. A readable storage medium, characterized in that, The readable storage medium stores an image enhancement program, wherein when the image enhancement program is executed by a processor, it implements the steps of the image enhancement method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Image enhancement method and device suitable for endoscope and storage medium
CN110533609A
Image processing method and device, electronic equipment and computer readable storage medium
CN111415317A