Method, apparatus, and storage medium for adjusting image resolution according to scale tick marks

By preprocessing, elliptical fitting and linear fitting of the adjusted image, the slope between the scale lines is calculated, which solves the problem of poor image resolution adjustment effect caused by missed detection and missed detection in the prior art, and achieves more accurate image resolution adjustment.

CN114140327BActive Publication Date: 2025-06-20PEKING UNIV RESOURCE TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111480912.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-06
Publication Date
2025-06-20
Estimated Expiration
2041-12-06

AI Technical Summary

Technical Problem

When existing algorithms for calculating the distance between scale lines occur under-checking or incorrectly, the distance between the obtained scale lines is much different from the actual distance, resulting in poor image resolution adjustment effect.

Method used

By preprocessing the image to be adjusted, the scale line profile information is extracted, and each scale line is elliptically fitted and rotated. The straight line fitted to obtain the slope of the fitted line, the distance between the scale lines is calculated based on the slope, and the image resolution is finally adjusted.

Benefits of technology

Through this method, the distance between the scale lines can be accurately calculated, missed and missed detection phenomena can be reduced, and the accuracy and effect of image resolution adjustment can be improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114140327B_ABST
    Figure CN114140327B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device and storage medium for adjusting the image resolution according to the scale graduation lines, belonging to the field of image adjustment. First, the image to be adjusted is preprocessed to obtain a contour image, then the contour image is subjected to ellipse fitting, and then the fitted image is rotated to make the major axis of the ellipse parallel to the vertical direction. The slope of the fitted straight line is obtained by linearly fitting the center points of each graduation line after rotation. The distance between the graduation lines is obtained according to the slope. Finally, the resolution of the image to be adjusted is adjusted according to the distance between the graduation lines. The solution of the present application obtains the distance between the graduation lines according to the slope of the straight line fitted by the center points of the graduation lines. Whether there is a problem of missed detection of the graduation lines or not, the slope of the straight line fitted by the center points of the graduation lines remains unchanged. Therefore, the distance between the graduation lines obtained according to the slope will not change due to the missing of the graduation lines, and the finally calculated distance has a small difference from the actual distance, and the effect of adjusting the image resolution according to the obtained distance is good.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image adjustment, and in particular, to a method, device, and storage medium for adjusting the image resolution according to the scale graduation lines. Background Art

[0002] With the rapid development of computer technology, the requirements for images are getting higher and higher. For example, in fingerprint recognition, there are high requirements for fingerprint images and the extracted features. Generally, during acquisition, a scale is needed to measure the size of the fingerprint, which is used to determine whether the fingerprint size meets the standard and standardizes the correction of the fingerprint size in the fingerprint image. Therefore, the resolution of the image, that is, the size of the image, can be changed by detecting the distance between the scale graduation lines in the image.

[0003] For the existing algorithms for calculating the distance between graduation lines, some are based on traditional image algorithms, analyzing the pixel distribution of the image using projection information to detect the edge of the scale; some directly calculate the average width between the graduation lines as the distance between the graduation lines after detecting the edge of the graduation lines; and some detect the scale measurement image and the scale image in the scale measurement image through deep learning algorithms.

[0004] However, there will be missed detection and misdetection phenomena in graduation line detection. When using the existing algorithms for calculating the distance between graduation lines and there are missed detection and misdetection phenomena, the obtained distance between the graduation lines often differs greatly from the actual distance, and the effect is poor when adjusting the image resolution according to the obtained distance. Summary of the Invention

[0005] In order to overcome the deficiencies of the prior art, the present invention provides a method, device, and storage medium for adjusting the image resolution according to the scale graduation lines, so as to solve the problem that when using the existing algorithms for calculating the distance between graduation lines and there are missed detection and misdetection phenomena, the obtained distance between the graduation lines often differs greatly from the actual distance, and the effect is poor when adjusting the image resolution according to the obtained distance.

[0006] The technical solution adopted by the present invention to solve its technical problems is as follows:

[0007] In the first aspect,

[0008] A method for adjusting the image resolution according to the scale graduation lines includes the following steps:

[0009] Preprocess the image to be adjusted to obtain a contour image containing the contour information of the graduation lines;

[0010] Perform ellipse fitting on the contour of each graduation line in the contour image, fit each graduation line into an ellipse, and use the center point of each ellipse as the center point of the graduation line;

[0011] Rotate the scale lines after fitting to make the major axis of the ellipse parallel to the vertical direction;

[0012] Perform linear fitting on the center points of each scale line after rotation to obtain the slope of the fitted straight line;

[0013] Obtain the distance between the scale lines according to the slope;

[0014] Adjust the resolution of the image to be adjusted according to the distance between the scale lines.

