Image sharpness calculation method, image processing model training method and device
By extracting edges, straightening edge lines, and calculating the image sharpness of beveled edges, the problem of poor universality of sharpness grading in image processing models under different scenarios is solved, achieving the unification of sharpness grading and improving the reliability of image processing models.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHEJIANG DAHUA TECH CO LTD
- Filing Date
- 2022-12-21
- Publication Date
- 2026-06-05
AI Technical Summary
Existing image processing models and methods for calculating image sharpness in different scenarios result in poor universality of sharpness grading, consuming a lot of manpower and time.
By extracting edges from the target image, selecting edge regions, straightening edge lines, calculating the sharpness of the diagonal image, and determining the credibility of the training image based on the image sharpness, an image processing model is trained using a weighted loss function.
The image sharpness amplitude fluctuates little under different scenarios, and the sharpness classification is uniform, which reduces manpower and time costs and improves the reliability of the image processing model.
Smart Images

Figure CN116012323B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to an image sharpness calculation method, an image processing model training method, and an apparatus. Background Technology
[0002] Currently, some image processing models use image sharpness as auxiliary training data. When using image sharpness as auxiliary training data, image sharpness can be graded to determine the sharpness range of each image in the training set. Currently, image sharpness is typically represented using edge gradient information and its feature values. However, if the image scene changes, the magnitude of the image sharpness determined by this method will vary significantly. This results in multiple images from the same scene using the same sharpness grading standard, while images from different scenes cannot use the same sharpness grading standard. Furthermore, in reality, the training data for image processing models often comes from multiple different scenes. Applying image sharpness determined by current image sharpness calculation methods as auxiliary training data requires significant manpower and time to grade the sharpness for each scene. Summary of the Invention
[0003] The main technical problem solved by this invention is to provide an image sharpness calculation method, an image processing model training method and apparatus, which can solve the problem of poor universality of sharpness classification when using the image sharpness determined by the current image sharpness calculation method as auxiliary training data for the image processing model.
[0004] To solve the above-mentioned technical problems, one technical solution adopted by the present invention is to provide an image sharpness calculation method, comprising: extracting edges from a target image to obtain an edge image; selecting edge regions based on the edge image; straightening the edge lines in the edge region image of the target image to obtain a bevel image; and calculating the sharpness of the target image based on the bevel image.
[0005] In one embodiment, straightening the edge lines in the edge region image of the target image includes: moving the pixels on the edge lines to the tangent lines of the edge lines to straighten the edge lines into tangent lines.
[0006] In one embodiment, there is only one edge line in the edge region; the length of the edge line in the edge region is greater than or equal to a first threshold; and the distance between the midpoint of the edge line in the edge region and the preset boundary of the edge region is greater than or equal to a second threshold.
[0007] In one embodiment, the edge line in the edge region is a strong edge line.
[0008] In one embodiment, calculating the sharpness of a target image based on a beveled image includes: rotating the beveled image so that the angle of the straightened edge line in the rotated beveled image is within a preset range; and calculating the sharpness of the target image based on the rotated beveled image.
[0009] In one embodiment, the sharpness of the target image is calculated based on the rotated hypotenuse image, including: cropping the rotated hypotenuse image to obtain an image containing a tough edge; wherein the midpoint of the straightened edge line is located at the center of the rectangle of the image containing the tough edge; the distance between the center of the rectangle and the boundary of the image containing the tough edge is greater than or equal to a third threshold; the minimum distance between a preset intersection point and the vertex of the image containing the tough edge is greater than or equal to a fourth threshold, and the preset intersection point is the intersection point of the straightened edge line and the boundary.
[0010] In one embodiment, the number of edge regions selected based on the edge image is at least two; the sharpness of the target image is calculated based on the bevel image, including: calculating the sharpness of the bevel image corresponding to each edge region; and fusing the sharpness of the bevel images corresponding to all edge regions to obtain the sharpness of the target image.
[0011] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is: to provide a training method for an image processing model, the method comprising: determining the credibility of each image in the training image set;
[0012] Each image is processed using an image processing model to obtain a processing result for each image; the loss of each image is calculated based on the processing result; the losses of at least some images in the training image set are weighted to obtain the total loss, wherein the weight of each image is positively correlated with the credibility of each image; the image processing model is trained based on the total loss.
[0013] In one implementation, the credibility of each image is determined by the sharpness of each image.
[0014] In one embodiment, determining the credibility of each image in the training image set includes calculating the sharpness of each image using the method described in any of the preceding embodiments.
[0015] In one implementation, the weight of each image is the weight corresponding to the sharpness interval in which the sharpness of each image is located.
[0016] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is: to provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the image sharpness calculation method of any of the above-mentioned methods; or the training method of the image processing model of any of the above-mentioned methods.
[0017] To solve the above-mentioned technical problems, another technical solution adopted by the present invention is to provide a computer-readable storage medium storing instructions, wherein the computer program, when executed by a processor, implements the image sharpness calculation method of any of the above-mentioned methods; or a training method for an image processing model as described in any of the above-mentioned methods.
[0018] The beneficial effects of this invention are as follows: Unlike existing technologies, this invention extracts edges from the target image to obtain an edge image; based on the edge image, edge regions are selected; the edge lines in the edge region image of the target image are straightened to obtain a beveled image; and based on the beveled image, the sharpness of the target image is calculated. This results in minimal fluctuations in image sharpness across different scenes. Through this method, this invention solves the problem of poor universality in sharpness grading when using image sharpness determined by current image sharpness calculation methods as auxiliary training data for image processing models. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. Wherein:
[0020] Figure 1 This is a flowchart illustrating one embodiment of the image sharpness calculation method of the present invention;
[0021] Figure 2 This is a schematic diagram of another embodiment of the image sharpness calculation method of the present invention;
[0022] Figure 3 This is a flowchart illustrating one embodiment of the image processing model training method of the present invention;
[0023] Figure 4 This is a schematic diagram of the structure of one embodiment of the computer device of the present invention. Detailed Implementation
[0024] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. It is understood that the specific embodiments described herein are only for explaining this application and not for limiting it. Furthermore, it should be noted that, for ease of description, only the parts related to this application are shown in the accompanying drawings, not all structures. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0025] Please see Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the image sharpness calculation method of the present invention, which includes:
[0026] Step 101: Extract edges from the target image to obtain an edge image.
[0027] Optionally, edge images can be obtained by extracting edges from the target image using an edge detection algorithm. The edge detection algorithm can be the Sobel operator, Prewitt operator, Canny operator, etc., and the type of algorithm is not limited.
[0028] Alternatively, an image gradient algorithm can be used, which involves calculating the gradient of each pixel in the image, generating a gradient histogram, and using a threshold to distinguish between edges and smooth regions to obtain the edge image. Other methods can also be used to extract edges from the target image, as long as the edge image of the target image can be obtained.
[0029] Before edge extraction of the target image, it can be filtered to remove noise and reduce unnecessary interference. For example, a 3×3 Gaussian filter can be used to perform Gaussian filtering on the target image. Filtering the target image removes noise, thereby reducing the impact of noise on edge extraction and improving the accuracy of edge detection.
[0030] The target image can be acquired before edge extraction is performed on the target image. In one possible implementation, the target image can be acquired from monitoring data so that edge extraction can be performed on the acquired target image in step 101.
[0031] The acquired image may be a grayscale image, or it may be a color image such as an RGB image or a YUV image.
[0032] If the acquired image is a grayscale image, it can be directly used as the target image.
[0033] When the acquired image is an RGB image, it needs to be processed into grayscale, and the grayscale-processed image is used as the target image for edge extraction in step 101. During grayscale processing, component analysis, maximum value analysis, average value analysis, or weighted average analysis can be used. Please refer to [link to relevant documentation]. Figure 2 , Figure 2 This is a flowchart illustrating one embodiment of the image sharpness calculation method of the present invention. Taking a vehicle image as an example: corresponding to the acquired RGB vehicle image (a), the vehicle image is processed into grayscale to obtain a grayscale image of the vehicle image (b); based on the grayscale image of the vehicle image (b), edge extraction is performed to obtain the edge image of the target image (c).
[0034] When the acquired image is a YUV image, the Y component of the YUV image can be used as the target image.
[0035] Step 102: Select edge regions based on the edge image.
[0036] After acquiring the edge image, you can select regions within the edge image.
[0037] In one feasible implementation, the edge image can be divided into regions to obtain multiple candidate regions; then, a suitable edge region can be selected from the multiple candidate regions.
[0038] In another feasible implementation, the region containing the edge line in the edge image is cropped, and a suitable edge region is selected from multiple cropped regions.
[0039] Optionally, a suitable edge region refers to a selected edge region that meets a first preset condition. Specifically, the first preset condition may be as shown below, but is not limited to this.
[0040] For example, as shown in Figure (e), the selected edge region has only one edge line. The length of the edge line in the edge region is greater than or equal to a first threshold, and / or the distance between the midpoint of the edge line in the edge region and the preset boundary of the edge region is greater than or equal to a second threshold.
[0041] The preset boundary can be any boundary of the edge region. Alternatively, the preset boundary can be determined based on the position of the edge line in the edge region. For example, if the absolute value of the angle between the external tangent line of the midpoint of the edge line in the edge region and the horizontal line is greater than a preset angle, then the preset boundary is the upper and / or lower boundary of the edge region; otherwise, the preset boundary is the left and / or right boundary of the edge region. The preset angle can be set according to the actual situation and is not limited here; for example, it can be 30° or 40°.
[0042] In one embodiment, the first threshold and the second threshold can be preset fixed thresholds. For example, the fixed thresholds can be set by the user based on experience.
[0043] In another embodiment, the first threshold and the second threshold can be set according to actual conditions, and there are no restrictions here. For example, the first threshold can be 100 pixels, and the second threshold can be 35 pixels.
[0044] Furthermore, the edge lines in the edge region can be strong edge lines. Compared to weak edge lines, the pixel values on both sides of a strong edge line are relatively large. Therefore, by selecting strong edge lines, the image sharpness can be calculated more accurately.
[0045] Step 103: Straighten the edge lines in the edge region image of the target image to obtain a beveled image.
[0046] After determining the selected edge region based on the above steps, the edge lines in the edge region image of the target image can be straightened to obtain a beveled image, which is then used to calculate the sharpness of the target image.
[0047] In one feasible implementation, the edge line can be straightened using a translation method. For example, pixels on the edge line can be moved to the tangent line of the edge line to straighten it into a tangent line. The tangent line of the edge line can refer to the tangent line of a preset point on the edge line. The preset point can be the midpoint of the edge line, a point adjacent to the midpoint, or an endpoint of the edge line; its specific location is not limited.
[0048] Specifically, taking the upper and / or lower boundaries of the edge region as an example (preset boundaries), the slope and intercept of the tangent line at the midpoint of the edge line in the edge region image are calculated. Using the midpoint of the edge line as a reference, multiple pixels on the edge line are moved horizontally. For each pixel moved, the target coordinate value is calculated according to the straight line equation. Based on the horizontal distance *d* between the target coordinate value and the initial coordinate value of the pixel on the edge line, the pixel on the edge line is horizontally shifted by *d* distances, so that the pixel on the edge line is now on the tangent line of the original edge line. This yields the beveled image, which is then used to calculate the sharpness of the target image.
[0049] Continuing with the example of a vehicle image: After obtaining the grayscale image (b) of the vehicle image and selecting the edge region based on the edge image (c), the edge lines in the edge region image (e) of the grayscale image (b) of the vehicle image are straightened. The specific method is described in step 103, and will not be repeated here.
[0050] It should be noted that, as shown in Figure (e), since the edge image (c) is obtained by processing the grayscale image (b) of the vehicle image, the edge region selected based on the edge image (c) can be mapped to the grayscale image (b) of the vehicle image. In this way, the edge region image in the grayscale image of the vehicle image can be determined based on the selected edge region.
[0051] It is important to note that, such as Figure 2As shown in (e)-(f), after straightening the edge lines in the edge region of the grayscale image of the vehicle image, the pixels on the edge lines move to the tangent line of the original edge lines, and the pixel values around the edge lines also move along with the pixels on the edge lines. This causes the pixel values of the pixels between the straightened edge lines and the original edge lines to become preset pixel values, which are equal to the pixel values of the adjacent pixels on the side of the original edge lines that are furthest from the straightened edge lines.
[0052] Step 104: Calculate the sharpness of the target image based on the slanted edge image.
[0053] After obtaining the slanted edge image based on the above steps, the sharpness of the target image can be calculated based on the slanted edge image.
[0054] The number of hypotenuse images obtained is unlimited; for example, there can be one or more hypotenuse images.
[0055] When only one hypotenuse image is obtained, the sharpness of that hypotenuse image is directly calculated, and the sharpness of the hypotenuse image is used as the sharpness of the target image.
[0056] When there are multiple oblique edge images, the sharpness of the oblique edge image corresponding to each edge region is first calculated; the sharpness of the oblique edge images corresponding to all edge regions is then fused to calculate the sharpness of the target image.
[0057] In one feasible approach, the sharpness of a beveled image can be calculated using the MTF50 algorithm. Related techniques, when using the MTF algorithm to calculate camera image sharpness, require determining the region of interest (ROI) using the coordinates of the edge center point of a test black block on a professional test chart, the constraint values of the set region of interest (ROI), and the known slope of each edge of interest, through a linear equation. This yields a ROI with a certain angle to the test black block, ensuring that the ROI is within a preset angle range to meet the ROI requirements of the MTF algorithm. This application, however, obtains a beveled image based on the above steps. When subsequently using the MTF algorithm to calculate image sharpness, it can calculate the sharpness MTF value in more general images, without relying on a professional test chart, thus exhibiting good scene versatility.
[0058] In another feasible approach, the sharpness of a beveled image can be calculated using the SFR algorithm. Related techniques rely on specialized test charts when calculating camera image sharpness using the SFR algorithm. However, this application obtains a beveled image based on the steps described above. When subsequently using the SFR algorithm to calculate image sharpness, the sharpness SFR value can be calculated in a more general range of images, without relying on specialized test charts, thus offering good scene versatility.
[0059] In another feasible approach, the slanted image can be input into a trained convolutional neural network model to obtain the sharpness score of the slanted image, thereby obtaining the sharpness of the target image.
[0060] Furthermore, image normalization can be performed before calculating the sharpness of the slanted image, allowing image sharpness calculations to be performed at the same resolution. This adapts to images obtained in different scenarios and from different shooting devices, enabling the evaluation of image sharpness using the same criteria, thus expanding the industrial application scope and evaluation accuracy of image sharpness calculation. The aforementioned image normalization methods include, but are not limited to, proportional scaling, or mapping pixels to blank files of the same size to achieve image size normalization.
[0061] Optionally, before performing the sharpness calculation, it can be determined whether the slanted image obtained based on the above steps meets the second preset condition; if the slanted image obtained based on the above steps does not meet the second preset condition, the slanted image is processed so that the processed slanted image meets the second preset condition, thereby satisfying the requirements of algorithms such as MTF / SFP for images used for sharpness calculation.
[0062] For example, it can be determined whether the angle of the straightened edge line in the beveled image is within a preset range (for example, [60°, 120°] or [75°, 115°], etc.). If the angle of the straightened edge line in the beveled image is within the preset range, the sharpness of the target image can be calculated based on the beveled image. It should be noted that the preset range does not include 90°. If the angle of the straightened edge line in the beveled image is not within the preset range, the beveled image needs to be rotated so that the angle of the straightened edge line in the rotated beveled image is within the preset range, and then the sharpness of the target image is calculated based on the rotated beveled image.
[0063] Furthermore, the second preset condition may include not only the aforementioned angle condition, but also the midpoint position condition and / or intersection position condition of the straightened edge line in the hypotenuse image. If the midpoint position condition and / or intersection position condition do not meet the requirements, the rotated hypotenuse image can be cropped to obtain an image containing the hypotenuse, so that the midpoint position condition and / or intersection position condition of the image containing the hypotenuse meets the requirements. Specifically, meeting the requirements for the midpoint position condition and / or intersection position condition of the image containing the hypotenuse can mean that: the midpoint of the straightened edge line is located at the center of the vertex of the image containing the hypotenuse; the distance between the center of the vertex and the boundary of the image containing the hypotenuse is greater than or equal to a third threshold; and the minimum distance between the preset intersection point and the vertex of the image containing the hypotenuse is greater than or equal to a fourth threshold. The preset intersection point is the intersection of the straightened edge line and the boundary.
[0064] In one embodiment, the third and fourth thresholds can be preset fixed thresholds. For example, the fixed thresholds can be set by the user based on experience.
[0065] In another embodiment, the third and fourth thresholds can be set according to actual conditions, and are not limited here. For example, the third threshold can be 20 pixels, and the fourth threshold can be 5 pixels.
[0066] In this embodiment, edge images are obtained by edge extraction of the target image; edge regions are selected based on the edge images; the edge lines in the edge region images of the target image are straightened to obtain beveled images; and the sharpness of the target image is calculated based on the beveled images. When the image scene changes, the amplitude fluctuation of the image sharpness determined by this method is small. Therefore, when using the image sharpness determined by this image sharpness calculation method as auxiliary training data, it is not necessary to spend a lot of manpower and time to classify the sharpness of each scene, making the sharpness classification uniform across different scenes. Furthermore, compared with the original camera image MTF / SFR value calculation method, the image sharpness calculation method of this application does not rely on professional test charts and can calculate the sharpness MTF value in more common images, resulting in good scene universality for sharpness classification. Through the above methods, this invention can solve the problem of poor universality in image sharpness calculation.
[0067] Please see Figure 3 , Figure 3 This is a flowchart illustrating one implementation method of an image processing model training method according to this application.
[0068] Step 301: Determine the credibility of each image in the training image set.
[0069] In one embodiment, the image sharpness calculation method described in any of the above embodiments can be used to calculate the sharpness of each image in the training image set, and the sharpness of each image in the training image set can be used as the reliability of each image in the training image set. Of course, other methods can also be used to determine the sharpness of each image. In this embodiment, during the training process, the sharpness of the training images in the training image set is used to characterize the reliability of the training images, and the model training is guided based on the sharpness of the training images. This makes the image processing model pay more attention to data with high sharpness, thereby appropriately reducing the impact of data with low sharpness on the image processing model, resulting in a more reliable model after training.
[0070] In another implementation, the source confidence of each image in the training image set can be used as the confidence of each image in the training image set.
[0071] Optionally, when using source credibility to obtain the credibility of each image in the training image set, the credibility of each image can be determined based on its source. For example, images obtained by direct photography have higher credibility than images downloaded from the internet.
[0072] In another embodiment, quality parameters such as sharpness, contrast, or data source credibility of each image in the training image set can be determined; then, based on the distribution of quality parameters of all images in the training image set, a quality parameter grading standard is determined; based on the grading standard, the credibility label corresponding to the quality parameter interval of each image in the training image set is used as the credibility of each pixel.
[0073] Optionally, the credibility label can range from [0,1]. In other embodiments, the credibility label can also range from [0,2].
[0074] The confidence label is positively correlated with the quality parameters of the training images. For example, the confidence label for the quality parameter interval (1,29) is 0.1, and the confidence label for the quality parameter interval (30,60) is 0.2.
[0075] For example, the sharpness of each image in the training image set can be determined; then, by combining the current sharpness distribution of the training images in the overall training image set, the current sharpness grading standard for the training images can be determined; based on the grading standard, the confidence label corresponding to the sharpness interval of each image in the training image set is used as the confidence of each pixel.
[0076] Step 302: Use the image processing model to process each image and obtain the processing result for each image.
[0077] Specifically, each training image in the training image set is input into the image processing model, which then processes each training image to obtain the processing result for that image. This image processing model can be applied to image processing tasks such as object classification, image detection, image recognition, and image segmentation.
[0078] Furthermore, before step 302, an image processing model can be constructed. This image processing model can be any type of neural network model capable of image processing; for example, it can be a deep neural network (DNN) model, such as a convolutional neural network (CNN) model, a recurrent neural network (RNN), and so on.
[0079] After constructing the image processing model network structure, the network parameters can be initialized so that the image processing model with initialized network parameters can be trained using the image processing model training method of this application.
[0080] Step 303: Calculate the loss for each image based on the processing results of each image.
[0081] Specifically, after obtaining the processing results of each image through the above steps, the loss of each image can be calculated based on the processing results of each image.
[0082] For example, the loss for each image can be calculated using the task label and processing result for each image.
[0083] The loss for each image can be calculated using loss functions such as variance loss function, squared difference loss function, and L2 distance.
[0084] Step 304: Weight the loss of at least a portion of the images in the training image set to obtain the total loss.
[0085] Specifically, the loss of at least a portion of the images in the training image set is weighted to obtain the total loss. The weighting method can be average weighting.
[0086] Optionally, the formula for calculating the total loss is as follows:
[0087]
[0088] Where, loss overall For the total loss, The weights of the i-th image, loss i Let N be the loss for the i-th image, and N represent the total number of images.
[0089] In this model, the weight of each image is positively correlated with its credibility; that is, images with higher credibility have higher weights in the loss function. Conversely, images with low credibility have lower weights in the loss function. This is to reduce the impact of low-credibility data on the image processing model, thereby making the final image processing model more reliable.
[0090] In step 301, if the credibility label of each image is used as the credibility of each image, the credibility label of each image can be directly used as the weight of each image.
[0091] In other embodiments, the credibility of each image can be linearly or non-linearly processed to obtain the weight of each image.
[0092] Step 305: Train the image processing model based on the total loss.
[0093] Optionally, the image processing model can be backpropagated based on the total loss mentioned above to iteratively update the parameters of each neural network in the image processing model, thereby completing the training of the model.
[0094] Preferably, as described in step S301 above, the image sharpness calculation method described above can be used to calculate the sharpness of each image in the training image set, and the sharpness of each image can be used as the confidence level of each image. In this way, the loss of each image can be calculated based on its sharpness, and the losses of at least a portion of the images in the training image set can be weighted to obtain the total loss. The image processing model is then trained based on the total loss. By using the sharpness of the input image to represent the confidence level and guide the training of the image processing model, the image processing model pays more attention to high-sharpness data, thereby appropriately reducing the impact of low-sharpness data on the image processing model, resulting in a more reliable trained image processing model.
[0095] Optionally, after calculating the total loss, it can be determined whether the current image processing model meets the termination condition based on the total loss. If the current image processing model does not meet the training termination condition, the image processing model parameters are optimized based on steps 302, 303, 304, and 305 until the image processing model meets the training termination condition and the model parameter update is stopped. In this way, the trained image processing model can be obtained.
[0096] Optionally, the training termination condition can be: the total loss is less than the loss threshold; or the number of parameter updates is greater than the number of updates threshold, etc.
[0097] In this embodiment, the credibility of each image in the training image set is determined; each image is processed using an image processing model to obtain a processing result; the loss of each image is calculated based on its processing result; the losses of at least a portion of the images in the training image set are weighted to obtain a total loss, wherein the weight of each image is positively correlated with its credibility; and the image processing model is trained based on the total loss. By utilizing image credibility as an aid, the image processing model focuses more on data with high credibility, thereby appropriately reducing the impact of data with low credibility on the image processing model, resulting in a more reliable trained model.
[0098] To better illustrate the image processing model training method of this application, the following specific embodiments of the image processing model are provided as examples:
[0099] S1: Obtain the training image set.
[0100] S2: Select a single image from the training image set as the target image to obtain an image with a tough edge.
[0101] S21: Perform grayscale processing on a single image selected from the training image set to obtain a grayscale image (i.e., the target image).
[0102] S22: Extract edges from the target image to obtain an edge image; select N edge regions that meet a first preset condition based on the edge image. The first preset condition is:
[0103] a) The length of the edge line needs to be greater than the limit threshold T1 (T1≥100pixel).
[0104] b) There is one and only one strong edge in the edge region, and the strong edge is located in the center of the edge region.
[0105] c) The distance between the midpoint of a strong edge and the reference boundary of the edge region should be greater than the limit threshold T2 (T2≥35pixel); if the absolute value of the angle between the external tangent of the midpoint of a strong edge and the horizontal line is greater than 30 degrees, then the reference boundary is the upper and lower boundary; otherwise, the reference boundary is the left and right boundary.
[0106] S23: Straighten the edge lines in the edge region image of the target image to obtain a slanted image.
[0107] Calculate the slope k and intercept b of the external tangent line at the midpoint of the strong edge within the edge region. Use the translation method to straighten the edge and obtain the slanted edge image. Taking the reference boundary as the upper and lower boundaries as an example, the specific implementation method is as follows: using the edge midpoint as the reference, for each horizontal movement of one pixel, calculate the target coordinate value according to the straight line equation, then calculate the horizontal distance d between the target coordinate and the pixel on the edge line of that row, and finally translate all pixels in the row as a whole by d pixels so that the moved edge point is on the aforementioned external tangent line.
[0108] S24: Based on the hypotenuse image, obtain the image containing the ligament.
[0109] The hypotenuse image is rotated so that the angle of the hypotenuse is in the range of [60°, 120°]. Then, an image containing the hypotenuse that meets the second preset condition is extracted from the rotated hypotenuse image. The second preset condition is:
[0110] a) The midpoint of the straightened edge line is located at the center of the rectangle of the image containing the tough edge.
[0111] b) The distance between the center of the square and the boundary of the image containing the tough edge is not less than the threshold T3 (T3≥20pixel).
[0112] c) The minimum distance from the intersection of the straightened edge line and the boundary of the image containing the tough edge to the nearest boundary is not less than the threshold T4 (T4≥5pixel).
[0113] S3: Determine the sharpness of a single image.
[0114] For a single image, extract several images containing tough edges, calculate their respective sharpness MTF50 / SFR values, and fuse the sharpness of all images containing tough edges to obtain the sharpness of the single image. 。
[0115] S4: Calculate the sharpness of all images in the training image set, and divide the sharpness distribution of all images in the training image set into multiple sharpness intervals. Determine the confidence label (i.e., confidence) for each sharpness interval.
[0116] Calculate the sharpness of all images in the training image set. Based on the overall sharpness distribution of the training image set, divide it into M sharpness intervals and determine a confidence label for each sharpness interval. Intervals with lower sharpness correspond to smaller confidence labels, and vice versa. The value range of the confidence label can be [0 to 1].
[0117] S5: Determine the credibility of a single image in the training image set.
[0118] The confidence label corresponding to the sharpness range of each image in the training image set can be used as the confidence of each image (also called the confidence label).
[0119] Furthermore, the confidence level of each image can be used as a weighting coefficient for the loss of each image. Using the methods described in S2-S5 above, the confidence labels of all training images in the training image set are determined.
[0120] S6: Guide the training of the image processing model based on task labels and credibility labels.
[0121] Data with high credibility indicates greater certainty, and people have a lower tolerance for its errors; therefore, its weight in the loss function should be increased. Conversely, data with low credibility should have its weight in the loss function appropriately reduced. Here, credibility labels are used as weight coefficients in the original loss function to achieve the above objective and improve the reliability of CNN models. The formula is as follows:
[0122]
[0123] It is important to note that the credibility label is only used to adjust the weight of the original loss and does not participate in the calculation of the task label.
[0124] Please see Figure 4 , Figure 4This is a schematic diagram of a computer device according to an embodiment of the present invention. In this embodiment, the computer device includes a processor 50 and a memory 51 coupled to each other for cooperating to implement the image occlusion method described in any of the above embodiments. The memory 51 also includes at least one computer program 52 running on the processor 50. When the processor 50 executes the computer program 52, it implements the steps in any of the above-described image occlusion method embodiments.
[0125] The processor 50 can be a Central Processing Unit (CPU), or it can be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0126] The memory 51 can be a Smart Media Card (SMC), a Secure Digital Card (SD), a Flash Card, etc. Furthermore, the memory 51 can include both internal storage units and external storage devices. The memory 51 is used to store the operating system, applications, bootloader, data, and other programs, such as the program code of computer programs. The memory 51 can also be used to temporarily store data that has been output or will be output.
[0127] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps described in the various method embodiments above.
[0128] This application provides a computer program product that, when run on a terminal device, enables the terminal device to implement the steps described in the various method embodiments above.
[0129] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying the computer program code to a terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks.
[0130] The above description is merely an embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this invention.
Claims
1. A training method for an image processing model, characterized in that, include: Edges are extracted from the target image to obtain an edge image; wherein the target image belongs to the training image set. Based on the edge image, the edge region is selected; The edge lines in the edge region image of the target image are straightened to obtain a beveled image; Based on the slanted image, the sharpness of the target image is calculated; wherein, the sharpness characterizes the credibility of the images in the training image set; Calculate the sharpness of all images in the training image set, and divide the sharpness distribution of all images in the training image set into multiple sharpness intervals. Determine the confidence level for each sharpness interval; the confidence level of the interval with lower sharpness is lower than the confidence level of the interval with higher sharpness. Determine the credibility of each image in the training image set; wherein, the credibility of the image is defined as the credibility of the image corresponding to the sharpness interval in which its sharpness falls. The image processing model is used to process each image in the training image set to obtain the processing result for each image; The loss of each image is calculated based on the processing result of each image; The total loss is obtained by weighting the loss of at least a portion of the images in the training image set, wherein the weight of each image is positively correlated with the confidence of each image; The image processing model is trained based on the total loss.
2. The method according to claim 1, characterized in that, The step of straightening the edge lines in the edge region image of the target image includes: moving the pixels on the edge lines to the outer tangent line of the edge lines to straighten the edge lines into the outer tangent line.
3. The method according to claim 1, characterized in that, There is only one edge line in the edge region; The length of the edge line in the edge region is greater than or equal to the first threshold. The distance between the midpoint of the edge line in the edge region and the preset boundary of the edge region is greater than or equal to a second threshold.
4. The method according to claim 3, characterized in that, The edge lines in the edge region are strong edge lines.
5. The method according to claim 1, characterized in that, The step of calculating the sharpness of the target image based on the beveled image includes: rotating the beveled image so that the angle of the straightened edge line in the rotated beveled image is within a preset range; The sharpness of the target image is calculated based on the rotated hypotenuse image.
6. The method according to claim 5, characterized in that, The step of calculating the sharpness of the target image based on the rotated hypotenuse image includes: cropping the rotated hypotenuse image to obtain an image containing the hypotenuse; The midpoint of the straightened edge line is located at the center of the rectangle of the image containing the tough edge; The distance between the center of the rectangle and the boundary of the image containing the tough edge is greater than or equal to the third threshold. The minimum distance between the preset intersection point and the vertex of the image with the tough edge is greater than or equal to a fourth threshold. The preset intersection point is the intersection point of the straightened edge line and the boundary.
7. The method according to claim 1, characterized in that, The number of edge regions selected based on the edge image is at least two; Calculating the sharpness of the target image based on the beveled image includes: calculating the sharpness of the beveled image corresponding to each edge region; The sharpness of the target image is obtained by fusing the sharpness of the diagonal images corresponding to all edge regions.
8. The method according to claim 1, characterized in that, The weight of the image is the weight corresponding to the sharpness interval in which the image's sharpness falls.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-8.