Digital image edge length measurement linear chromatic aberration maximum gradient adjustment method and system

By drawing a long-measuring straight line between the edges of the image and calculating the maximum gradient of the color difference to adjust the coordinates of the line endpoints, the problem of large image edge measurement error in the prior art is solved, and more accurate and easy-to-implement image edge measurement is achieved.

CN119941600APending Publication Date: 2025-05-06GUIZHOU POWER GRID CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411780456.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-05
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

The prior art has large errors in measuring and calculating the dimensions between the edges of objects on pictures, mainly due to inaccurate measurements due to human eye parallax and operational errors.

Method used

By drawing a length-measuring line between the edges of the object to be measured, and calculating the maximum color difference gradient of the end point along the front and reverse directions of the straight line, adjusting the starting point and end point coordinates of the straight line according to the maximum color difference gradient, so as to accurately measure the dimensions between the edges of the image.

Benefits of technology

It effectively reduces measurement errors, improves the accuracy and ease of use of image edge length measurement, and reduces the labor intensity of the measuring person.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119941600A_ABST
    Figure CN119941600A_ABST
Patent Text Reader

Abstract

The invention discloses a digital image edge length measurement straight line chromatic aberration maximum gradient adjustment method and system, and relates to the technical field of image measurement, and the method comprises the steps: importing a digital image of a to-be-measured object; drawing a length measurement straight line and recording starting point pixel coordinates and ending point pixel coordinates of the straight line; calculating the color difference maximum gradient of the end point of the length measurement straight line; adjusting the starting point and end point coordinates of the length measurement straight line according to the maximum gradient of chromatic aberration; and calculating and outputting the length of the measurement straight line to obtain the edge moment of the image. According to the method for automatically adjusting the maximum gradient of the color difference between the length measurement straight line end points between the digital image edges, the pixel points with the maximum gradient of the color difference are solved by calculating the gradient of the color difference of the pixel points in a certain range at the two end points of the length measurement straight line, a new length measurement straight line is formed, the parallax and operation error of people are corrected, and the accuracy is improved. The digital image edge length measurement is accurate and easy to implement, and the labor intensity of a measurer is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of image measurement, and in particular to a method and system for adjusting the maximum gradient of linear color difference in length measurement of digital image edges. Background Art

[0002] Usually, when measuring and calculating the size (pixels) between the edges of an object in a picture, a straight line is drawn between the edges of the image with the mouse, and then the size between the edges of the object is obtained based on the pixel length of the straight line. Although this measurement is convenient and easy to implement, it has a large error. Since the human eye has unclear image boundaries when looking at pictures, people cannot accurately control the mouse point to the pixel point of the image boundary when moving the mouse, so the error in measuring the size between the image edges is large. Summary of the invention

[0003] In view of the above-mentioned problems, the present invention is proposed.

[0004] Therefore, the technical problem solved by the present invention is to reduce the size error between the edges of measured and calculated images, correct the parallax and operation errors of humans, make the length measurement of digital image edges accurate and easy to implement, and reduce the labor intensity of the measurer.

[0005] In order to solve the above technical problems, the present invention provides the following technical solutions: a method for adjusting the maximum gradient of linear color difference in edge length measurement of digital images, comprising:

[0006] Import the digital image of the object to be tested;

[0007] Input automatic color difference gradient to automatically calculate the number of pixels;

[0008] Draw a length measuring line between the edges of the object to be measured and record the pixel coordinates of the starting point and the end point of the line;

[0009] Calculate the maximum color difference gradient of the endpoints in the range of automatically calculated pixel points along the forward and reverse directions of the length measuring line;

[0010] Adjust the starting and ending coordinates of the length measurement line according to the maximum gradient of the color difference;

[0011] Calculate and output the length of the measured straight line to obtain the image edge moment.

[0012] As a preferred solution of the method for automatically adjusting the maximum gradient of the color difference of the endpoints of the length measuring straight line between digital image edges described in the present invention, the starting pixel coordinates of the length measuring straight line are the initial point of the line, and the end pixel coordinates are the end point of the line.