[0015] Further, the preprocessing of the image to be adjusted to obtain a contour image including the scale line contours includes:

[0016] Segment the image to be adjusted through a pre-trained image segmentation model to obtain a scale bar mask image including only the background and scale lines;

[0017] Binarize the scale bar mask image to obtain a binarized image;

[0018] Extract the contours of the binarized image to obtain a contour image including the scale line contours.

[0019] Further, the linear fitting of the center points of each scale line after rotation includes:

[0020] Map the center points of each scale line to obtain the mapped center points, where the ordinate of the mapped center points is the abscissa of the center points before mapping, and the abscissas of all the mapped center points are arbitrary values and the same;

[0021] Adjust the abscissa of the mapped center points according to the ordinate of the mapped center points, and the abscissas of all the mapped center points after adjustment are different integers;

[0022] Perform linear fitting on the adjusted center points.

[0023] Further, the adjustment of the abscissa of the mapped center points according to the ordinate of the mapped center points includes:

[0024] For any mapped center point, calculate the first step distance between the current point and the next point, and the first step distance is the difference between the ordinate of the next point and the ordinate of the current point;

[0025] If the first step distance is within a preset range, calculate the first relative distance between the current point and all the remaining center points;

[0026] Assign the abscissa of the current point to 0, calculate the first ratio of the first relative distance to the first step distance, and take the integer of the first ratio as the abscissa of the center point corresponding to the first relative distance.

[0027] Further, the linear fitting of the center points of each scale line after rotation includes:

[0028] Mapping the center points of each scale line to obtain the mapped center points, where the abscissa of the mapped center points is the abscissa of the center points before mapping, and the ordinates of all the mapped center points are arbitrary values and the same;

[0029] Adjust the ordinates of the mapped center points according to the abscissas of the mapped center points, so that the abscissas of all the adjusted mapped center points are different integers;

[0030] Perform linear fitting on the adjusted center points.

[0031] Further, the adjustment of the ordinate of the center point before mapping according to the abscissa of the mapped center point includes:

[0032] For any mapped center point, calculate the second step distance between the current point and the next point, and the second step distance is the difference between the abscissa of the next point and the abscissa of the current point;

[0033] If the second step distance is within a preset range, calculate the second relative distance between the current point and all the remaining center points;

[0034] Assign the ordinate of the current point to 0, calculate the second ratio of the second relative distance to the second step distance, and take the integer of the second ratio as the ordinate of the center point corresponding to the second relative distance.

[0035] Further, obtaining the distance between the scale lines according to the slope includes:

[0036] For the straight line fitted with any center point as the current point, calculate the sum of the differences between the ordinates corresponding to all points on the fitted straight line and the actual ordinates, or calculate the sum of the differences between the abscissas corresponding to all points on the fitted straight line and the actual abscissas;

[0037] The average difference of the calculated sum is used as the average error of the current point;

[0038] Select the slope of the fitted straight line with the minimum average error as the distance between the scale lines, or select the reciprocal of the slope of the fitted straight line with the minimum average error as the distance between the scale lines.

[0039] Further, in the process of obtaining the slope of the fitted straight line, it also includes:

[0040] Detect whether the number of scale lines is greater than a preset number;

[0041] If it is not greater than, perform a dilation operation on the image to be adjusted so that the number of scale lines is greater than the preset number.

[0042] In a second aspect,

[0043] An apparatus for adjusting the resolution of an image according to scale lines of a scale includes:

[0044] An image preprocessing module for preprocessing the image to be adjusted to obtain a contour image including the contour information of the scale lines;

[0045] An image fitting module for performing elliptical fitting on the contour of each scale line in the contour image, fitting each scale line into an ellipse, and taking the center point of each ellipse as the center point of the scale line;

[0046] A scale line rotation module for rotating the scale lines after fitting so that the major axis of the ellipse is parallel to the vertical direction;

[0047] A slope acquisition module for performing linear fitting on the center points of each scale line after rotation to obtain the slope of the fitting line;

[0048] A distance calculation module for obtaining the distance between the scale lines according to the slope;

[0049] A resolution adjustment module for adjusting the resolution of the image to be adjusted according to the distance between the scale lines.

[0050] In a third aspect,

[0051] A storage medium includes:

[0052] A processor;

[0053] A memory for executing instructions executable by the processor;

[0054] The processor is configured to be used for the method described in any one of the technical solutions in the first aspect.

[0055] Advantageous effects:

