Image clarity calculation method, device and computer equipment
Through the combination of image size normalization, Canny operator, and local dynamic binarization algorithm, image edge points are extracted, and their intersection and union are calculated to calculate image sharpness, which solves the problem of inconsistent image blur detection results and realizes image The scene and device consistency of definition calculation are suitable for a variety of application scenarios.
Patent Information
- Application Number
- CN202011511194.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-18
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2040-12-18
AI Technical Summary
Existing image blur detection algorithms cannot ensure the consistency of measurement results in different scenarios, resulting in inconsistent image sharpness calculation results and difficulty in applying to various business scenarios.
By obtaining the image to be analyzed, determine and normalize its size to a preset size, convert it into a grayscale image, use the Canny operator and local dynamic binarization algorithm to extract edge points, and calculate the intersection and union of edge points to calculate the image Clarity.
It achieves consistency of image definition calculation and device consistency in different scenarios, expands the industrial application field of image definition, reduces the amount of calculation, and is suitable for embedded devices and large-scale deployment.
Smart Images

Figure CN112561890B
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a method, device and computer equipment for calculating image clarity. Background Art
[0002] Image blur calculation has applications in many fields, and its application in intelligent security operation and maintenance is even more urgent. However, the robustness of existing judgment methods based on image processing needs to be improved, and most of the existing image blur detection algorithms cannot guarantee the consistency of measurement results in multiple scenarios. The inconsistency of image blur calculation results has brought considerable difficulties to the promotion and application of algorithms. Because the simple blur does not have application value, comparing the clarity of two images and judging whether they are clear or not is what is needed in the application. The blur values in different scenarios cannot be divided by a unified threshold and cannot be uniformly applied to various business scenarios. Summary of the invention
[0003] The main purpose of this application is to provide image clarity calculation, aiming to solve the technical problem that the image clarity calculation results in different business scenarios are not universal.
[0004] This application proposes a method for calculating image clarity, including:
[0005] Acquire an image to be analyzed;
[0006] Determining whether the image size of the image to be analyzed is consistent with a preset size;
[0007] If not, normalizing the image size of the image to be analyzed to be consistent with the preset size;
[0008] Convert the image to be analyzed after image size normalization into a grayscale image;
[0009] Extracting edge points of the grayscale image respectively by using a Canny operator and a local dynamic binarization algorithm;
[0010] The image clarity is calculated based on the intersection and union of edge points extracted by the Canny operator and the local dynamic binarization algorithm respectively.
[0011] Preferably, the step of normalizing the image size of the image to be analyzed to be consistent with the preset size includes:
[0012] Get the resolution value to be compatible;
[0013] Calculate the average resolution corresponding to the resolution value to be compatible;
[0014] Determine a preset height value and a preset width value corresponding to the preset size according to the mean resolution;
[0015] The height of the image to be analyzed is scaled to the preset height value, and the width of the image to be analyzed is scaled to the preset width value.
[0016] Preferably, the step of respectively extracting edge points of the grayscale image by using a Canny operator and a local dynamic binarization algorithm comprises:
[0017] Extract edge points of the grayscale image using a Canny operator to obtain a first edge point set;
[0018] Processing the grayscale image by a local dynamic binarization algorithm to obtain a binary grayscale image, wherein the binary grayscale image includes 1 and 0, marking pixels in the grayscale image whose pixel values are greater than a preset threshold as 1, and marking pixels whose pixel values are less than or equal to the preset threshold as 0;
[0019] The pixels marked as 1 in the binary grayscale image are combined into a pixel set;
[0020] The edge points of the grayscale image are determined according to the intersection of the first edge point set and the pixel point set.
[0021] Preferably, the step of extracting edge points of the grayscale image by using a Canny operator to obtain a first edge point set includes:
[0022] Smoothing the grayscale image by accumulating pixel values;
[0023] Calculating the gradient amplitude and gradient direction of the smoothed grayscale image by first-order partial derivative finite difference;
[0024] Performing non-maximum suppression on the gradient amplitude to obtain a suppressed gradient amplitude;
[0025] The first edge point set is determined according to the gradient magnitude after suppression and the gradient magnitude before suppression.
[0026] Preferably, the step of smoothing the grayscale image by accumulating pixel values comprises:
[0027] Determine a specified number of adjacent pixel points adjacent to a specified pixel point, wherein the specified pixel point is any pixel point in the grayscale image;
[0028] Calculating the pixel value difference between each of the adjacent pixel points and the designated pixel point respectively;
[0029] Determine the minimum value of the absolute values of the pixel value differences;
[0030] Multiply the minimum value of the absolute value by a specified multiple to obtain a smoothed pixel value, wherein the specified multiple belongs to the interval (0, 1);
[0031] Accumulating the smoothed pixel values with the original pixel values in the grayscale image to obtain corrected pixel values of the grayscale image;
[0032] The corrected pixel values are stored in the blank image at pixel positions corresponding to the original pixel values in a one-to-one correspondence with the original pixel values, so as to obtain the smoothed grayscale image.
[0033] Preferably, the step of calculating the image clarity according to the intersection and union of edge points extracted by the Canny operator and the local dynamic binarization algorithm respectively comprises:
[0034] Calculating a union of the first edge point set and the pixel point set;
[0035] Calculating an intersection-and-union ratio according to an intersection of the first edge point set and the pixel point set, and a union of the first edge point set and the pixel point set;
[0036] The I / O ratio is converted into a percentage as the clarity of the image to be analyzed.
[0037] The present application also provides a device for calculating image clarity, comprising:
[0038] An acquisition module, used for acquiring an image to be analyzed;
[0039] A judging module, used to judge whether the image size of the image to be analyzed is consistent with a preset size;
[0040] A normalization module, used for normalizing the image size of the image to be analyzed to be consistent with the preset size if it is not consistent with the preset size;
[0041] A conversion module, used for converting the image to be analyzed after the image size normalization process into a grayscale image;
[0042] An extraction module, used to extract edge points of the grayscale image respectively by using a Canny operator and a local dynamic binarization algorithm;
[0043] The calculation module is used to calculate the image clarity according to the intersection and union of edge points extracted by the Canny operator and the local dynamic binarization algorithm respectively.
[0044] The present application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0045] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented.
[0046] This application normalizes the image size to normalize all the images to be analyzed to the same size to ensure that the image clarity calculation is performed at the same resolution to adapt to images obtained in different scenes and with different shooting devices. The image clarity can be evaluated by the same evaluation standard, thereby expanding the industrial application field and evaluation accuracy of image clarity. There is no need to use a reference image as a standard, and the application has good scene consistency and device consistency. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 A schematic diagram of a method for calculating image clarity according to an embodiment of the present application;
[0048] Figure 2 A schematic diagram of a system flow chart for calculating image clarity according to an embodiment of the present application;
[0049] Figure 3 A schematic diagram of the internal structure of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0051] Reference Figure 1 , a method for calculating image clarity according to an embodiment of the present application includes:
[0052] S1: Acquire the image to be analyzed;
[0053] S2: Determine whether the image size of the image to be analyzed is consistent with a preset size;
[0054] S3: If not, normalizing the image size of the image to be analyzed to be consistent with the preset size;
[0055] S4: converting the image to be analyzed after the image size normalization process into a grayscale image;
[0056] S5: extracting edge points of the grayscale image respectively by using a Canny operator and a local dynamic binarization algorithm;
[0057] S6: Calculate the image clarity according to the intersection and union of the edge points extracted by the Canny operator and the local dynamic binarization algorithm respectively.
[0058] This application uses image size normalization processing to normalize all images to be analyzed to the same size to ensure that image clarity calculation is performed at the same resolution to adapt to images obtained in different scenes and different shooting devices. Image clarity can be evaluated by the same evaluation standard, expanding the industrial application field and evaluation accuracy of image clarity, and no reference image is required as a standard, with good scene consistency and device consistency. The above-mentioned image size normalization method includes but is not limited to proportional scaling, or normalization of image size by mapping pixels to blank files of the same size.
[0059] In order to reduce the amount of calculation, this application calculates the clarity of the edge points of the image as the clarity of the entire image. Because edge points are an important component of the image, and the clarity of the edge and the clarity of the image complement each other. By extracting edge points and calculating the clarity of the edge lines connected by all edge points as the image clarity, the amount of calculation is small, which is convenient for deployment in embedded devices or applied to application scenarios that require large-scale deployment.
[0060] Furthermore, the step S3 of normalizing the image size of the image to be analyzed to be consistent with the preset size includes:
[0061] S31: Obtaining a resolution value to be compatible;
[0062] S32: Calculate the average resolution corresponding to the resolution value to be compatible;
[0063] S33: Determine a preset height value and a preset width value corresponding to the preset size according to the mean resolution;
[0064] S34: scaling the height of the image to be analyzed to the preset height value, and scaling the width of the image to be analyzed to the preset width value.
[0065] The preset size of the embodiment of the present application is obtained by statistically analyzing the average values of each resolution type that needs to be compatible, so as to improve the compatibility with different resolutions. For example, the average value is obtained by adding up the sum of all resolutions and then dividing it by the resolution type. Or different weights are set according to the frequency of use of each resolution in different scenes. For example, the weight of high usage frequency is greater than the weight of low usage frequency, and the sum of the weights corresponding to all resolution types is equal to 1. Then, each resolution is multiplied by the weight corresponding to each resolution, and then the sum is divided by the resolution type to obtain the weighted resolution average. Other embodiments of the present application may also set the preset size to a suitable fixed size.
[0066] Furthermore, the step S5 of respectively extracting edge points of the grayscale image by using the Canny operator and the local dynamic binarization algorithm comprises:
[0067] S51: extracting edge points of the grayscale image by using a Canny operator to obtain a first edge point set;
[0068] S52: Processing the grayscale image by a local dynamic binarization algorithm to obtain a binary grayscale image, wherein the binary grayscale image includes 1 and 0, marking pixels in the grayscale image whose pixel values are greater than a preset threshold as 1, and marking pixels whose pixel values are less than or equal to the preset threshold as 0;
[0069] S53: Pixel points marked as 1 in the binary grayscale image are combined into a pixel point set;
[0070] S54: Determine edge points of the grayscale image according to the intersection of the first edge point set and the pixel point set.
[0071] The embodiment of the present application locates edge points by using the Canny operator and the local dynamic binarization algorithm. If the image clarity is high, the edge points extracted by the above two algorithms are close to the same, and the difference is small. On the contrary, if the image clarity is low, the above two different algorithms locate the edge points, and different results with large differences will be obtained. By extracting edge points by two or more algorithms, the stability of the edge points is improved, and the robustness of the image clarity calculation method is improved. Taking into account the amount of calculation, fast feedback, and accuracy, the present application compromises and chooses to extract edge points by using the Canny operator and the local dynamic binarization algorithm, and uses the intersection of the edge points obtained by the two methods as the final edge point set.
[0072] The process of local adaptive dynamic binarization in the embodiment of the present application is exemplified as follows: first, the image is filtered; then a sliding window with a size of w*h is selected to binarize the image; the mean a of the original grayscale image in the sliding window is calculated; (ak 4 ) as the local threshold, and binarize the pixel point falling in the center of the sliding window. If the pixel value of the original grayscale image falling in the center of the sliding window is greater than (ak 4 ) then the corresponding position in the copy of the original grayscale image is set to 1, otherwise it is set to 0. The above w and h are calculated by the window size coefficient K 3 , multiplied by the default original window size w 0 and h 0 Then we get a sliding window with a width of w and a height of h, such as K 3 is 0.05. 4 ) is represented as a dynamic threshold, which is calculated by subtracting a constant k from the mean pixel value in the sliding window. 4 We get the constant k 4 The empirical value of is 0.2 times the global mean, where the global mean refers to the mean of the pixel values of the original grayscale image.
[0073] Furthermore, the step S51 of extracting edge points of the grayscale image by using a Canny operator to obtain a first edge point set includes:
[0074] S511: smoothing the grayscale image by accumulating pixel values;
[0075] S512: Calculate the gradient amplitude and gradient direction of the smoothed grayscale image through first-order partial derivative finite difference;
[0076] S513: performing non-maximum suppression on the gradient amplitude to obtain a suppressed gradient amplitude;
[0077] S514: Determine the first edge point set according to the gradient amplitude after suppression and the gradient amplitude before suppression.
[0078] In the process of extracting the edge points of the grayscale image by the Canny operator, the smoothing process of the image is improved, the image is smoothed by pixel superposition, the original Gaussian blur smoothing process is abandoned, and the abstract deformation of the original edge in the Gaussian blur smoothing process is avoided. The image is smoothed by pixel superposition, and the original existence state of the original edge points is retained, which is more in line with the technical requirements of the application for accurately determining the edge points, making the calculation of the image clarity value through the edge points more reliable and accurate.
[0079] The Canny operator function is expressed as: void cv Canny (const CvArr*image, CvArr*edges, double threshold1, double threshold2, int aperture_size=3). The parameter CvArr*image represents the input image, which must be a single-channel grayscale image. The parameter CvArr*edges represents the output edge image, which is a single-channel black and white image. The parameters double threshold1 and double threshold2 represent the thresholds. The smaller threshold of the two thresholds is used to control edge connection, and the larger threshold is used to control the initial segmentation of the edge. That is, if the gradient amplitude of a pixel is greater than the upper threshold, it is considered to be an edge pixel. If it is less than the lower threshold, it is discarded. If the gradient amplitude of the point is between the two, it is retained only when the point is connected to a pixel point higher than the upper threshold, otherwise it is deleted. The parameter intaperture_size represents the size of the Sobel operator. The default value is 3, which means a 3*3 matrix.
[0080] In the embodiment of the present application, the lower limit threshold is set to K 1 times the mean, the upper threshold is set to K 2 times the mean, K2 Greater than k 1 Preferably, the present application determines K based on experimental verification. 2 =1.6, K 1 When =0.6, the best effect is achieved by smoothing the grayscale image by accumulating pixel values to obtain edge points.
[0081] Furthermore, the step S511 of smoothing the grayscale image by accumulating pixel values includes:
[0082] S5111: Determine a specified number of adjacent pixel points adjacent to a specified pixel point, wherein the specified pixel point is any pixel point in the grayscale image;
[0083] S5112: Calculate the pixel value difference between each of the adjacent pixel points and the designated pixel point respectively;
[0084] S5113: Determine the minimum value of the absolute values of the pixel value differences;
[0085] S5114: multiplying the minimum value of the absolute value by a specified multiple to obtain a smoothed pixel value, wherein the specified multiple belongs to the interval (0, 1);
[0086] S5115: Accumulating the smoothed pixel values with the original pixel values in the grayscale image to obtain corrected pixel values of the grayscale image;
[0087] S5116: The corrected pixel values are stored in the blank image at pixel positions corresponding to the original pixel values in a one-to-one correspondence with the original pixel values, to obtain the smoothed grayscale image.
[0088] In the embodiment of the present application, before smoothing by pixel value superposition, a suitable smooth pixel value for superposition is first determined. For example, a specified number of adjacent pixels adjacent to any pixel point is determined, such as a specified number of 8, to obtain the pixel values of all pixels around the pixel point, so as to reduce the inaccurate defects of the pixel value of any pixel point due to other factors. By comparing the pixel value of the pixel point with the pixel value of the surrounding pixels adjacent to it, the difference of the pixel value to be smoothed is obtained, and then the minimum value of the absolute value of the difference is multiplied by the specified multiple to obtain the smoothed pixel value. The specified multiple belongs to the (0,1) interval, and experiments have shown that 0.5 times is the best. Since the attribution of the target pixel point to be smoothed is undetermined, according to similarity clustering, the pixel value with the smallest difference should be a class, which can restrict each other, so the minimum value of the absolute value of the difference is selected as the smoothing factor. For example, the pixel value of the current pixel point may contain noise, which is the noise added on the basis of the true value. Compared with the unknown pixel value, the true value plus another noise value is more likely to be the closest to him, so as to achieve smoothing. Then, the smoothed pixel values are added to the original pixel values on the blank image according to the one-to-one correspondence of the pixel positions to form a grayscale image, which is the smoothed grayscale image.
[0089] Furthermore, the step S6 of calculating the image clarity according to the intersection and union of edge points respectively extracted by the Canny operator and the local dynamic binarization algorithm comprises:
[0090] S61: Calculate the union of the first edge point set and the pixel point set;
[0091] S62: calculating an intersection-and-union ratio according to an intersection of the first edge point set and the pixel point set, and a union of the first edge point set and the pixel point set;
[0092] S63: Convert the intersection-over-union ratio into a percentage as the clarity of the image to be analyzed.
[0093] This application is approved by Calculate the intersection-over-union ratio, where P 1 ={(x,y)|C 1 (x,y)=1},P 2 ={(x,y)|C 2 (x,y)=1},P 1 represents the first edge point set, C 1 Represents the binary image of the grayscale image processed by the Canny operator, P 2 represents a set of pixels, C 2 Represents a grayscale image processed by local adaptive dynamic binarization, (x, y) represents a pixel, and 1 represents the binary value assigned to the pixel.
[0094] Reference Figure 2 , a device for calculating image clarity according to an embodiment of the present application includes:
[0095] An acquisition module 1 is used to acquire an image to be analyzed;
[0096] A judgment module 2 is used to judge whether the image size of the image to be analyzed is consistent with a preset size;
[0097] A normalization module 3 is used to normalize the image size of the image to be analyzed to be consistent with the preset size if it is not consistent with the preset size;
[0098] The conversion module 4 is used to convert the image to be analyzed after the image size normalization process into a grayscale image;
[0099] An extraction module 5 is used to extract edge points of the grayscale image respectively by using a Canny operator and a local dynamic binarization algorithm;
[0100] The calculation module 6 is used to calculate the image clarity according to the intersection and union of edge points extracted by the Canny operator and the local dynamic binarization algorithm respectively.
[0101] This application uses image size normalization processing to normalize all images to be analyzed to the same size to ensure that image clarity calculation is performed at the same resolution to adapt to images obtained in different scenes and different shooting devices. Image clarity can be evaluated by the same evaluation standard, expanding the industrial application field and evaluation accuracy of image clarity, and no reference image is required as a standard, with good scene consistency and device consistency. The above-mentioned image size normalization method includes but is not limited to proportional scaling, or normalization of image size by mapping pixels to blank files of the same size.
[0102] In order to reduce the amount of calculation, this application calculates the clarity of the edge points of the image as the clarity of the entire image. Because edge points are an important component of the image, and the clarity of the edge and the clarity of the image complement each other. By extracting edge points and calculating the clarity of the edge lines connected by all edge points as the image clarity, the amount of calculation is small, which is convenient for deployment in embedded devices or applied to application scenarios that require large-scale deployment.
[0103] Furthermore, the normalization module 3 comprises:
[0104] The acquisition submodule is used to obtain the resolution value to be compatible;
[0105] A first calculation submodule, used for calculating the average resolution corresponding to the resolution value to be compatible;
[0106] A first determination submodule, configured to determine a preset height value and a preset width value corresponding to the preset size according to the mean resolution;
[0107] The scaling submodule is used to scale the height of the image to be analyzed to the preset height value, and scale the width of the image to be analyzed to the preset width value.
[0108] The preset size of the embodiment of the present application is obtained by statistically analyzing the average values of each resolution type that needs to be compatible, so as to improve the compatibility with different resolutions. For example, the average value is obtained by adding up the sum of all resolutions and then dividing it by the resolution type. Or different weights are set according to the frequency of use of each resolution in different scenes. For example, the weight of high usage frequency is greater than the weight of low usage frequency, and the sum of the weights corresponding to all resolution types is equal to 1. Then, each resolution is multiplied by the weight corresponding to each resolution, and then the sum is divided by the resolution type to obtain the weighted resolution average. Other embodiments of the present application may also set the preset size to a suitable fixed size.
[0109] Furthermore, the extraction module 5 comprises:
[0110] An extraction submodule, configured to extract edge points of the grayscale image by using a Canny operator to obtain a first edge point set;
[0111] A processing submodule, configured to process the grayscale image by a local dynamic binarization algorithm to obtain a binary grayscale image, wherein the binary grayscale image includes 1 and 0, and pixels in the grayscale image whose pixel values are greater than a preset threshold are marked as 1, and pixels whose pixel values are less than or equal to the preset threshold are marked as 0;
[0112] A marking submodule, used for forming a pixel set by marking the pixel points marked as 1 in the binary grayscale image;
[0113] The second determining submodule is used to determine the edge points of the grayscale image according to the intersection of the first edge point set and the pixel point set.
[0114] The embodiment of the present application locates edge points by using the Canny operator and the local dynamic binarization algorithm. If the image clarity is high, the edge points extracted by the above two algorithms are close to the same, and the difference is small. On the contrary, if the image clarity is low, the above two different algorithms locate the edge points, and different results with large differences will be obtained. By extracting edge points by two or more algorithms, the stability of the edge points is improved, and the robustness of the image clarity calculation method is improved. Taking into account the amount of calculation, fast feedback, and accuracy, the present application compromises and chooses to extract edge points by using the Canny operator and the local dynamic binarization algorithm, and uses the intersection of the edge points obtained by the two methods as the final edge point set.
[0115] The process of local adaptive dynamic binarization in the embodiment of the present application is exemplified as follows: first, the image is filtered; then a sliding window with a size of w*h is selected to binarize the image; the mean a of the original grayscale image in the sliding window is calculated; (ak 4 ) as the local threshold, and binarize the pixel point falling in the center of the sliding window. If the pixel value of the original grayscale image falling in the center of the sliding window is greater than (ak 4 ) then the corresponding position in the copy of the original grayscale image is set to 1, otherwise it is set to 0. The above w and h are calculated by the window size coefficient K 3 , multiplied by the default original window size w 0 and h 0 Then we get a sliding window with a width of w and a height of h, such as K 3 is 0.05. 4 ) is represented as a dynamic threshold, which is calculated by subtracting a constant k from the mean pixel value in the sliding window. 4 We get the constant k 4 The empirical value of is 0.2 times the global mean, where the global mean refers to the mean of the pixel values of the original grayscale image.
[0116] Furthermore, the submodules are extracted, including:
[0117] A smoothing unit, used for smoothing the grayscale image by accumulating pixel values;
[0118] A calculation unit, used for calculating the gradient amplitude and gradient direction of the smoothed grayscale image through first-order partial derivative finite difference;
[0119] A suppression unit, used for performing non-maximum suppression on the gradient amplitude to obtain a suppressed gradient amplitude;
[0120] A determining unit is used to determine the first edge point set according to the gradient amplitude after suppression and the gradient amplitude before suppression.
[0121] In the process of extracting the edge points of the grayscale image by the Canny operator, the smoothing process of the image is improved, the image is smoothed by pixel superposition, the original Gaussian blur smoothing process is abandoned, and the abstract deformation of the original edge in the Gaussian blur smoothing process is avoided. The image is smoothed by pixel superposition, and the original existence state of the original edge points is retained, which is more in line with the technical requirements of the application for accurately determining the edge points, making the calculation of the image clarity value through the edge points more reliable and accurate.
[0122] The Canny operator function is expressed as: void cv Canny (const CvArr*image, CvArr*edges, double threshold1, double threshold2, int aperture_size=3). The parameter CvArr*image represents the input image, which must be a single-channel grayscale image. The parameter CvArr*edges represents the output edge image, which is a single-channel black and white image. The parameters double threshold1 and double threshold2 represent the thresholds. The smaller threshold of the two thresholds is used to control edge connection, and the larger threshold is used to control the initial segmentation of the edge. That is, if the gradient amplitude of a pixel is greater than the upper threshold, it is considered to be an edge pixel. If it is less than the lower threshold, it is discarded. If the gradient amplitude of the point is between the two, it is retained only when the point is connected to a pixel point higher than the upper threshold, otherwise it is deleted. The parameter intaperture_size represents the size of the Sobel operator. The default value is 3, which means a 3*3 matrix.
[0123] In the embodiment of the present application, the lower limit threshold is set to K 1 times the mean, the upper threshold is set to K 2 times the mean, K 2 Greater than k 1 Preferably, the present application determines K based on experimental verification. 2 =1.6, K 1 When =0.6, the best effect is achieved by smoothing the grayscale image by accumulating pixel values to obtain edge points.
[0124] Furthermore, the smoothing unit comprises:
[0125] A first determining subunit is used to determine a specified number of adjacent pixel points adjacent to a specified pixel point, wherein the specified pixel point is any pixel point in the grayscale image;
[0126] A calculation subunit, used to calculate the pixel value difference between each of the adjacent pixel points and the designated pixel point;
[0127] A second determining subunit is used to determine the minimum value of the absolute values of the pixel value differences;
[0128] Obtain a subunit, which is used to multiply the minimum value of the absolute value by a specified multiple to obtain a smoothed pixel value, wherein the specified multiple belongs to the interval (0,1);
[0129] Accumulation subunit: accumulating the smoothed pixel value with each original pixel value in the grayscale image to obtain a corrected pixel value of the grayscale image;
[0130] Storage subunit: stores the corrected pixel values in the blank image at pixel positions corresponding to the original pixel values in a one-to-one correspondence with the original pixel values, to obtain the smoothed grayscale image.
[0131] In the embodiment of the present application, before smoothing by pixel value superposition, a suitable smooth pixel value for superposition is first determined. For example, a specified number of adjacent pixels adjacent to any pixel point is determined, such as a specified number of 8, to obtain the pixel values of all pixels around the pixel point, so as to reduce the inaccurate defects of the pixel value of any pixel point due to other factors. By comparing the pixel value of the pixel point with the pixel value of the surrounding pixels adjacent to it, the difference of the pixel value to be smoothed is obtained, and then the minimum value of the absolute value of the difference is multiplied by the specified multiple to obtain the smoothed pixel value. The specified multiple belongs to the (0,1) interval, and experiments have shown that 0.5 times is the best. Since the attribution of the target pixel point to be smoothed is undetermined, according to similarity clustering, the pixel value with the smallest difference should be a class, which can restrict each other, so the minimum value of the absolute value of the difference is selected as the smoothing factor. For example, the pixel value of the current pixel point may contain noise, which is the noise added on the basis of the true value. Compared with the unknown pixel value, the true value plus another noise value is more likely to be the closest to him, so as to achieve smoothing. Then, the smoothed pixel values are added to the original pixel values on the blank image according to the one-to-one correspondence of the pixel positions to form a grayscale image, which is the smoothed grayscale image.
[0132] Furthermore, the calculation module 6 includes:
[0133] A second calculation submodule, used to calculate the union of the first edge point set and the pixel point set;
[0134] a third calculation submodule, configured to calculate an intersection-and-union ratio according to an intersection of the first edge point set and the pixel point set, and a union of the first edge point set and the pixel point set;
[0135] As a submodule, it is used to convert the intersection-and-union ratio into a percentage as the clarity of the image to be analyzed.
[0136] This application is approved by Calculate the intersection-over-union ratio, where P 1 ={(x,y)|C 1 (x,y)=1},P 2 ={(x,y)|C 2 (x,y)=1},P 1 represents the first edge point set, C 1 Represents the binary image of the grayscale image processed by the Canny operator, P 2 represents a set of pixels, C2 Represents a grayscale image processed by local adaptive dynamic binarization, (x, y) represents a pixel, and 1 represents the binary value assigned to the pixel.
[0137] Reference Figure 3 In an embodiment of the present application, a computer device is also provided. The computer device may be a server, and its internal structure may be as follows: Figure 3 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor designed by the computer is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store all data required for the calculation process of image clarity. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the method for calculating image clarity is implemented.
[0138] The above-mentioned processor executes the above-mentioned method for calculating the image clarity, including: obtaining the image to be analyzed; determining whether the image size of the image to be analyzed is consistent with a preset size; if not, normalizing the image size of the image to be analyzed to be consistent with the preset size; converting the image to be analyzed after the image size normalization process into a grayscale image; extracting edge points of the grayscale image respectively through the Canny operator and the local dynamic binarization algorithm; and calculating the image clarity according to the intersection and union of the edge points respectively extracted by the Canny operator and the local dynamic binarization algorithm.
[0139] The above-mentioned computer device normalizes all the images to be analyzed to the same size through image size normalization to ensure that the image clarity calculation is performed at the same resolution to adapt to images obtained in different scenes and different shooting devices. The image clarity can be evaluated by the same evaluation standard, thereby expanding the industrial application field and evaluation accuracy of image clarity. There is no need to use a reference image as a standard, and the device has good scene consistency and device consistency.
[0140] In one embodiment, the processor normalizes the image size of the image to be analyzed to be consistent with the preset size, including: obtaining a resolution value to be compatible; calculating a mean resolution corresponding to the resolution value to be compatible; determining a preset height value and a preset width value corresponding to the preset size according to the mean resolution; scaling the height of the image to be analyzed to the preset height value, and scaling the width of the image to be analyzed to the preset width value.
[0141] In one embodiment, the processor extracts edge points of the grayscale image by using the Canny operator and the local dynamic binarization algorithm, respectively, including: extracting edge points of the grayscale image by using the Canny operator to obtain a first edge point set; processing the grayscale image by using the local dynamic binarization algorithm to obtain a binary grayscale image, wherein the binary grayscale image includes 1 and 0, marking pixels in the grayscale image whose pixel values are greater than a preset threshold as 1, and marking pixels whose pixel values are less than or equal to the preset threshold as 0; forming a pixel point set with pixels marked as 1 in the binary grayscale image; and determining the edge points of the grayscale image according to the intersection of the first edge point set and the pixel point set.
[0142] In one embodiment, the processor extracts edge points of the grayscale image through the Canny operator to obtain a step of a first edge point set, including: smoothing the grayscale image by accumulating pixel values; calculating the gradient amplitude and gradient direction of the smoothed grayscale image through first-order partial derivative finite difference; performing non-maximum suppression on the gradient amplitude to obtain a suppressed gradient amplitude; and determining the first edge point set based on the suppressed gradient amplitude and the gradient amplitude before suppression.
[0143] In one embodiment, the processor smoothes the grayscale image by accumulating pixel values, including: determining a specified number of adjacent pixel points adjacent to a specified pixel point, wherein the specified pixel point is any pixel point in the grayscale image; respectively calculating the pixel value difference between each of the adjacent pixel points and the specified pixel point; determining the minimum of the absolute values of each of the pixel value differences; multiplying the minimum of the absolute values by a specified multiple to obtain a smoothed pixel value, wherein the specified multiple belongs to the interval (0,1); accumulating the smoothed pixel values with the original pixel values in the grayscale image to obtain corrected pixel values of the grayscale image; storing the corrected pixel values at pixel positions corresponding to the original pixel values in the blank image in a one-to-one correspondence with the original pixel values to obtain the smoothed grayscale image.
[0144] In one embodiment, the processor calculates the image clarity based on the intersection and union of edge points extracted by the Canny operator and the local dynamic binarization algorithm, respectively, comprising: calculating the union of the first edge point set and the pixel point set; calculating the intersection-and-union ratio based on the intersection of the first edge point set and the pixel point set, and the union of the first edge point set and the pixel point set; and converting the intersection-and-union ratio into a percentage as the clarity of the image to be analyzed.
[0145] Those skilled in the art will understand that Figure 3The structure shown in is merely a block diagram of a portion of the structure related to the present application solution and does not constitute a limitation on the computer device to which the present application solution is applied.
[0146] An embodiment of the present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, a method for calculating image clarity is implemented, including: acquiring an image to be analyzed; determining whether the image size of the image to be analyzed is consistent with a preset size; if not, normalizing the image size of the image to be analyzed to be consistent with the preset size; converting the image to be analyzed after the image size normalization process into a grayscale image; extracting edge points of the grayscale image respectively through a Canny operator and a local dynamic binarization algorithm; and calculating image clarity according to the intersection and union of the edge points respectively extracted by the Canny operator and the local dynamic binarization algorithm.
[0147] The above-mentioned computer-readable storage medium normalizes the image size to normalize all the images to be analyzed to the same size to ensure that the image clarity calculation is performed at the same resolution to adapt to images obtained in different scenes and different shooting devices. The image clarity can be evaluated by the same evaluation standard, thereby expanding the industrial application field and evaluation accuracy of image clarity. There is no need to use a reference image as a standard, and the system has good scene consistency and device consistency.
[0148] In one embodiment, the processor normalizes the image size of the image to be analyzed to be consistent with the preset size, including: obtaining a resolution value to be compatible; calculating a mean resolution corresponding to the resolution value to be compatible; determining a preset height value and a preset width value corresponding to the preset size according to the mean resolution; scaling the height of the image to be analyzed to the preset height value, and scaling the width of the image to be analyzed to the preset width value.
[0149] In one embodiment, the processor extracts edge points of the grayscale image by using the Canny operator and the local dynamic binarization algorithm, respectively, including: extracting edge points of the grayscale image by using the Canny operator to obtain a first edge point set; processing the grayscale image by using the local dynamic binarization algorithm to obtain a binary grayscale image, wherein the binary grayscale image includes 1 and 0, marking pixels in the grayscale image whose pixel values are greater than a preset threshold as 1, and marking pixels whose pixel values are less than or equal to the preset threshold as 0; forming a pixel point set with pixels marked as 1 in the binary grayscale image; and determining the edge points of the grayscale image according to the intersection of the first edge point set and the pixel point set.
[0150] In one embodiment, the processor extracts edge points of the grayscale image through the Canny operator to obtain a step of a first edge point set, including: smoothing the grayscale image by accumulating pixel values; calculating the gradient amplitude and gradient direction of the smoothed grayscale image through first-order partial derivative finite difference; performing non-maximum suppression on the gradient amplitude to obtain a suppressed gradient amplitude; and determining the first edge point set based on the suppressed gradient amplitude and the gradient amplitude before suppression.
[0151] In one embodiment, the processor smoothes the grayscale image by accumulating pixel values, including: determining a specified number of adjacent pixel points adjacent to a specified pixel point, wherein the specified pixel point is any pixel point in the grayscale image; respectively calculating the pixel value difference between each of the adjacent pixel points and the specified pixel point; determining the minimum of the absolute values of each of the pixel value differences; multiplying the minimum of the absolute values by a specified multiple to obtain a smoothed pixel value, wherein the specified multiple belongs to the interval (0,1); accumulating the smoothed pixel values with the original pixel values in the grayscale image to obtain corrected pixel values of the grayscale image; storing the corrected pixel values at pixel positions corresponding to the original pixel values in the blank image in a one-to-one correspondence with the original pixel values to obtain the smoothed grayscale image.
[0152] In one embodiment, the processor calculates the image clarity based on the intersection and union of edge points extracted by the Canny operator and the local dynamic binarization algorithm, respectively, comprising: calculating the union of the first edge point set and the pixel point set; calculating the intersection-and-union ratio based on the intersection of the first edge point set and the pixel point set, and the union of the first edge point set and the pixel point set; and converting the intersection-and-union ratio into a percentage as the clarity of the image to be analyzed.
[0153] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing related hardware through a computer program, and the above-mentioned computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media provided in this application and used in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0154] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, device, article or method including the element.
[0155] The above description is only a preferred embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for calculating image clarity, It is characterized in that include: Acquire an image to be analyzed; Determining whether the image size of the image to be analyzed is consistent with a preset size; If not, normalizing the image size of the image to be analyzed to be consistent with the preset size; Convert the image to be analyzed after image size normalization into a grayscale image; Extracting edge points of the grayscale image respectively by using a Canny operator and a local dynamic binarization algorithm; Calculating image clarity based on the intersection and union of edge points extracted by the Canny operator and the local dynamic binarization algorithm; The step of respectively extracting edge points of the grayscale image by using the Canny operator and the local dynamic binarization algorithm comprises: Extract edge points of the grayscale image using a Canny operator to obtain a first edge point set; Processing the grayscale image by a local dynamic binarization algorithm to obtain a binary grayscale image, wherein the binary grayscale image includes 1 and 0, marking pixels in the grayscale image whose pixel values are greater than a preset threshold as 1, and marking pixels whose pixel values are less than or equal to the preset threshold as 0; The pixels marked as 1 in the binary grayscale image are combined into a pixel set; Determining edge points of the grayscale image according to an intersection of the first edge point set and the pixel point set; The step of calculating the image clarity according to the intersection and union of edge points extracted by the Canny operator and the local dynamic binarization algorithm respectively comprises: Calculating a union of the first edge point set and the pixel point set; Calculating an intersection-and-union ratio according to an intersection of the first edge point set and the pixel point set, and a union of the first edge point set and the pixel point set; The I / O ratio is converted into a percentage as the clarity of the image to be analyzed.
2. The method for calculating image clarity according to claim 1, It is characterized in that The step of normalizing the image size of the image to be analyzed to be consistent with the preset size includes: Get the resolution value to be compatible; Calculate the average resolution corresponding to the resolution value to be compatible; Determine a preset height value and a preset width value corresponding to the preset size according to the mean resolution; The height of the image to be analyzed is scaled to the preset height value, and the width of the image to be analyzed is scaled to the preset width value.
3. The method for calculating image clarity according to claim 1, It is characterized in that The step of extracting edge points of the grayscale image by using a Canny operator to obtain a first edge point set comprises: Smoothing the grayscale image by accumulating pixel values; Calculating the gradient amplitude and gradient direction of the smoothed grayscale image by first-order partial derivative finite difference; Performing non-maximum suppression on the gradient amplitude to obtain a suppressed gradient amplitude; The first edge point set is determined according to the gradient magnitude after suppression and the gradient magnitude before suppression.
4. The method for calculating image clarity according to claim 3, It is characterized in that The step of smoothing the grayscale image by accumulating pixel values comprises: Determine a specified number of adjacent pixel points adjacent to a specified pixel point, wherein the specified pixel point is any pixel point in the grayscale image; Calculating the pixel value difference between each of the adjacent pixel points and the designated pixel point respectively; Determine the minimum value of the absolute values of the pixel value differences; Multiply the minimum value of the absolute value by a specified multiple to obtain a smoothed pixel value, wherein the specified multiple belongs to the interval (0, 1); Accumulating the smoothed pixel values with the original pixel values in the grayscale image to obtain corrected pixel values of the grayscale image; The corrected pixel values are stored in the blank image at pixel positions corresponding to the original pixel values in a one-to-one correspondence with the original pixel values, so as to obtain the smoothed grayscale image.
5. A device for calculating image clarity, used to implement the method according to any one of claims 1 to 4, It is characterized in that include: An acquisition module, used for acquiring an image to be analyzed; A judging module, used to judge whether the image size of the image to be analyzed is consistent with a preset size; A normalization module, used for normalizing the image size of the image to be analyzed to be consistent with the preset size if it is not consistent with the preset size; A conversion module, used for converting the image to be analyzed after the image size normalization process into a grayscale image; An extraction module, used to extract edge points of the grayscale image respectively by using a Canny operator and a local dynamic binarization algorithm; The calculation module is used to calculate the image clarity according to the intersection and union of edge points extracted by the Canny operator and the local dynamic binarization algorithm respectively.
6. The image definition calculation device according to claim 5, It is characterized in that The normalization module comprises: The acquisition submodule is used to obtain the resolution value to be compatible; A first calculation submodule, used for calculating the average resolution corresponding to the resolution value to be compatible; A first determination submodule, configured to determine a preset height value and a preset width value corresponding to the preset size according to the mean resolution; The scaling submodule is used to scale the height of the image to be analyzed to the preset height value, and scale the width of the image to be analyzed to the preset width value.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