[0013] As a preferred solution of the method for automatically adjusting the maximum gradient of the color difference of the endpoints of the length measuring straight line between the edges of the digital image described in the present invention, wherein: the calculation of the maximum gradient of the color difference of the endpoints of the length measuring straight line includes calculating the color difference of the endpoints of the vertical line, by calculating the color difference of each pixel point in the vertical direction within the range of automatically calculating the number of pixels in front and back of the endpoint and finding the maximum value;

[0014] Calculate the color difference of the endpoints of the horizontal line by automatically calculating the color difference of each pixel in the horizontal direction and finding the maximum value;

[0015] The color difference of the endpoints of the oblique straight line is calculated. According to the different slopes, the color difference of the corresponding pixel points is calculated within the range of the number of pixels automatically calculated in the positive and negative directions of the endpoints in the oblique straight line direction and the maximum value is updated.

[0016] As a preferred solution of the method for automatically adjusting the maximum gradient of the color difference of the endpoints of the straight line measuring the length between the edges of the digital image described in the present invention, the color difference calculation of the vertical line endpoints includes adjusting the y coordinates of the line start point and the line end point up and down within the range of automatically calculating the number of pixel points, calculating the color difference of each pixel point and comparing it with the previous pixel point, and updating the maximum color difference value;

[0017] The color difference calculation of the horizontal line endpoints includes adjusting the x coordinates of the line start point and the line end point left and right within the range of automatically calculated pixel points, calculating the color difference of each pixel point and comparing it with the previous pixel point, and updating the maximum color difference value.

[0018] As a preferred solution of the method for automatically adjusting the maximum gradient of the color difference of the endpoints of the length measuring straight line between the edges of the digital image described in the present invention, wherein: the color difference calculation of the oblique straight line endpoints includes calculating the oblique line equation according to the slope k and the intercept b;

[0019] Adjust the coordinates of the pixels around the start and end points of the straight line in the range of automatically calculated pixel points, calculate the color difference of each pixel and update the maximum color difference value.

[0020] As a preferred solution of the method for automatically adjusting the maximum gradient of the color difference of the endpoints of the straight line measuring the length between the edges of the digital image described in the present invention, when the absolute value of the slope k is equal to 1, the color difference of the pixel points around the starting point and the end point is calculated by positively and negatively shifting the x coordinate of the endpoint by 1 point by point and the positively and negatively shifting the y coordinate by 1 point by point within the range of automatically calculated pixel points, the maximum color difference is found and the coordinates of the straight line endpoint are adjusted;

[0021] When the absolute value of the slope k is greater than 1, the y coordinates of the endpoints are offset by 1 in the positive and negative directions within the range of automatically calculated pixel points. The x coordinates of the endpoints are calculated and rounded according to the equation of the inclined straight line. The color difference of the corresponding pixel points is calculated and the maximum color difference in the vertical direction is updated.

[0022] When the absolute value of the slope k is less than 1, the x-coordinate of the endpoint is offset by 1 point by point within the range of automatically calculated pixel points, the y-coordinate of the endpoint is calculated and rounded according to the equation of the inclined straight line, the color difference of the corresponding pixel point is calculated, and the maximum color difference in the horizontal direction is updated.

[0023] As a preferred solution of the method for automatically adjusting the maximum gradient of the color difference of the endpoints of the digital image edge measurement line described in the present invention, the image edge moment includes the difference between the red and green components of each pixel, and the color difference of each pixel is accumulated and compared, and finally the coordinates of the endpoints of the straight line that best represent the edge features of the measured object are determined to calculate the measured length.

[0024] Another object of the present invention is to provide a digital image edge measurement straight line color difference maximum gradient adjustment system, which can solve the parallax and operation error problems in the existing manual measurement method by constructing a digital image edge measurement straight line color difference maximum gradient adjustment system, automatically adjust the endpoint coordinates, and thus achieve more accurate digital image edge size measurement.