[0056] The technical solution of this application provides a method, device, and storage medium for adjusting the image resolution according to the scale graduation lines. First, preprocess the image to be adjusted to obtain the contour image of the scale graduation lines, then perform ellipse fitting on all the contours in the contour image, and then rotate the fitted image to make the major axis of the ellipse parallel to the vertical direction; perform linear fitting on the center points of each graduation line after rotation to obtain the slope of the fitted line; obtain the distance between the graduation lines according to the slope; finally, adjust the resolution of the image to be adjusted according to the distance between the graduation lines. The solution of this application uses the slope of the line fitted by the center points of the graduation lines to obtain the distance between the graduation lines. Whether there is a problem of missed detection of the graduation lines or not, the slope of the line formed by the center points of the graduation lines remains unchanged. Therefore, the distance between the graduation lines obtained according to the slope will not change due to the missing of the graduation lines. The finally obtained distance between the graduation lines has a small difference from the actual distance, and the effect of adjusting the image resolution according to the obtained distance is good. Brief Description of the Drawings

[0057] In order to more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of this application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0058] Figure 1 is a flowchart of a method for adjusting the image resolution according to the scale graduation lines provided by an embodiment of the present invention;

[0059] Figure 2 is a flowchart of a specific method for adjusting the image resolution according to the scale graduation lines provided by an embodiment of the present invention;

[0060] Figure 3 is a schematic diagram of the graduation lines before and after ellipse fitting provided by an embodiment of the present invention;

[0061] Figure 4 is a schematic structural diagram of a device for adjusting the image resolution according to the scale graduation lines provided by an embodiment of the present invention. Detailed Description of the Embodiments

[0062] To make the purpose, technical solution, and advantages of this application clearer, the technical solutions of the present invention will be described in detail below with reference to the drawings and embodiments. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all the embodiments. All other implementation manners obtained by those of ordinary skill in the art without creative efforts based on the embodiments in this application belong to the scope protected by this application.

[0063] Refer to Figure 1, an embodiment of the present invention provides a method for adjusting the image resolution according to the scale graduation lines, including the following steps:

[0064] Preprocess the image to be adjusted to obtain a contour image containing the contour information of the graduation lines;

[0065] Perform ellipse fitting on the contour of each graduation line in the contour image, fit each graduation line into an ellipse, and use the center point of each ellipse as the center point of the graduation line;

[0066] Rotate the fitted graduation lines to make the major axis of the ellipse parallel to the vertical direction;

[0067] Perform linear fitting on the center points of each rotated graduation line to obtain the slope of the fitted straight line;

[0068] Obtain the distance between the graduation lines according to the slope;

[0069] Adjust the resolution of the image to be adjusted according to the distance between the graduation lines.

[0070] A method for adjusting the image resolution according to the scale graduation lines provided by an embodiment of the present invention first preprocesses the image to be adjusted to obtain a contour image of the scale graduation lines, then performs ellipse fitting on all the contours in the contour image, and then rotates the fitted image to make the major axis of the ellipse parallel to the vertical direction; perform linear fitting on the center points of each rotated graduation line to obtain the slope of the fitted straight line; obtain the distance between the graduation lines according to the slope; finally, adjust the resolution of the image to be adjusted according to the distance between the graduation lines. The solution of this application uses the slope of the straight line fitted by the center points of the graduation lines to obtain the distance between the graduation lines. Whether there is a problem of missed detection of the graduation lines or not, the slope of the straight line formed by the center points of the graduation lines remains unchanged. Therefore, the distance between the graduation lines obtained according to the slope will not change due to the missing of the graduation lines, and the finally obtained distance between the graduation lines is very close to the actual distance. Adjusting the image resolution according to the obtained distance has a good effect.

[0071] To further illustrate the above embodiments, an embodiment of the present invention also provides a specific method for adjusting the image resolution according to the scale graduation lines, as Figure 2 shown, including the following steps:

[0072] The first step: Image segmentation. First, train an image segmentation model, which is mainly used to segment the scale graduation lines and fingerprint parts in the image. This algorithm is the basis of the whole algorithm. The output image is a black and white image, with the background being black and the graduation lines being white. This image is similar to a mask image, so it is called a scale mask image.

[0073] The second step: Image binarization. Since the above scale mask image approximates a binary image but is not a binary image in the strict sense, it is necessary to perform binarization on the image for subsequent processing.

[0074] Step 3: Extract contours. Perform contour extraction on the above-mentioned binarized image, and determine whether the number of contours in the binary image is greater than 5, that is, whether the number of scale lines is greater than 5. If the condition is met, perform the following steps; if not, jump to Step 9. This condition is to prevent excessive calculation errors caused by too few scale lines. In addition, the perimeter of the contour needs to be screened by conditions to determine whether the perimeter of the contour meets the conditions. If the condition is met, perform the following steps; if not, jump to Step 9. This condition is to prevent irrelevant noises from being calculated, that is, there are some lines that are not scale lines, which will be regarded as scale lines during the above steps.

