Adaptive graying target edge enhancement method and device and readable medium
Through the adaptive grayscale method, the image clarity evaluation algorithm and median filtering denoising are used to determine the deviation coefficient and threshold for grayscale transformation, which solves the problems of poor image grayscale effect and complex debugging in industrial production, and achieves efficient edge enhancement and accuracy improvement.
Patent Information
- Application Number
- CN202310716994.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-16
- Publication Date
- 2025-07-18
AI Technical Summary
The prior art has poor image graying effect in industrial production, complex debugging process, and adaptive graying algorithms are sensitive to noise and easily lead to loss of edge details.
The image clarity evaluation algorithm determines the single-channel image with the highest definition, sets the deviation coefficient, calculates the first and second thresholds for grayscale transformation, combines median filtering and denoising, adjusts the deviation coefficient to optimize the grayscale transformation, and enhances edge contrast.
Improves accuracy and effectiveness of edge extraction, reduces debugging complexity, is more adaptable, retains edge details and enhances edge contrast.
Smart Images

Figure CN120339081A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and particularly to a method, device and readable medium for enhancing the edges of an object with adaptive grayscale conversion. Background Art
[0002] Machine vision has been widely applied to defect detection in industrial production. The key to visual inspection lies in object localization and edge extraction. When performing edge extraction, generally, the image is first preprocessed to convert the three-channel color image collected by the camera into a single-channel grayscale image. The edge features of the grayscale image play a decisive role in the effect of edge extraction. Conventional grayscale conversion usually has problems such as small edge gradients and unclear edges, and it is necessary to perform grayscale transformation enhancement on the grayscale image to obtain clearer edge features and improve the accuracy of edge extraction.
[0003] Currently, the commonly used grayscale transformation algorithms require manual input of upper and lower limits. When appropriate upper and lower limits are input, good results can be achieved, but continuous attempts are required to debug to the best effect, and the debugging process is complex. Commonly used adaptive grayscale conversion algorithms such as histogram equalization grayscale conversion, OTSU algorithm, etc.; if the image is a picture in industrial production where the proportion of the object in the picture is small, when the adaptive grayscale conversion algorithm uses histogram equalization grayscale conversion, it is greatly affected by noise and the edge gradient change is not obvious; when the adaptive grayscale conversion algorithm uses the OTSU algorithm to segment the background area and the object area, serious loss of edge details will occur, so the grayscale conversion effect is poor. Summary of the Invention
[0004] Aiming at the above-mentioned technical problems such as poor grayscale conversion effect and complex debugging process in industrial production inspection. The purpose of the embodiments of the present application is to propose a method, device and readable medium for enhancing the edges of an object with adaptive grayscale conversion to solve the technical problems mentioned in the above background art section.
[0005] In a first aspect, the present invention provides a method for enhancing the edges of an object with adaptive grayscale conversion, including the following steps:
[0006] S1, obtain an image, determine the first single-channel image with the highest clarity in different channels corresponding to the image through an image clarity evaluation algorithm, and set the deviation coefficient in the grayscale transformation process of the first single-channel image;
[0007] S2, determine a first threshold and a second threshold according to the deviation coefficient, where the first threshold is the grayscale value at the boundary between the background area and the edge candidate area and the object area in the first single-channel image, and the second threshold is the grayscale value at the boundary between the edge candidate area and the object area, and perform grayscale transformation on the first single-channel image according to the first threshold and the second threshold to obtain a second single-channel image;
[0008] S3. Adjust the deviation coefficient, repeat step S2 to determine the second single-channel image corresponding to the grayscale transformation of the first single-channel image under different deviation coefficients, and evaluate the second single-channel images corresponding to different deviation coefficients through an image sharpness evaluation algorithm to obtain the sharpness evaluation values corresponding to the second single-channel images obtained under different deviation coefficients.
[0009] S4. Determine the target image in the second single-channel image according to the sharpness evaluation values corresponding to the second single-channel images obtained under different deviation coefficients.
[0010] Preferably, step S4 specifically includes:
[0011] Normalize the sharpness evaluation values corresponding to the second single-channel images obtained under different deviation coefficients to obtain the normalized evaluation values.
[0012] Select the second single-channel image obtained under the deviation coefficient corresponding to the normalized evaluation value as the target image.
[0013] Preferably, in the first single-channel image, the region where the grayscale value is between the first threshold and the second threshold is the edge candidate region, the region where the grayscale value is less than the first threshold is the background region, and the region where the grayscale value is greater than the second threshold is the target region.
[0014] Preferably, in step S2, determining the first threshold and the second threshold according to the deviation coefficient specifically includes:
[0015] Use the following formula to calculate the grayscale average value M1 of the first single-channel image:
[0016]
[0017] where R1 is the first single-channel image, (x, y) are the coordinates of the pixel point, f(x, y) is the grayscale value of the pixel point (x, y) in the first single-channel image, and n1 is the number of pixel points in the first single-channel image;
[0018] Calculate the grayscale deviation d1 of the first single-channel image according to the grayscale average value of the first single-channel image. The formula is as follows:
[0019]
[0020] Calculate the first threshold a according to the grayscale average value and the grayscale deviation of the first single-channel image l , and the formula is as follows:
[0021] a l = M1 + k·d1;
[0022] where k is the deviation coefficient;
[0023] Segment the background region, edge candidate region, and target region in the first single-channel image according to the first threshold to obtain a third single-channel image, and determine the gray value F(x, y) of the third single-channel image:
[0024] F(x, y) = f(x, y) when f(x, y) ≥ a l ;
[0025] Calculate the average gray value M2 of the third single-channel image using the following formula:
[0026]
[0027] where R2 is the third single-channel image and n2 is the number of pixel points in the third single-channel image;
[0028] Calculate the gray deviation d2 of the third single-channel image based on the average gray value of the third single-channel image. The formula is as follows:
[0029]
[0030] Calculate the second threshold a based on the average gray value and gray deviation of the third single-channel image h , and the formula is as follows:
[0031] a h = M2 + k·d2.
[0032] Preferably, in step S2, gray-scale transformation of the first single-channel image is performed according to the first threshold and the second threshold, which specifically includes:
[0033] Perform gray-scale transformation on the first single-channel image using the following formula:
[0034]
[0035] where G(x, y) is the gray value of the pixel point (x, y) in the second single-channel image.
[0036] Preferably, the range of the deviation coefficient is between the third threshold and the fourth threshold, and the deviation coefficient is set to the third threshold in step S1;
[0037] In step S3, adjust the deviation coefficient, which specifically includes:
[0038] Gradually increase it from the third threshold to the fourth threshold in a preset step size.
[0039] Preferably, in step S1, the first single-channel image with the highest clarity among different channels corresponding to the image is determined through an image clarity evaluation algorithm, which specifically includes:
[0040] Split the image into a number of fourth single-channel images according to several channels;
[0041] Perform denoising on the number of fourth single-channel images using median filtering to obtain fifth single-channel images;
[0042] Evaluate the fifth single-channel image through an image sharpness evaluation algorithm to obtain the sharpness evaluation value of the fifth single-channel image. The formula is as follows:
[0043] G x = f(x + 2, y) - f(x, y);
[0044] G y = f(x, y + 2) - f(x, y);
[0045] G xy = |f(x, y) - f(x + 1, y + 1)| + |f(x + 1, y) - f(x, y + 1)|;
[0046] F = G x ·G y ·G xy ;
[0047] Among them, G x is the gradient information of the fifth single-channel image in the x direction, G y is the gradient information of the fifth single-channel image in the y direction, G xy is the gradient information of the fifth single-channel image in the ±45° direction, F is the sharpness evaluation value, and f(x, y) is the gray value of the pixel point (x, y) in the fifth single-channel image;
[0048] Select the fifth single-channel image corresponding to the maximum sharpness evaluation value as the first single-channel image.
[0049] In a second aspect, the present invention provides an adaptive grayscale target edge enhancement device, including the following steps:
[0050] An image acquisition module, configured to acquire an image, determine the first single-channel image with the highest sharpness in different channels corresponding to the image through an image sharpness evaluation algorithm, and set the deviation coefficient during the gray-scale transformation of the first single-channel image;
[0051] A gray-scale transformation module, configured to determine a first threshold and a second threshold according to the deviation coefficient. Among them, the first threshold is the gray value at the boundary between the background region and the edge candidate region and the target region in the first single-channel image, and the second threshold is the gray value at the boundary between the edge candidate region and the target region. Perform gray-scale transformation on the first single-channel image according to the first threshold and the second threshold to obtain a second single-channel image;
[0052] An adjustment module, configured to adjust a deviation coefficient, repeatedly execute a grayscale transformation module, determine a second single-channel image corresponding to the first single-channel image after grayscale transformation under different deviation coefficients, and evaluate the second single-channel images corresponding to different deviation coefficients through an image sharpness evaluation algorithm, so as to obtain sharpness evaluation values corresponding to the second single-channel images obtained under different deviation coefficients;
[0053] An output module, configured to determine a target image according to the sharpness evaluation values corresponding to the second single-channel images obtained under different deviation coefficients.
[0054] In a third aspect, the present invention provides an electronic device, including one or more processors; a storage device, configured to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any implementation manner of the first aspect.
[0055] In a fourth aspect, the present invention provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method described in any implementation manner of the first aspect is implemented.
[0056] Compared with the prior art, the present invention has the following beneficial effects:
[0057] (1) The present invention applies the grayscale average value and grayscale deviation of an image to the grayscale transformation process, and combines an image sharpness evaluation algorithm to implement an adaptive transformation grayscale target edge enhancement method, which can solve the problems of poor grayscale effect and complex debugging process in industrial production detection.
[0058] (2) The present invention performs median filtering denoising and combines an image sharpness evaluation algorithm to select the first single-channel image with the highest sharpness in different channels corresponding to the image, so that the effect of the second single-channel image obtained by grayscale transformation is better and the adaptability is higher. On this basis, the first single-channel image is subjected to grayscale transformation under different deviation coefficients, the first threshold and the second threshold are determined, and grayscale linear transformation is performed through the first threshold and the second threshold to increase the grayscale difference between the edge candidate region and the background region and the target region, improve the contrast of the edge region, and increase the grayscale gradient of the edge region, so as to achieve the purpose of edge contrast enhancement.
[0059] (3) The present invention adjusts the deviation coefficient, traverses and adjusts the first threshold and the second threshold of the grayscale transformation, obtains the second single-channel images corresponding to different deviation coefficients, and determines that the second single-channel image obtained under the deviation coefficient corresponding to the maximum sharpness evaluation value is the target image, which can not only greatly retain edge details, but also achieve a very good edge enhancement effect, making the accuracy of target edge extraction higher. Description of the Drawings
[0060] To more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.
[0061] Figure 1 It is an exemplary device architecture diagram to which an embodiment of the present application can be applied;
[0062] Figure 2 It is a schematic flowchart of the target edge enhancement method for adaptive grayscale conversion in the embodiment of the present application;
[0063] Figure 3 It is a flowchart of the target edge enhancement method for adaptive grayscale conversion in the embodiment of the present application;
[0064] Figure 4 It is the image obtained in step S1 of the target edge enhancement method for adaptive grayscale conversion in the embodiment of the present application;
[0065] Figures 5-7 They are respectively three fourth single-channel images obtained by splitting the channels of the image of the target edge enhancement method for adaptive grayscale conversion in the embodiment of the present application, and the one with the highest clarity is selected Figure 5 as the first single-channel image;
[0066] Figure 8 It is a schematic diagram of the image clarity evaluation curve of the target edge enhancement method for adaptive grayscale conversion in the embodiment of the present application;
[0067] Figure 9 It is the target image of the target edge enhancement method for adaptive grayscale conversion in the embodiment of the present application;
[0068] Figure 10 It is a schematic diagram of the target edge enhancement device for adaptive grayscale conversion in the embodiment of the present application;
[0069] Figure 11 It is a schematic diagram of the structure of a computer device of an electronic device suitable for implementing the embodiments of the present application. Detailed implementation manners
[0070] In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the drawings. Obviously, the described embodiments are only some embodiments of the present invention, rather than all embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts fall within the scope of protection of the present invention.
[0071] Figure 1 An exemplary device architecture 100 is shown that can apply the target edge enhancement method of adaptive grayscale conversion or the target edge enhancement device of adaptive grayscale conversion according to the embodiments of the present application.
[0072] As Figure 1 shown, the device architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.
[0073] Users can use the terminal devices 101, 102, 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various applications can be installed on the terminal devices 101, 102, 103, such as data processing applications, file processing applications, etc.
[0074] The terminal devices 101, 102, 103 can be hardware or software. When the terminal devices 101, 102, 103 are hardware, they can be various electronic devices, including but not limited to smartphones, tablets, laptop portable computers, and desktop computers, etc. When the terminal devices 101, 102, 103 are software, they can be installed in the above-listed electronic devices. It can be implemented as multiple software or software modules (such as software or software modules for providing distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0075] The server 105 can be a server that provides various services, such as a background data processing server that processes files or data uploaded by the terminal devices 101, 102, 103. The background data processing server can process the obtained files or data and generate a processing result.
[0076] It should be noted that the target edge enhancement method of adaptive grayscale conversion provided by the embodiments of the present application can be executed by the server 105, or can be executed by the terminal devices 101, 102, 103. Correspondingly, the target edge enhancement device of adaptive grayscale conversion can be set in the server 105, or can be set in the terminal devices 101, 102, 103.
[0077] It should be understood that Figure 1 the numbers of the terminal devices, the network, and the server in are merely illustrative. According to the implementation requirements, there can be any number of terminal devices, networks, and servers. In the case where the data to be processed does not need to be obtained remotely, the above device architecture may not include a network, but only a server or a terminal device.
[0078] Figure 2 An edge enhancement method for adaptive grayscale conversion provided by an embodiment of the present application is shown, including the following steps:
[0079] S1. Obtain an image, determine the first single-channel image with the highest clarity in different channels corresponding to the image through an image clarity evaluation algorithm, and set the deviation coefficient of the first single-channel image during the grayscale transformation process.
[0080] In a specific embodiment, obtaining the image in step S1 and determining the first single-channel image with the highest clarity in different channels corresponding to the image through an image clarity evaluation algorithm specifically includes:
[0081] Split the image into a plurality of fourth single-channel images according to several channels;
[0082] Perform denoising on the plurality of fourth single-channel images by using median filtering to obtain fifth single-channel images;
[0083] Evaluate the fifth single-channel images through an image clarity evaluation algorithm to obtain the clarity evaluation value of the fifth single-channel images. The formula is as follows:
[0084] G x = f(x + 2, y) - f(x, y);
[0085] G y = f(x, y + 2) - f(x, y);
[0086] G xy = |f(x, y) - f(x + 1, y + 1)| + |f(x + 1, y) - f(x, y + 1)|;
[0087] F = G x ·G y ·G xy ;
[0088] where G x is the gradient information of the fifth single-channel image in the x direction, G y is the gradient information of the fifth single-channel image in the y direction, G xy is the gradient information of the fifth single-channel image in the ±45° direction, F is the clarity evaluation value, and f(x, y) is the grayscale value of the pixel point (x, y) in the fifth single-channel image;
[0089] Select the fifth single-channel image corresponding to the maximum clarity evaluation value of the fifth single-channel images as the first single-channel image.
[0090] In a specific embodiment, the range of the deviation coefficient is between a third threshold and a fourth threshold, and the deviation coefficient is set to the third threshold in step S1.
[0091] Specifically, referring to Figure 3 , in the embodiments of the present application, an image with a small proportion of the target in the picture in industrial production can be used as the research object. First, the image is acquired. In a specific embodiment, referring to Figure 4 , the image can be a color image. The color image is split into channels, and several fourth single-channel images corresponding to several channels are obtained. The single-channel image is a grayscale image, which can specifically include three channels, and three fourth single-channel images are obtained. Referring to Figures 5-7 . Since the images acquired in actual industrial production are affected by environmental light and brightness and are prone to noise, in order to reduce noise interference, median filtering can be used to denoise the three fourth single-channel images respectively. In other embodiments, other methods can also be used according to actual situations to obtain fifth single-channel images with better quality. And because the contrast of different channels is different and the degree of feature highlighting is different, the Brenner2d_Roberts image sharpness evaluation algorithm is used to process the fifth single-channel image, and the fifth single-channel image corresponding to the largest sharpness evaluation value is selected as the first single-channel image. Using this first single-channel image as the basic image in the subsequent gray-scale transformation process can make the effect of the image obtained after gray-scale transformation better.
[0092] The Brenner2d_Roberts image sharpness evaluation algorithm extracts the gray-scale gradient information of the fifth single-channel image from multiple angles and has good applicability in the case of edge direction changes. After determining the first single-channel image with the highest sharpness, the deviation coefficient in the gray-scale transformation process of the first single-channel image can be set. By traversing the deviation coefficient, the first threshold and the second threshold in the gray-scale transformation process of the first single-channel image are adjusted, and linear gray-scale transformation is performed on the first single-channel image to enhance the contrast of the edges of the first single-channel image. Specifically, the range of the deviation coefficient is between a third threshold and a fourth threshold (including the third threshold and the fourth threshold), and the initial value of the deviation coefficient can be set to the third threshold. As an example, the third threshold can be 0.6, and the fourth threshold can be 2.4. In other embodiments, the third threshold can also be set to other appropriate values.
[0093] S2. Determine the first threshold and the second threshold according to the deviation coefficient. Among them, the first threshold is the gray-scale value at the boundary between the background area and the edge candidate area and the target area in the first single-channel image, and the second threshold is the gray-scale value at the boundary between the edge candidate area and the target area. Perform gray-scale transformation on the first single-channel image according to the first threshold and the second threshold to obtain a second single-channel image.
[0094] In a specific embodiment, in step S2, determining the first threshold and the second threshold according to the deviation coefficient specifically includes:
[0095] Calculate the gray - scale average value M1 of the first single - channel image using the following formula:
[0096]
[0097] where R1 is the first single - channel image, (x, y) is the coordinate of the pixel point, f(x, y) is the gray - scale value of the pixel point (x, y) in the first single - channel image, and n1 is the number of pixel points in the first single - channel image;
[0098] Calculate the gray - scale deviation d1 of the first single - channel image according to the gray - scale average value of the first single - channel image. The formula is as follows:
[0099]
[0100] Calculate the first threshold a according to the gray - scale average value and the gray - scale deviation of the first single - channel image l , the formula is as follows:
[0101] a l = M1 + k·d1;
[0102] where k is the deviation coefficient;
[0103] Separate the background area, the edge candidate area, and the target area in the first single - channel image according to the first threshold to obtain the third single - channel image, and determine the gray - scale value F(x, y) of the third single - channel image:
[0104] F(x, y)= f(x, y) f(x, y)≥a l ;
[0105] Calculate the gray - scale average value M2 of the third single - channel image using the following formula:
[0106]
[0107] where R2 is the third single - channel image and n2 is the number of pixel points in the third single - channel image;
[0108] Calculate the gray - scale deviation d2 of the third single - channel image according to the gray - scale average value of the third single - channel image. The formula is as follows:
[0109]
[0110] Calculate the second threshold a according to the gray - scale average value and the gray - scale deviation of the third single - channel image h , the formula is as follows:
[0111] a h= M2 + k·d2。
[0112] In a specific embodiment, in the first single-channel image, the region where the gray value is distributed between the first threshold and the second threshold is the edge candidate region, the region where the gray value is less than the first threshold is the background region, and the region where the gray value is greater than the second threshold is the target region.
[0113] In a specific embodiment, in step S2, performing gray-scale transformation on the first single-channel image according to the first threshold and the second threshold specifically includes:
[0114] Performing gray-scale transformation on the first single-channel image using the following formula:
[0115]
[0116] where G(x, y) is the gray value of the pixel point (x, y) in the second single-channel image.
[0117] Specifically, after selecting the first single-channel image with the highest clarity among different channels of the image through the image clarity evaluation algorithm, taking the first single-channel image as the base image for gray-scale transformation, the key to gray-scale transformation is to determine the upper and lower limits of gray-scale transformation, that is, the first threshold and the second threshold of gray-scale transformation. The first threshold is the gray value at the boundary between the background region and the edge candidate region and the target region in the first single-channel image, and the second threshold is the gray value at the boundary between the edge candidate region and the target region. The first threshold and the second threshold of gray-scale transformation divide the first single-channel image into three regions: the background region, the edge candidate region, and the target region. After determining the edge candidate region, perform linear gray-scale transformation on it to achieve the purpose of enhancing edge contrast. The first threshold of gray-scale transformation is the boundary between the background region and the edge candidate region and the target region. The background region has a large area, and the gray average value and gray deviation of the first single-channel image can better reflect the distribution of gray values. Therefore, the first threshold of gray-scale transformation can be determined according to the gray average value of the first single-channel image plus the gray deviation multiplied by the deviation coefficient.
[0118] Further, after determining the first threshold of gray-scale transformation, using the first threshold of gray-scale transformation as the segmentation threshold to separate the background region from the edge candidate region and the target region, the third single-channel image containing only the edge candidate region and the target region in the first single-channel image can be obtained for subsequent operations. According to the characteristic that the gray value span of the edge candidate region is large, again use the gray average value of the third single-channel image plus the gray deviation multiplied by the deviation coefficient as the second threshold of gray-scale transformation to segment the edge candidate region.
[0119] After the above steps, the first threshold a of the edge candidate region can be determined l and the second threshold a h , and the first threshold al and the second threshold a h Using the upper and lower limits of the gray-scale transformation as the first single-channel image is gray-scale transformed. In the embodiments of the present application, gray-scale linear transformation can be used. In other embodiments, other transformation methods can also be used. If other transformation methods are used, they are also within the protection scope of the present invention. The gray-scale linear transformation evenly stretches the gray-scale values of the edge candidate regions distributed in [a l , a h to [0, 255], thereby improving the contrast of the edge candidate regions of the first single-channel image. For the gray-scale values of the background region and the target region, they are directly set to 0 and 255 respectively, effectively increasing the gray-scale difference between the target region and the background region and increasing the gray-scale gradient of the edge region.
[0120] S3. Adjust the deviation coefficient, repeat step S2, determine the second single-channel images corresponding to the gray-scale transformation of the first single-channel image under different deviation coefficients, and evaluate the second single-channel images corresponding to different deviation coefficients through an image sharpness evaluation algorithm to obtain the sharpness evaluation values corresponding to the second single-channel images obtained under different deviation coefficients.
[0121] In a specific embodiment, adjusting the deviation coefficient in step S3 specifically includes:
[0122] Gradually increasing from the third threshold to the fourth threshold at a preset step size.
[0123] Specifically, to make the effect of the linear transformation better, the deviation coefficient is adjusted through an image sharpness evaluation algorithm, further changing the first threshold and the second threshold of the gray-scale transformation to achieve the best effect. The deviation coefficient is usually set within the range of [0.6 - 2.4], with 0.6 as the initial value and 0.1 as the preset step size to adjust the deviation coefficient, and traverse and adjust the first threshold and the second threshold of the gray-scale transformation. Perform linear gray-scale transformation on the first single-channel image, and use the image sharpness evaluation algorithm in step S1 to evaluate the second single-channel image after the transformation to obtain the sharpness evaluation values corresponding to the second single-channel images obtained under different deviation coefficients.
[0124] S4. Determine the target image according to the sharpness evaluation values corresponding to the second single-channel images obtained under different deviation coefficients.
[0125] In a specific embodiment, step S4 specifically includes:
[0126] Normalize the sharpness evaluation values corresponding to the second single-channel images obtained under different deviation coefficients to obtain the normalized evaluation values;
[0127] Select the second single-channel image obtained under the deviation coefficient corresponding to the normalized evaluation value as the target image.
[0128] Specifically, the second single-channel image corresponding to the maximum value in the clarity evaluation value is taken as the target image. In practical applications, the image clarity evaluation curve obtained after normalization is as Figure 8 shown. The evaluation curve takes the deviation coefficient k value as the abscissa and the normalized evaluation value of the second single-channel image as the ordinate. There is a maximum value in this evaluation curve, and the overall trend on both sides of the maximum value is downward. From this, the deviation coefficient corresponding to the normalized evaluation value can be determined, and further, the second single-channel image obtained under the deviation coefficient corresponding to the normalized evaluation value is selected as the target image. This target image is as Figure 9 shown.
[0129] Further referring to Figure 10 , as an implementation of the methods shown in the above figures, an embodiment of an apparatus for enhancing the target edge of adaptive grayscale is provided in the present application. This apparatus embodiment corresponds to the Figure 2 method embodiment shown and can be specifically applied to various electronic devices.
[0130] An embodiment of the present application provides an apparatus for enhancing the target edge of adaptive grayscale, including the following steps:
[0131] An image acquisition module 1, configured to acquire an image, determine the first single-channel image with the highest clarity in different channels corresponding to the image through an image clarity evaluation algorithm, and set the deviation coefficient in the grayscale transformation process of the first single-channel image;
[0132] A grayscale transformation module 2, configured to determine a first threshold and a second threshold according to the deviation coefficient. Among them, the first threshold is the grayscale value at the boundary between the background area and the edge candidate area and the target area in the first single-channel image, and the second threshold is the grayscale value at the boundary between the edge candidate area and the target area. The first single-channel image is subjected to grayscale transformation according to the first threshold and the second threshold to obtain a second single-channel image;
[0133] An adjustment module 3, configured to adjust the deviation coefficient, repeatedly execute the grayscale transformation module, determine the second single-channel images corresponding to the grayscale transformation of the first single-channel image under different deviation coefficients, evaluate the second single-channel images corresponding to different deviation coefficients through an image clarity evaluation algorithm, and obtain the clarity evaluation values corresponding to the second single-channel images obtained under different deviation coefficients;
[0134] An output module 4, configured to determine the target image according to the clarity evaluation values corresponding to the second single-channel images obtained under different deviation coefficients.
[0135] Next, referring to Figure 11, which shows a schematic structural diagram of a computer device 1100 suitable for use in implementing the electronic device (such as the server or terminal device shown in Figure 1 ). The electronic device shown is merely an example and should not impose any limitation on the functions and usage scope of the embodiments of the present application. Figure 11 The electronic device shown is merely an example and should not impose any limitation on the functions and usage scope of the embodiments of the present application.
[0136] As Figure 11 shown, the computer device 1100 includes a central processing unit (CPU) 1101 and a graphics processing unit (GPU) 1102, which can perform various appropriate actions and processes according to the programs stored in the read-only memory (ROM) 1103 or the programs loaded from the storage section 1109 into the random access memory (RAM) 1104. In the RAM 1104, various programs and data required for the operation of the device 1100 are also stored. The CPU 1101, GPU 1102, ROM 1103, and RAM 1104 are connected to each other via a bus 1105. An input / output (I / O) interface 1106 is also connected to the bus 1105.
[0137] The following components are connected to the I / O interface 1106: an input section 1107 including a keyboard, a mouse, etc.; an output section 1108 including, for example, a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 1109 including a hard disk, etc.; and a communication section 1110 including a network interface card such as a LAN card, a modem, etc. The communication section 1110 performs communication processing via a network such as the Internet. A drive 1111 can also be connected to the I / O interface 1106 as needed. A removable medium 1112, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1111 as needed so that a computer program read from it can be installed into the storage section 1109 as needed.
[0138] Specifically, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product that includes a computer program carried on a computer-readable medium, and the computer program includes program codes for performing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1110, and / or installed from the removable medium 1112. When the computer program is executed by the central processing unit (CPU) 1101 and the graphics processing unit (GPU) 1102, the above-mentioned functions defined in the method of the present application are executed.
[0139] It should be noted that the computer-readable medium described in this application can be a computer-readable signal medium, a computer-readable medium, or any combination of the two. The computer-readable medium can be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor devices, apparatuses, or components, or any combination of the above. More specific examples of the computer-readable medium can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this application, the computer-readable medium can be any tangible medium that contains or stores a program, and this program can be used by or in combination with an instruction execution device, apparatus, or component. In this application, the computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, in which the computer-readable program code is carried. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer-readable signal medium can also be any computer-readable medium other than the computer-readable medium, and this computer-readable medium can send, propagate, or transmit a program for use by or in combination with an instruction execution device, apparatus, or component. The program code contained on the computer-readable medium can be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0140] The computer program code for performing the operations of this application can be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages - such as Java, Smalltalk, C++, and also include conventional procedural programming languages - such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, executed as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network - including a local area network (LAN) or a wide area network (WAN) - or, alternatively, can be connected to an external computer (for example, by using an Internet service provider to connect through the Internet).
[0141] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of apparatuses, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a part of code that contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based device that performs the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.
[0142] The modules described in the embodiments of the present application can be implemented in software or in hardware. The described modules can also be provided in a processor.
[0143] As another aspect, the present application also provides a computer-readable medium, which may be included in the electronic device described in the above embodiments; or may exist separately without being assembled into the electronic device. The above computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device is caused to: acquire an image, determine a first single-channel image with the highest clarity in different channels corresponding to the image through an image clarity evaluation algorithm, and set a deviation coefficient during the gray-scale transformation of the first single-channel image; determine a first threshold and a second threshold according to the deviation coefficient, where the first threshold is the gray-scale value at the boundary between the background region and the edge candidate region and the target region in the first single-channel image, and the second threshold is the gray-scale value at the boundary between the edge candidate region and the target region, and perform gray-scale transformation on the first single-channel image according to the first threshold and the second threshold to obtain a second single-channel image; adjust the deviation coefficient, repeat the above steps, determine the second single-channel images corresponding to the gray-scale transformation of the first single-channel image under different deviation coefficients, evaluate the second single-channel images corresponding to different deviation coefficients through the image clarity evaluation algorithm, and obtain the clarity evaluation values corresponding to the second single-channel images obtained under different deviation coefficients; determine a target image in the second single-channel image according to the clarity evaluation values corresponding to the second single-channel images obtained under different deviation coefficients.
[0144] The above description is only a preferred embodiment of the present application and an explanation of the applied technical principles. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by the specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above inventive concept. For example, a technical solution formed by mutually replacing the above features with technical features (but not limited to) having similar functions disclosed in the present application.
Claims
1. An object edge enhancement method for adaptive grayscale conversion, characterized in that, It includes the following steps: S1. Obtain an image, determine the first single-channel image with the highest clarity in different channels corresponding to the image through an image clarity evaluation algorithm, and set the deviation coefficient during the gray-scale transformation of the first single-channel image; S2. Determine a first threshold and a second threshold according to the deviation coefficient. Wherein, the first threshold is the gray-scale value at the boundary between the background area and the edge candidate area and the target area in the first single-channel image, and the second threshold is the gray-scale value at the boundary between the edge candidate area and the target area. Perform gray-scale transformation on the first single-channel image according to the first threshold and the second threshold to obtain a second single-channel image; S3. Adjust the deviation coefficient, repeat step S2, determine the second single-channel images corresponding to the gray-scale transformation of the first single-channel image under different deviation coefficients, evaluate the second single-channel images corresponding to different deviation coefficients through the image clarity evaluation algorithm, and obtain the clarity evaluation values corresponding to the second single-channel images obtained under different deviation coefficients; S4. Determine the target image in the second single-channel image according to the clarity evaluation values corresponding to the second single-channel images obtained under different deviation coefficients.
2. The target edge enhancement method for adaptive grayscale conversion according to claim 1, characterized in that The specific content of step S4 includes: Normalize the clarity evaluation values corresponding to the second single-channel images obtained under different deviation coefficients to obtain the normalized evaluation values; Select the second single-channel image obtained under the deviation coefficient corresponding to the normalized evaluation value as the target image.
3. The target edge enhancement method for adaptive grayscale conversion according to claim 1, characterized in that In the first single-channel image, the area where the gray-scale value is between the first threshold and the second threshold is the edge candidate area, the area where the gray-scale value is less than the first threshold is the background area, and the area where the gray-scale value is greater than the second threshold is the target area.
4. The target edge enhancement method for adaptive grayscale conversion according to claim 1, characterized in that In step S2, determining the first threshold and the second threshold according to the deviation coefficient specifically includes: Calculate the gray-scale average value M1 of the first single-channel image using the following formula: Wherein, R1 is the first single-channel image, (x, y) is the coordinate of the pixel point, f(x, y) is the gray-scale value of the pixel point (x, y) in the first single-channel image, and n1 is the number of pixel points in the first single-channel image; Calculate the gray-scale deviation d1 of the first single-channel image according to the gray-scale average value of the first single-channel image. The formula is as follows: Calculate the first threshold value a based on the average gray level and gray level deviation of the first single-channel image l , and the formula is as follows: a l = M1 + k·d1; Wherein, k is the deviation coefficient; Separate the background area and the edge candidate area and the target area in the first single-channel image according to the first threshold to obtain a third single-channel image, and determine the gray-scale value F(x, y) of the third single-channel image; F(x, y) = f(x, y) where f(x, y) ≥ a l ; Calculate the gray-scale average value M2 of the third single-channel image using the following formula: Wherein, R2 is the third single-channel image, and n2 is the number of pixel points in the third single-channel image; Calculate the gray-scale deviation d2 of the third single-channel image according to the gray-scale average value of the third single-channel image. The formula is as follows: Calculate the second threshold a according to the gray average value and gray deviation of the third single-channel image h , and the formula is as follows: a h = M2 + k·d2.
5. The target edge enhancement method for adaptive grayscale conversion according to claim 4, characterized in that In step S2, performing gray-scale transformation on the first single-channel image according to the first threshold and the second threshold specifically includes: The gray-scale transformation is performed on the first single-channel image using the following formula: where G(x, y) is the gray-scale value of the pixel point (x, y) in the second single-channel image.
6. The target edge enhancement method for adaptive grayscale conversion according to claim 1, characterized in that, The range of the deviation coefficient is between a third threshold and a fourth threshold, and the deviation coefficient is set to the third threshold in the step S1; In the step S3, adjusting the deviation coefficient specifically includes: successively increasing from the third threshold to the fourth threshold at a preset step size.
7. The target edge enhancement method for adaptive grayscale conversion according to claim 1, wherein In the step S1, determining the first single-channel image with the highest clarity among different channels corresponding to the image through an image clarity evaluation algorithm specifically includes: splitting the image into a plurality of fourth single-channel images according to a plurality of channels; performing denoising on the plurality of fourth single-channel images using median filtering to obtain fifth single-channel images; evaluating the fifth single-channel images through the image clarity evaluation algorithm to obtain the clarity evaluation values of the fifth single-channel images, and the formula is as follows: G x = f(x + 2, y) - f(x, y); G y = f(x, y + 2) - f(x, y); G xy = |f(x,y) - f(x + 1,y + 1)| + |f(x + 1,y) - f(x,y + 1)|; F = G x ·G y ·G xy ; Among them, G x is the gradient information of the fifth single-channel image in the x direction, G y is the gradient information of the fifth single-channel image in the y direction, G xy is the gradient information of the fifth single-channel image in the ±45° direction, F is the clarity evaluation value, and f(x, y) is the gray value of the pixel point (x, y) in the fifth single-channel image; selecting the fifth single-channel image corresponding to the maximum clarity evaluation value as the first single-channel image.
8. An object edge enhancement device for adaptive grayscale conversion, characterized in that, including the following steps: An image acquisition module, configured to acquire an image, determine the first single-channel image with the highest clarity among different channels corresponding to the image through an image clarity evaluation algorithm, and set the deviation coefficient in the process of gray-scale transformation of the first single-channel image; A gray-scale transformation module, configured to determine a first threshold and a second threshold according to the deviation coefficient, where the first threshold is the gray-scale value at the boundary between the background region and the edge candidate region and the target region in the first single-channel image, and the second threshold is the gray-scale value at the boundary between the edge candidate region and the target region, and perform gray-scale transformation on the first single-channel image according to the first threshold and the second threshold to obtain a second single-channel image; An adjustment module, configured to adjust the deviation coefficient, repeatedly execute the gray-scale transformation module, determine the second single-channel images corresponding to the gray-scale transformation of the first single-channel image under different deviation coefficients, evaluate the second single-channel images corresponding to different deviation coefficients through the image clarity evaluation algorithm, and obtain the clarity evaluation values corresponding to the second single-channel images obtained under different deviation coefficients; An output module, configured to determine a target image according to the clarity evaluation values corresponding to the second single-channel images obtained under different deviation coefficients.
9. An electronic device, comprising: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, enabling the one or more processors to implement the method according to any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method according to any one of claims 1-7.