[0025] In order to solve the above technical problems, the present invention provides the following technical solutions: a digital image edge length measurement straight line color difference maximum gradient adjustment system, comprising: an image import module, a pixel point calculation module, a straight line drawing module, a color difference calculation module, an endpoint adjustment module and a measurement output module;

[0026] The image import module is used to import the digital image of the object to be measured;

[0027] The pixel point calculation module is used to input the automatic color difference gradient to automatically calculate the number of pixels;

[0028] The straight line drawing module is used to draw a length measuring straight line between the edges of the object to be measured and record the starting pixel coordinates and the ending pixel coordinates of the straight line;

[0029] The color difference calculation module is used to calculate the maximum color difference gradient of the endpoints in the range of automatically calculating the number of pixels along the forward and reverse directions of the length measuring line;

[0030] The endpoint adjustment module is used to adjust the starting point and end point coordinates of the length measurement line according to the maximum gradient of the color difference;

[0031] The measurement output module is used to calculate and output the length of the measurement line to obtain the image edge moment.

[0032] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the method for automatically adjusting the maximum gradient of the color difference of the endpoints of the length measuring straight lines between the edges of a digital image are implemented as described above.

[0033] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the method for automatically adjusting the maximum gradient of the color difference of the endpoints of the length-measured straight lines between the edges of a digital image as described above.

[0034] Beneficial effects of the present invention: The method for automatically adjusting the maximum gradient of the color difference of the endpoints of the length measuring line between the edges of a digital image provided by the present invention calculates the color difference gradient of the pixel points in a certain range at the two end points of the length measuring line, solves the pixel point with the maximum gradient of the color difference, forms a new length measuring line, corrects the parallax and operation errors of humans, makes the length measurement of the edge of the digital image accurate and easy to implement, and reduces the labor intensity of the measurer. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.

[0036] Figure 1 An overall flow chart of a method for adjusting the maximum gradient of linear color difference of digital image edge length measurement provided by an embodiment of the present invention.

[0037] Figure 2 This is an overall structural diagram of a digital image edge length measurement and linear color difference maximum gradient adjustment system provided by the second embodiment of the present invention. DETAILED DESCRIPTION

[0038] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the drawings of the specification. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary persons in the art without creative work should fall within the scope of protection of the present invention.

[0039] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.

[0040] Example 1

[0041] Reference Figure 1 , which is an embodiment of the present invention, provides a method for adjusting the maximum gradient of straight line color difference of edge length measurement of digital image, comprising:

[0042] Import the digital image of the object to be tested;

[0043] Input automatic color difference gradient to automatically calculate the number of pixels;

[0044] Draw a length measuring line between the edges of the object to be measured and record the pixel coordinates of the starting point and the end point of the line;

[0045] Calculate the maximum color difference gradient of the endpoints in the range of automatically calculated pixel points along the forward and reverse directions of the length measuring line;

[0046] Adjust the starting and ending coordinates of the length measurement line according to the maximum gradient of the color difference;

[0047] Calculate and output the length of the measured straight line to obtain the image edge moment.

[0048] The pixel coordinates of the starting point of the length measuring line are the initial point of the line, and the pixel coordinates of the end point are the end point of the line.

[0049] Calculating the maximum color difference gradient of the endpoints of the measuring straight line includes calculating the color difference of the endpoints of the vertical line, by calculating the color difference of each pixel point within the range of automatically calculating the number of pixels in the vertical direction in front and back of the endpoint and finding the maximum value;

[0050] Calculate the color difference of the endpoints of the horizontal line by automatically calculating the color difference of each pixel in the horizontal direction and finding the maximum value.

[0051] The color difference of the endpoints of the oblique straight line is calculated. According to the different slopes, the color difference of the corresponding pixel points is calculated within the range of the number of pixels automatically calculated in the positive and negative directions of the endpoints in the oblique straight line direction and the maximum value is updated.

[0052] The color difference calculation of the vertical line endpoints includes adjusting the y coordinates of the line start point and the line end point up and down within the range of automatically calculated pixel points, calculating the color difference of each pixel point and comparing it with the previous pixel point, and updating the maximum color difference value;