[0075] Step 4: Ellipse fitting. Perform ellipse fitting based on the above-mentioned contour information. As Figure 3 shown, at this time each scale line becomes an ellipse. Calculate the center point coordinates of the ellipse, the lengths of the major axis and the minor axis, and perform contour screening based on the center point coordinates, the major axis, the minor axis, and the ratio of the major axis to the minor axis. Discard the unreasonable contours, and record the center point, the major axis, the minor axis, and the angle information of each remaining ellipse. The ellipse fitting algorithm in this step uses the covariance matrix method. Although the specific position information of the scale lines can also be detected through the line detection algorithm, the traditional hough line detection method is time-consuming, and although the LSD algorithm is fast, neither of them can simply and accurately calculate the length and width of the line. Therefore, the ellipse fitting algorithm is used in the scale line detection part.

[0076] Step 5: Rotate the scale lines. First, vote on the angles between all scale lines and the horizontal direction to calculate the optimal angle, and then rotate them according to the optimal angle. The specific algorithm is as follows:

[0077] 1. Count the rotation angles of all scale lines, divide 360 degrees into 72 equal intervals, and count the number of rotation angles in each interval;

[0078] 2. Correspondingly merge the number of rotation angles in the latter half of the 72 intervals into the first 36 intervals, and retain the values in the first 36 intervals;

[0079] 3. Calculate the proportion of the number of rotation angles in each interval to the total number of all rotation angles, sort them, find the rotation angle interval with the largest proportion, and determine whether the proportion meets the preset threshold. If the condition is met, go to 4; otherwise, directly go to Step 9;

[0080] 4. Calculate the average value of the rotation angle interval with the largest proportion, and use the mean method to determine the optimal rotation angle;

[0081] 5. According to the optimal rotation angle, select or discard the contours, and rotate the retained contours so that the major axes of the ellipses are vertically arranged, which is convenient for subsequent calculations.

[0082] Step 6: Projection. Project the center points of the rotated ellipses along the y-axis direction, and divide the image into multiple regions along this direction. Use a histogram to record the sum of the number of center points contained in each region, and judge whether the maximum value of the sum of the number of center points in each region is greater than 5 and greater than 30% of the total sum of the number of center points in all regions. If the conditions are met, this region is the main region of the scale lines in the image. When calculating the distance between the scale lines later, only consider solving within the main region, and directly enter Step 7. If the conditions are not met, jump to Step 9.

[0083] Step 7: Mapping. Process the center points of the found main region so that they are mapped from the original coordinate points to new coordinate points. The mapping relationship is as follows:

[0084] The original point coordinates (x, y) = (i, j), and the mapped point coordinates (x, y) obtained after mapping = (-1000, i);

[0085] Among them, -1000 in the new coordinate points is a randomly set value, and it will be re-assigned and adjusted later. The ordinate value after mapping corresponds to the abscissa value of the original point before mapping, that is, the difference between the ordinate values in the mapped coordinates is the distance between the scale lines. The reason for performing the mapping operation is that the distance between the scale lines to be calculated is only related to the abscissa in the original coordinates and has nothing to do with the ordinate. Mapping it to the new coordinates is beneficial for subsequent operations.

[0086] Step 8: Line fitting. The specific algorithm is as follows: Traverse all the above mapped points. For each point i, perform all the following steps in sequence.

[0087] 1. Calculate the distance between the current point and the next point. This distance is denoted as the step size step, and judge whether the step size step is between 10 and 35. The reason for setting 10 - 35 is to limit the number of scale lines between the current point and the next point to avoid missing too many scale lines. If the condition is met, enter 2; otherwise, repeat 1 starting from the next point. Since the coordinates of all points on the x-axis are -1000, the distance between two points is the coordinate difference on the y-axis;

[0088] 2. If 1 holds, then traverse all the remaining points and calculate the distances (the coordinate differences on the y-axis) between the current point and all the remaining points. Make conditional judgments based on the calculated distances to screen out points with relatively high credibility (exemplarily, if the estimated distance between scale lines is 10, the integer parts of the ratios of the obtained distances to 10 are generally different), to prevent the situation of particularly scattered distribution. (Note: When the current point is the first point, use l1, l2, l3,... l n , where n is the total number of points - 1, to represent the distances between the first point and the subsequent 1st, 2nd,... nth points; when the current point is the second point, use l -1 , l1, l2,... l n , where n is the total number of points - 2, to represent the distances between the second point and the previous 1st point, and between the second point and the subsequent 1st, 2nd,... nth points. The obtained distances can be positive or negative. A positive value indicates that the point is after the current point, and a negative value indicates that the point is before the current point);

[0089] 3. According to the ratio between the distance from this point to the current point in 2 and the step size step, reassign the x-coordinate of the mapped points after screening, taking the integer value here; exemplarily, if the ratios are 1.1, 3.8, 4.9, 6.1, and 9.3; the integer values taken are 1, 4, 5, 6, and 9 respectively, and use these integer values as the x-coordinates of the mapped points after screening.

[0090] 4. Since conditional screening is performed during the process of adjusting the x-coordinate, it is necessary to re-judge here whether the number of mapped points after screening is greater than or equal to 5. If the condition is met, proceed to 5; otherwise, start calculating the next point from 1;

[0091] 5. Fit a straight line using the coordinates of the screened points. Let the slope of the fitted straight line be k i , and the intercept be b i , then the straight line is y = k i x + b i , then for any two points (x1, y1) and (x2, y2), the following formula holds:

[0092] (When the two points are adjacent, x1 - x2 = 1)

[0093] At this time, the least squares method is used to fit a straight line to obtain a set of values for k and b. If the number of both k and b is 0, then proceed to Step Nine. Otherwise, for each set of k and b, record the sum of the differences between the actual ordinate values of all points and the corresponding ordinate values on the fitted straight line (exemplarily, an actual coordinate is (3, 7.1), the fitted straight line is y = 2x + 1, and its ordinate value on the fitted straight line is 7, and the difference from the actual ordinate is 0.1, and calculate the differences of all points in this way). Take the average value and set it as the average error when i is the current point. The above 5 steps are the algorithm for calculating the slope of the straight line when i is the current point. After that, the slope value corresponding to the straight line with the minimum average error is the final slope value.

[0094] Step Nine: Scale mask image processing. When the slope of the straight line is not calculated in Step Eight, the following operations need to be performed on the scale mask image obtained in Step One in sequence, and then start calculating from Step Two above to Step Eight until the slope is calculated. The image processing operations in this step include: 1. Magnify the scale mask image by 2 times; 2. Reduce the scale mask image by 1 / 2; 3. Perform dilation operations on the scale mask image in eight directions: down, up, left, right, bottom - right, top - left, bottom - left, and top - right in sequence with a certain kernel size until the slope is calculated; 4. Perform dilation operations on the scale mask image in eight directions: down, up, left, right, bottom - right, top - left, bottom - left, and top - right in sequence with different kernel sizes until the slope is calculated. The operations in this step are to solve the problems of broken lines or adhesion between lines during scale detection. The sizes of the kernels used in 3 and 4 are different to detect scales of different lengths, so the sizes used are different. If the slope is finally calculated, then proceed to Step Ten. Otherwise, directly exit the program and output an exception.

[0095] Step Ten: Image resolution correction. The absolute value of the finally calculated slope is the distance between the scales. Since the resolution is the number of pixels per inch, the distance between the scales can be converted into the resolution. At this time, according to the need, the magnification or reduction factor required for the image can be calculated to complete the correction of the image resolution.

[0096] A specific method for adjusting the image resolution according to the scale graduation lines provided by an embodiment of the present invention. Input an image. First, use a segmentation detection model to segment all the graduation lines in the image to obtain a scale mask image. Then, perform binarization processing on the scale mask image, perform ellipse fitting on the graduation lines in the binary image, judge whether it meets the conditions according to the contour information, then solve the optimal rotation angle of the graduation lines and rotate them. After that, project the center points of the rotated graduation lines and judge whether the number of center points meets the conditions. Then, perform mapping and line fitting on all the center points. If the slope cannot be calculated, first perform a limited number of processes on the scale mask image and loop through the entire program again until the slope is calculated. Then, adjust the resolution of the image, and finally output the image to end the operation. The present invention combines a deep learning algorithm with a traditional image processing algorithm to propose a more robust algorithm for calculating the distance between adjacent graduation lines. This algorithm converts the distance into the calculation of the slope. The abscissa of the points participating in the line fitting is a multiple of the distance between the detected graduation lines, and the ordinate is the distance between the graduation lines. Whether there is a problem of missing detection of the graduation lines or not, the slope formed by the above points remains unchanged. Then, adjust the resolution of the image according to this value, and the adjustment effect is good.

[0097] In one embodiment, the present invention also provides a device for adjusting the image resolution according to the scale graduation lines, as Figure 4 shown, including:

[0098] An image preprocessing module 41, configured to preprocess the image to be adjusted to obtain a contour image including the contour information of the graduation lines; wherein, the image preprocessing module 41 segments the image to be adjusted through a pre-trained image segmentation model to obtain a scale mask image including only the background and the graduation lines; then binarizes the scale mask image to obtain a binary image; and finally extracts the contour of the binary image to obtain a contour image including the contour of the graduation lines.