[0053] The color difference calculation of the horizontal line endpoints includes adjusting the x coordinates of the line start point and the line end point left and right within the range of automatically calculated pixel points, calculating the color difference of each pixel point and comparing it with the previous pixel point, and updating the maximum color difference value.

[0054] The color difference calculation of the endpoints of the oblique straight line includes calculating the oblique line equation according to the slope k and the intercept b;

[0055] Adjust the coordinates of the pixels around the start and end points of the straight line in the range of automatically calculated pixel points, calculate the color difference of each pixel and update the maximum color difference value.

[0056] When the absolute value of the slope k is equal to 1, the color difference of the pixels around the starting point and the end point is calculated by shifting the x coordinate of the endpoint by 1 point by point and the y coordinate by 1 point by point within the range of automatically calculated pixel points, the maximum color difference is found and the coordinates of the straight line endpoint are adjusted;

[0057] When the absolute value of the slope k is greater than 1, the y coordinates of the endpoints are offset by 1 in the positive and negative directions within the range of automatically calculated pixel points. The x coordinates of the endpoints are calculated and rounded according to the equation of the inclined straight line. The color difference of the corresponding pixel points is calculated and the maximum color difference in the vertical direction is updated.

[0058] When the absolute value of the slope k is less than 1, the x-coordinate of the endpoint is offset by 1 point by point within the range of automatically calculated pixel points, the y-coordinate of the endpoint is calculated and rounded according to the equation of the inclined straight line, the color difference of the corresponding pixel point is calculated, and the maximum color difference in the horizontal direction is updated.

[0059] The image edge moments include accumulating and comparing the color difference of each pixel based on the difference between the red and green components of each pixel, and finally determining the coordinates of the endpoints of the straight line that best represents the edge features of the measured object, and calculating the measured length.

[0060] Example 2

[0061] Reference Figure 2 , which is an embodiment of the present invention, provides a digital image edge length measurement straight line color difference maximum gradient adjustment system, comprising:

[0062] An image import module 100, a pixel point calculation module 200, a straight line drawing module 300, a color difference calculation module 400, an endpoint adjustment module 500 and a measurement output module 600;

[0063] The image import module 100 is used to import the digital image of the object to be measured;

[0064] The pixel point calculation module 200 is used to input the automatic color difference gradient and automatically calculate the number of pixels;

[0065] The straight line drawing module 300 is used to draw a length measuring straight line between the edges of the object to be measured and record the starting pixel coordinates and the ending pixel coordinates of the straight line;

[0066] The color difference calculation module 400 is used to calculate the maximum color difference gradient of the endpoints in the range of automatically calculated pixel points along the forward and reverse directions of the length measurement line;

[0067] The endpoint adjustment module 500 is used to adjust the starting point and end point coordinates of the length measurement line according to the maximum gradient of the color difference;

[0068] The measurement output module 600 is used to calculate and output the length of the measurement line to obtain the image edge moment.

[0069] Example 3

[0070] An embodiment of the present invention is different from the first two embodiments in that:

[0071] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.

[0072] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in conjunction with such instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in conjunction with such instruction execution systems, devices or apparatuses.

[0073] More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be a paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering or, if necessary, processing in another suitable manner, and then stored in a computer memory.

[0074] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of 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, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0075] Example 4

[0076] As an embodiment of the present invention, a method for adjusting the maximum gradient of linear color difference in edge length measurement of a digital image is provided. In order to verify the beneficial effects of the present invention, a scientific demonstration is carried out through simulation experiments.

[0077] Step 1. Import the digital image file into the picture frame of the computer picture file browser;

[0078] Step 2. Use the mouse to draw a straight line between the edges of the object image on the calculation picture to be measured. The system remembers the pixel coordinates of the starting point of the straight line ("line initial point") and the pixel coordinates of the end point of the straight line ("line end point")

[0079] Step 3. Measure the maximum color difference gradient at the end point of the straight line and adjust the calculation