[0099] An image fitting module 42, configured to perform ellipse fitting on the contour of each graduation line in the contour image, fit each graduation line into an ellipse, and use the center point of each ellipse as the center point of the graduation line.

[0100] A graduation line rotation module 43, configured to rotate the fitted graduation lines so that the major axis of the ellipse is parallel to the vertical direction.

[0101] A slope acquisition module 44, configured to perform line fitting on the center points of each rotated graduation line to obtain the slope of the fitted line;

[0102] In one embodiment, the slope acquisition module 44 maps the center point of each scale line to obtain the mapped center point, where the ordinate of the mapped center point is the abscissa of the center point before mapping, and the abscissas of all the mapped center points are arbitrary values and the same; adjusts the abscissa of the mapped center point according to the ordinate of the mapped center point, and after adjustment, the abscissas of all the mapped center points are different integers; performs linear fitting on the adjusted center points. Among them, adjusting the abscissa of the mapped center point according to the ordinate of the mapped center point includes: for any mapped center point, calculating the first step distance between the current point and the next point, where the first step distance is the difference between the ordinate of the next point and the ordinate of the current point; if the first step distance is within a preset range, calculating the first relative distance between the current point and all the remaining center points; assigning the abscissa of the current point to 0, calculating the first ratio of the first relative distance to the first step distance, and taking the integer of the first ratio as the abscissa of the center point corresponding to the first relative distance.

[0103] In another embodiment, the slope acquisition module 44 maps the center point of each scale line to obtain the mapped center point, where the abscissa of the mapped center point is the abscissa of the center point before mapping, and the ordinates of all the mapped center points are arbitrary values and the same; adjusts the ordinate of the mapped center point according to the abscissa of the mapped center point, and after adjustment, the abscissas of all the mapped center points are different integers; performs linear fitting on the adjusted center points. Among them, adjusting the ordinate of the mapped center point according to the abscissa of the mapped center point includes: for any mapped center point, calculating the second step distance between the current point and the next point, where the second step distance is the difference between the abscissa of the next point and the abscissa of the current point; if the second step distance is within a preset range, calculating the second relative distance between the current point and all the remaining center points; assigning the ordinate of the current point to 0, calculating the second ratio of the second relative distance to the second step distance, and taking the integer of the second ratio as the ordinate of the center point corresponding to the second relative distance.

[0104] The distance calculation module 45 is configured to obtain the distance between scale lines according to the slope; specifically, for the straight line fitted with any center point as the current point, the distance calculation module 45 calculates the sum of the differences between the ordinates corresponding to all points on the fitted straight line and the actual ordinates, or calculates the sum of the differences between the abscissas corresponding to all points on the fitted straight line and the actual abscissas; the average difference of the calculated sum is used as the average error of the current point; the slope of the fitted straight line with the minimum average error is selected as the distance between scale lines, or the reciprocal of the slope of the fitted straight line with the minimum average error is selected as the distance between scale lines. It should be noted that in the slope acquisition module 44, when the mapped abscissa remains unchanged, the reciprocal of the slope is used as the distance between scale lines, and when the mapped ordinate is the abscissa before mapping, the slope is used as the distance between scale lines.

[0105] A resolution adjustment module 46 is configured to adjust the resolution of an image to be adjusted according to the distance between scale lines. Adjusting the resolution according to the distance between scale lines is a very mature technical solution in the art and will not be introduced herein.

[0106] An image dilation module 47 is configured to detect whether the number of scale lines is greater than a preset number during the process of obtaining the slope of the fitted straight line; if not, perform a dilation operation on the image to be adjusted so that the number of scale lines is greater than the preset number.

[0107] An apparatus for adjusting the resolution of an image according to scale lines of a ruler provided by an embodiment of the present invention. An image preprocessing module preprocesses the image to be adjusted to obtain a contour image including the contours of the scale lines; an image fitting module performs ellipse fitting on each scale line contour in the contour image to fit each scale line into an ellipse; a scale line rotation module rotates the fitted scale lines so that the major axis of the ellipse is parallel to the vertical direction; a slope acquisition module performs straight line fitting on the center points of each rotated scale line to obtain the slope of the fitted straight line; a distance calculation module obtains the distance between the scale lines according to the slope; the resolution adjustment module adjusts the resolution of the image to be adjusted according to the distance between the scale lines. The image dilation module performs a dilation operation on the image to be adjusted so that the number of scale lines is greater than the preset number. The apparatus provided by the embodiment of the present invention uses the slope of the straight line fitted by the center points of the scale lines to obtain the distance between the scale lines. Whether there is a problem of missed detection of the scale lines or not, the slope of the straight line formed by the center points of the scale lines remains unchanged. Therefore, the distance obtained according to the slope will not change due to the missing of scale lines, and the finally calculated distance has a small difference from the actual distance, and the effect of adjusting the image resolution according to the obtained distance is good.

[0108] In one embodiment, the embodiment of the present invention provides a storage medium, including:

[0109] A processor;

[0110] A memory for executing instructions executable by the processor;

[0111] The processor is configured to perform the method for adjusting the resolution of an image according to the scale lines of a ruler provided in the above embodiment. Since this method has been described in detail in the above embodiment, it will not be elaborated herein.

[0112] In the embodiments of the present invention, the storage medium stores the executable instructions of the processor. When the processor executes the executable instructions, it can obtain the distance between scale lines according to the slope of the straight line fitted by the center points of the scale lines. Regardless of whether there is a problem of missed detection of scale lines, the slope of the straight line formed by the center points of the scale lines remains unchanged. Therefore, the distance between scale lines obtained according to the slope will not change due to the missing or omission of scale lines. Finally, the calculated distance has a small difference from the actual distance, and the adjustment of the image resolution based on the obtained distance has a good effect.

[0113] It can be understood that the same or similar parts in the above embodiments can be referred to each other. For the content not detailed in some embodiments, reference can be made to the same or similar content in other embodiments.

[0114] It should be noted that in the description of the present application, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of the present application, unless otherwise specified, the meaning of "a plurality" refers to at least two.

[0115] Any process or method description in the flowchart or described in other ways herein can be understood as representing a module, segment, or part of code including one or more executable instructions for implementing a specific logical function or process. The scope of the preferred embodiments of the present application includes additional implementations, where the functions can be executed in a substantially simultaneous manner or in the reverse order according to the involved functions, rather than in the order shown or discussed. This should be understood by those skilled in the technical field of the embodiments of the present application.

[0116] It should be understood that each part of the present application can be implemented by hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, any one or a combination of the following well-known technologies in the art can be used: discrete logic circuits with logic gate circuits for implementing logical functions on data signals, application-specific integrated circuits with appropriate combinational logic gate circuits, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.

[0117] Those of ordinary skill in the technical field of the present application can understand that all or part of the steps carried by the methods in the above embodiments can be completed by instructing relevant hardware through a program. The program can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiments.

[0118] In addition, each functional unit in various embodiments of the present application may be integrated into a processing module, may exist physically alone for each unit, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. When the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.

[0119] The above-mentioned storage medium may be a read-only memory, a magnetic disk, an optical disc, or the like.

[0120] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples", etc. means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in a suitable manner in any one or more embodiments or examples.

[0121] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and should not be construed as limiting the present application. Those of ordinary skill in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present application.

Claims

1. A method for adjusting the image resolution according to the scale graduation lines, characterized in that, The method includes the following steps: Preprocess the image to be adjusted to obtain a contour image containing the contour information of the scale lines; Perform ellipse fitting on the contour of each scale line in the contour image, fit each scale line into an ellipse, and use the center point of each ellipse as the center point of the scale line; Rotate the fitted scale lines so that the major axis of the ellipse is parallel to the vertical direction; Perform linear fitting on the center points of each rotated scale line to obtain the slope of the fitted line. Among them, performing linear fitting on the center points of each rotated scale line includes: mapping the center point of each scale line to obtain a mapped center point, where the ordinate of the mapped center point is the abscissa of the center point before mapping, and the abscissas of all mapped center points are arbitrary values and the same; adjusting the abscissa of the mapped center point according to the ordinate of the mapped center point, and after adjustment, the abscissas of all mapped center points are different integers; performing linear fitting on the adjusted center points; The adjusting the abscissa of the mapped center point according to the ordinate of the mapped center point includes: for any mapped center point, calculating the first step length distance between the current point and the next point, where the first step length distance is the difference between the ordinate of the next point and the ordinate of the current point; if the first step length distance is within a preset range, calculating the first relative distance between the current point and all the remaining center points; adjusting the abscissa of the current point to 0, calculating the first ratio of the first relative distance to the first step length distance, and taking the integer part of the first ratio as the abscissa of the center point corresponding to the first relative distance; Obtaining the distance between the scale lines according to the slope includes: for the line fitted with any center point as the current point, calculating the sum of the differences between the ordinates corresponding to all points on the fitted line and the actual ordinates, or calculating the sum of the differences between the abscissas corresponding to all points on the fitted line and the actual abscissas; taking the average difference of the calculated sum as the average error of the current point; selecting the slope of the fitted line with the minimum average error as the distance between the scale lines; Adjust the resolution of the image to be adjusted according to the distance between the scale lines.