[0080] Step 3.1 Define variables

[0081] Given the “starting point of the line”, “ending point of the line” and “number of pixels ws”, the number of pixels ws is a system-given value and can be input through the input port.

[0082] Define the "start point of line" and "end point of line",

[0083] Calculate the image width w and image height h,

[0084] Define color 1 and color 2,

[0085] Define point gray value 1 and point gray value 2,

[0086] Define the maximum color difference DiffMax1 of the starting point of the line = 0 and the maximum color difference DiffMax2 of the end point of the line = 0,

[0087] Define the coordinates of the starting point of the line (x00, y00) and the end point of the line (x01, y01).

[0088] Step 3.2 Calculate the endpoints of the vertical line

[0089] Define color array a (2 times the number of pixels + 1)

[0090] Define color array c (2 times the number of pixels + 1)

[0091] It should be noted that the group number a() is the color of each pixel point automatically collected at the "starting point of the line", and the group number C() is the color of each pixel point automatically collected at the "ending point of the line".

[0092] i is gradually increased from 1 to 2 times the number of pixels, where i is an integer, i = 1, 2, 3, 4, 5 to 2 times the number of pixels, and the following calculations are performed respectively.

[0093] {nx1=x coordinate of the line's initial point, ny1=y coordinate of the line's initial point + number of pixels ws-i,

[0094] Color a(i) = color of image point (nx1,ny1),

[0095] If i>1, color difference diff=(a(i-1) red + a(i-1) green - a(i) red - a(i) green) absolute value, if the maximum color difference DiffMax1 at the starting point of the line < color difference diff, then

[0096] The maximum color difference at the starting point of the line DiffMax1 = color difference diff, x00 = nx1, y00 = ny1 (1)}

[0097] i is gradually increased from 1 to 2 times the number of pixels, and the following calculations are performed respectively.

[0098] {nx2 = x coordinate of the end point of the line, ny2 = y coordinate of the end point of the line + number of pixels ws-i,

[0099] Color c(i) = color of image point (nx2,ny2),

[0100] If i>1, color difference diff=(c(i-1) red + c(i-1) green - c(i) red - c(i) green) absolute value, if the maximum color difference DiffMax2 of the end point of the line < color difference diff, then

[0101] The maximum color difference at the end of the line DiffMax2 = color difference diff, x01 = nx2, y01 = ny2 (2)}

[0102] The starting point coordinates of the length measuring straight line are (x00, y00), and the end point coordinates of the length measuring straight line are (x01, y01).

[0103] {} represents a loop, a(i) represents the color of the i-th pixel point of the automatic volume set of the “starting point of the line”, and c(i) represents the color of the i-th pixel point of the automatic volume set of the “end point of the line”.

[0104] Step 3.2 Calculate the endpoints of the horizontal line

[0105] Define color array a (2 times the number of pixels + 1)

[0106] Define color array c (2 times the number of pixels + 1)

[0107] i is gradually increased from 1 to 2 times the number of pixels, and the following calculations are performed respectively.

[0108] {ny1=y coordinate of the line's initial point, nx1=x coordinate of the line's initial point + number of pixels ws-i,

[0109] Color a(i) = color of image point (nx1,ny1),

[0110] If i>1, color difference diff=(a(i-1) red + a(i-1) green - a(i) red - a(i) green) absolute value, if the maximum color difference DiffMax1 at the starting point of the line < color difference diff, then

[0111] The maximum color difference at the starting point of the line DiffMax1 = color difference diff, x00 = nx1, y00 = ny1 (3)}

[0112] i is gradually increased from 1 to 2 times the number of pixels, and the following calculations are performed respectively.

[0113] {ny2=y coordinate of the end point of the line, nx2=x coordinate of the end point of the line + number of pixels ws-i,

[0114] Color c(i) = color of image point (nx2,ny2),

[0115] If i>1, color difference diff=(c(i-1) red + c(i-1) green - c(i) red - c(i) green) absolute value, if the maximum color difference DiffMax2 of the end point of the line < color difference diff, then

[0116] The maximum color difference at the end of the line DiffMax2 = color difference diff, x01 = nx2, y01 = ny2 (4)}

[0117] The starting point coordinates of the length measuring straight line are (x00, y00), and the end point coordinates of the length measuring straight line are (x01, y01).

[0118] Step 3.3 Calculate the endpoints of the oblique straight line

[0119] The equation of the inclined straight line is y=kx+b

[0120] Slope k = (y coordinate of the line's initial point - y coordinate of the line's end point) / (x coordinate of the line's initial point - x coordinate of the line's end point),

[0121] b = y coordinate of the line's initial point - k × x coordinate of the line's initial point

[0122] Step 3.3.1 Calculate the endpoints of the inclined straight line when the absolute value of the slope k = 1

[0123] It should be noted that since digital images are described by pixels, mathematically y=kx+b can describe any point on any straight line on the plane, but this is not the case with digital images. X and Y can only represent an integer pixel. When the slope is greater than 1, y can only move one pixel each time it is calculated, and X can only be rounded; when the slope is less than 1, X can only move one pixel each time it is calculated, and y can only be rounded; when the slope is equal to 1, both X and Y can move one pixel each time they are calculated.

[0124] Define color array a (2 times the number of pixels + 1)

[0125] Define color array c (2 times the number of pixels + 1)

[0126] i is gradually increased from 1 to 2 times the number of pixels, and the following calculations are performed respectively.

[0127] {nx1=x coordinate of the initial point of the line + number of pixels ws-i,ny1=k×nx1+b,

[0128] Color a(i) = color of image point (nx1,ny1),

[0129] If i>1, color difference diff=(a(i-1) red + a(i-1) green - a(i) red - a(i) green) absolute value, if the maximum color difference DiffMax1 at the starting point of the line < color difference diff, then

[0130] The maximum color difference at the starting point of the line DiffMax1 = color difference diff, x00 = nx1, y00 = ny1 (5)}

[0131] i is gradually increased from 1 to 2 times the number of pixels, and the following calculations are performed respectively.

[0132] {nx2=x coordinate of the end point of the line+number of pixels ws-i,ny2=k×nx2+b,

[0133] Color c(i) = color of image point (nx2,ny2),

[0134] If i>1, color difference diff=(c(i-1) red + c(i-1) green - c(i) red - c(i) green) absolute value, if the maximum color difference DiffMax2 of the end point of the line < color difference diff, then

[0135] The maximum color difference at the end point of the line DiffMax2 = color difference diff, x01 = nx2, y01 = ny2 (6)}

[0136] The starting point coordinates of the length measuring straight line are (x00, y00), and the end point coordinates of the length measuring straight line are (x01, y01).

[0137] Step 3.3.2 Calculate the endpoints of the inclined straight line when the absolute value of the slope k is greater than 1

[0138] n=absolute value of the integer of (number of pixels xs / slope k)+1

[0139] Define color array a (2 times n+1)

[0140] Define color array c (2 times n+1)

[0141] i is gradually increased from 1 to 2 times n, and the following calculations are performed respectively

[0142] {nx1=(ni) / k+x coordinate of the initial point of the line, ny1=k×nx1+b,

[0143] Color a(i) = color of image point (nx1,ny1),

[0144] If i>1, color difference diff=(a(i-1) red + a(i-1) green - a(i) red - a(i) green) absolute value, if the maximum color difference DiffMax1 at the starting point of the line < color difference diff, then

[0145] The maximum color difference at the starting point of the line DiffMax1 = color difference diff, x00 = nx1, y00 = ny1 (7)}

[0146] i is gradually increased from 1 to 2 times n, and the following calculations are performed respectively

[0147] {nx2=(ni) / k+x coordinate of the end point of the line, ny2=k×nx2+b,

[0148] Color c(i) = color of image point (nx2,ny2),

[0149] If i>1, color difference diff=(c(i-1) red + c(i-1) green - c(i) red - c(i) green) absolute value, if the maximum color difference DiffMax2 of the end point of the line < color difference diff, then

[0150] The maximum color difference at the end of the line DiffMax2 = color difference diff, x01 = nx2, y01 = ny2 (8)}