2. The method according to claim 1, characterized in that: The preprocessing the image to be adjusted to obtain a contour image containing the scale line contours includes: Segment the image to be adjusted through a pre-trained image segmentation model to obtain a scale mask image including only the background and scale lines; Binarize the scale mask image to obtain a binarized image; Extract the contour of the binarized image to obtain a contour image containing the scale line contours.

3. The method according to claim 1, characterized in that: The performing linear fitting on the center points of each rotated scale line further includes: Mapping the center point of each scale line to obtain a mapped center point, where the abscissa of the mapped center point is the abscissa of the center point before mapping, and the ordinates of all mapped center points are arbitrary values and the same; Adjusting the ordinate of the mapped center point according to the abscissa of the mapped center point, and after adjustment, the ordinates of all mapped center points are different integers; Performing linear fitting on the adjusted center points.

4. The method according to claim 3, characterized in that: Adjusting the ordinate of the center point before mapping according to the abscissa of the center point after mapping includes: For any center point after mapping, calculate the second step length distance between the current point and the next point, where the second step length distance is the difference between the abscissa of the next point and the abscissa of the current point; If the second step length distance is within a preset range, calculate the second relative distance between the current point and all the remaining center points; Adjust the ordinate of the current point to 0, calculate the second ratio of the second relative distance to the second step length distance, and take the integer part of the second ratio as the ordinate of the center point corresponding to the second relative distance.

5. The method according to claim 3, characterized in that: Obtaining the distance between the scale lines according to the slope includes: For a straight line fitted with any center point as the current point, calculate the sum of the differences between the ordinates corresponding to all points on the fitted straight line and the actual ordinates, or calculate the sum of the differences between the abscissas corresponding to all points on the fitted straight line and the actual abscissas; The average difference of the calculated sum is used as the average error of the current point; Select the reciprocal of the slope of the fitted straight line with the smallest average error as the distance between the scale lines.

6. The method according to any one of claims 1 - 3, characterized in that, In the process of obtaining the slope of the fitted straight line, it also includes: Detect whether the number of scale lines is greater than a preset number; If it is not greater than, perform a dilation operation on the image to be adjusted so that the number of scale lines is greater than the preset number.

7. An apparatus for adjusting the image resolution according to the scale graduation lines, characterized in that, It includes: An image preprocessing module for preprocessing the image to be adjusted to obtain a contour image containing the contour information of the scale lines; An image fitting module for performing elliptical fitting on the contour of each scale line in the contour image, fitting each scale line into an ellipse, and taking the center point of each ellipse as the center point of the scale line; A scale line rotation module for rotating the fitted scale lines so that the major axis of the ellipse is parallel to the vertical direction; A slope acquisition module for performing linear fitting on the center points of each rotated scale line to obtain the slope of the fitted straight line; specifically, for mapping the center points of each scale line to obtain the center points after mapping, where the ordinate of the center point after mapping is the abscissa of the center point before mapping, and the abscissas of all center points after mapping are arbitrary values and the same; adjusting the abscissa of the center point after mapping according to the ordinate of the center point after mapping, and the abscissas of all center points after adjustment are different integers; Performing linear fitting on the adjusted center points; adjusting the abscissa of the center point after mapping according to the ordinate of the center point after mapping includes: for any center point after mapping, calculate the first step length distance between the current point and the next point, where the first step length distance is the difference between the ordinate of the next point and the ordinate of the current point; if the first step length distance is within a preset range, calculate the first relative distance between the current point and all the remaining center points; adjust the abscissa of the current point to 0, calculate the first ratio of the first relative distance to the first step length distance, and take the integer part of the first ratio as the abscissa of the center point corresponding to the first relative distance; A distance calculation module, configured to obtain the distance between the scale lines according to the slope; specifically, for a straight line fitted with any center point as the current point, calculate the sum of the differences between the ordinates corresponding to all points on the fitted straight line and the actual ordinates, or calculate the sum of the differences between the abscissas corresponding to all points on the fitted straight line and the actual abscissas; the average difference of the calculated sums is used as the average error of the current point; the slope of the fitted straight line with the smallest average error is selected as the distance between the scale lines. A resolution adjustment module, configured to adjust the resolution of the image to be adjusted according to the distance between the scale lines.

8. A storage medium, characterized in that, Comprising: A processor; A memory for executing the executable instructions of the processor; The processor is configured to execute the method according to any one of claims 1-6.

Citation Information

Patent Citations

  • Image detection-based two-dimensional characteristic size measurement method

    CN102425989A

  • A method and apparatus for measuring image magnification

    CN109215068A