[0151] The starting point coordinates of the length measuring straight line are (x00, y00), and the end point coordinates of the length measuring straight line are (x01, y01).

[0152] Step 3.3.3 Calculation of the endpoints of the inclined straight line when the absolute value of the slope k is less than 1

[0153] n = absolute value of the integer of (number of pixels xs × slope k) + 1

[0154] Define color array a (2 times n+1)

[0155] Define color array c (2 times n+1)

[0156] i is gradually increased from 1 to 2 times n, and the following calculations are performed respectively

[0157] {ny1=k×(ni)+y coordinate of the line initial point, nx1=(ny1+b) / k,

[0158] Color a(i) = color of image point (nx1,ny1),

[0159] If i>1, color difference diff=(a(i-1) red + a(i-1) green - a(i) red - a(i) green) absolute value, if the maximum color difference DiffMax1 at the starting point of the line < color difference diff, then

[0160] The maximum color difference at the starting point of the line DiffMax1 = color difference diff, x00 = nx1, y00 = ny1 (9)}

[0161] i is gradually increased from 1 to 2 times n, and the following calculations are performed respectively

[0162] {ny2=k×(ni)+y coordinate of the end point of the line, nx2=(ny2+b) / k,

[0163] Color c(i) = color of image point (nx2,ny2),

[0164] If i>1, color difference diff=(c(i-1) red + c(i-1) green - c(i) red - c(i) green) absolute value, if the maximum color difference DiffMax2 of the end point of the line < color difference diff, then

[0165] The maximum color difference at the end of the line DiffMax2 = color difference diff, x01 = nx2, y01 = ny2 (10)}

[0166] The starting point coordinates of the length measuring straight line are (x00, y00), and the end point coordinates of the length measuring straight line are (x01, y01).

[0167] Step 4. The coordinates of the two end points of the automatically adjusted length measuring line are (x00, y00) and (x01, y01) respectively. The length of the length measuring line is the edge moment of the image of the object to be measured.

[0168]

[0169] It should be noted that (x00, y00) is based on formulas (1)(3)(5)(7)(9); (x01, y01) is based on formulas (2)(4)(6)(8)(10).

[0170] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should be included in the scope of the claims of the present invention.

Claims

1. A method for adjusting the maximum gradient of linear color difference in edge length measurement of digital images, characterized in that: include: Import the digital image of the object to be tested; Input automatic color difference gradient to automatically calculate the number of pixels; Draw a length measuring line between the edges of the object to be measured and record the pixel coordinates of the starting point and the end point of the line; Calculate the maximum color difference gradient of the endpoints in the range of automatically calculated pixel points along the forward and reverse directions of the length measuring line; Adjust the starting and ending coordinates of the length measurement line according to the maximum gradient of the color difference; Calculate and output the length of the measured straight line to obtain the image edge moment.

2. The method for automatically adjusting the maximum gradient of color difference between the endpoints of the length measuring straight line between the edges of a digital image as claimed in claim 1, characterized in that: The pixel coordinates of the starting point of the length measuring line are the initial point of the line, and the pixel coordinates of the end point are the end point of the line.

3. The method for automatically adjusting the maximum gradient of color difference between the endpoints of the length measuring straight line between the edges of a digital image as claimed in claim 2, characterized in that: Calculating the maximum color difference gradient of the endpoints of the measuring straight line includes calculating the color difference of the endpoints of the vertical line, by calculating the color difference of each pixel point within the range of automatically calculating the number of pixels in the vertical direction in front and back of the endpoint and finding the maximum value; Calculate the color difference of the endpoints of the horizontal line by automatically calculating the color difference of each pixel in the horizontal direction and finding the maximum value; The color difference of the endpoints of the oblique straight line is calculated. According to the different slopes, the color difference of the corresponding pixel points is calculated within the range of the number of pixels automatically calculated in the positive and negative directions of the endpoints in the oblique straight line direction and the maximum value is updated.

4. The method for automatically adjusting the maximum gradient of color difference between the endpoints of the length measuring straight lines between the edges of a digital image as claimed in claim 3, characterized in that: The color difference calculation of the vertical line endpoints includes adjusting the y coordinates of the line start point and the line end point up and down within the range of automatically calculated pixel points, calculating the color difference of each pixel point and comparing it with the previous pixel point, and updating the maximum color difference value; The color difference calculation of the horizontal line endpoints includes adjusting the x coordinates of the line start point and the line end point left and right within the range of automatically calculated pixel points, calculating the color difference of each pixel point and comparing it with the previous pixel point, and updating the maximum color difference value.

5. The method for automatically adjusting the maximum gradient of color difference between the endpoints of the length measuring straight lines between the edges of a digital image as claimed in claim 4, characterized in that: The color difference calculation of the endpoints of the oblique straight line includes calculating the oblique line equation according to the slope k and the intercept b; Adjust the coordinates of the pixels around the start and end points of the straight line in the range of automatically calculated pixel points, calculate the color difference of each pixel and update the maximum color difference value.

6. The method for automatically adjusting the maximum gradient of color difference between the endpoints of the length measuring straight lines between the edges of a digital image as claimed in claim 5, characterized in that: When the absolute value of the slope k is equal to 1, the color difference of the pixels around the starting point and the end point is calculated by shifting the x coordinate of the endpoint by 1 point by point and the y coordinate by 1 point by point within the range of automatically calculated pixel points, the maximum color difference is found and the coordinates of the straight line endpoint are adjusted; When the absolute value of the slope k is greater than 1, the y coordinates of the endpoints are offset by 1 in the positive and negative directions within the range of automatically calculated pixel points. The x coordinates of the endpoints are calculated and rounded according to the equation of the inclined straight line. The color difference of the corresponding pixel points is calculated and the maximum color difference in the vertical direction is updated. When the absolute value of the slope k is less than 1, the x-coordinate of the endpoint is offset by 1 point by point within the range of automatically calculated pixel points, the y-coordinate of the endpoint is calculated and rounded according to the equation of the inclined straight line, the color difference of the corresponding pixel point is calculated, and the maximum color difference in the horizontal direction is updated.

7. The method for automatically adjusting the maximum gradient of color difference between the endpoints of the length measuring straight lines between the edges of a digital image as claimed in claim 1, characterized in that: The image edge moments include accumulating and comparing the color difference of each pixel based on the difference between the red and green components of each pixel, and finally determining the coordinates of the endpoints of the straight line that best represents the edge features of the measured object, and calculating the measured length.

8. A system using the method for automatically adjusting the maximum gradient of color difference at the endpoints of the length measuring straight lines between digital image edges as claimed in any one of claims 1 to 7, characterized in that: include: An image import module (100), a pixel point calculation module (200), a straight line drawing module (300), a color difference calculation module (400), an endpoint adjustment module (500), and a measurement output module (600); The image import module (100) is used to import a digital image of an object to be tested; The pixel point calculation module (200) is used to input automatic color difference gradient and automatically calculate the number of pixel points; The straight line drawing module (300) is used to draw a length measuring straight line between the edges of the object to be measured and record the starting pixel coordinates and the ending pixel coordinates of the straight line; The color difference calculation module (400) is used to calculate the maximum color difference gradient of the endpoints in the range of automatically calculating the number of pixels along the forward and reverse directions of the length measuring line; The endpoint adjustment module (500) is used to adjust the starting point and end point coordinates of the length measurement line according to the maximum gradient of the color difference; The measurement output module (600) is used to calculate and output the length of the measurement straight line to obtain the image edge moment.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method for automatically adjusting the maximum gradient of the color difference at the endpoints of the length measuring straight lines between edges of a digital image according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for automatically adjusting the maximum gradient of the color difference at the endpoints of the length measuring straight lines between edges of a digital image according to any one of claims 1 to 7 are implemented.