A method and related device for image compression and restoration
By performing edge point fitting and four-corner intersection coordinate calculations on the images captured by industrial cameras, the compressed image size is determined, and the problem of accuracy loss in the image compression process in the prior art is solved, and efficient and high-quality image compression and restoration effects are achieved.
Patent Information
- Application Number
- CN202411613761.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-13
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2044-11-13
AI Technical Summary
The prior art often suffers from loss of image accuracy during image compression, resulting in deviations from the original image from the restored image, affecting subsequent quality detection and analysis work.
By obtaining the original image taken by an industrial camera, fitting its edge point contour, obtaining multiple edge point fitting linear equations, calculating the coordinates and boundary fitting linear equations of the intersection of four corners, judging whether the compressed image size is correct, and compressing the original image based on the fitted data set.
The efficiency and quality of image compression and restoration are improved, ensuring that the compression process is based on the actual content and structure of the image, retaining important information, reducing unnecessary storage space, and determining in real time whether the size of the compressed image meets expectations.
Smart Images

Figure CN119136069B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of image processing technology, and in particular to a method and related device for image compression and restoration. Background Art
[0002] In the context of intelligent manufacturing, the new display industry has put forward higher requirements for the capture and storage of display screen images. In order to accurately capture and analyze every detail of the display screen, high-resolution cameras have become standard. The pictures taken by these cameras are often huge, and a set of image data can easily reach several GB or even tens of GB. For large-scale intelligent manufacturing workshops, such data storage requirements are undoubtedly a huge test for hardware resources. Traditional storage solutions, such as directly using large-capacity hard drives for storage, are simple and direct. Another solution is to compress the image through an algorithm to reduce the storage space occupied. Among them, for the second solution, the compression process of the existing compression algorithm is often accompanied by a loss of image accuracy, resulting in a deviation between the restored image and the original image, affecting the subsequent quality inspection and analysis work. Summary of the invention
[0003] The present application discloses a method and a related device for image compression and restoration, which are used to improve the efficiency and quality of image compression and restoration.
[0004] The first aspect of the present application discloses a method for image compression, comprising:
[0005] Acquire an original image, where the original image is an image taken by an industrial camera;
[0006] Fitting the edge point contours of the original image to obtain multiple edge point fitting straight line equations;
[0007] Performing row and column processing on the intersection points of the plurality of edge point fitting straight line equations to obtain the coordinates of the four corner intersection points;
[0008] Calculating four boundary fitting straight line equations of the original image;
[0009] Determining whether the size of the compressed image is correct according to the Euclidean distance between adjacent intersection points of the four corners, the length and width of the original image, and the compressed image ratio control threshold;
[0010] If the compressed image size is correct, the size and type of the original image, the coordinates of the intersections of the plurality of edge point fitting straight line equations, the coordinates of the four corner intersections and the four boundary fitting straight line equations are stored in the fitting data set;
[0011] The original image is compressed according to the fitting data set to obtain a compressed image.
[0012] Optionally, performing row and column processing on the intersections of the plurality of edge point fitting straight line equations to obtain the coordinates of the four corner intersections includes:
[0013] Taking the upper left corner of the original image as the origin, obtaining the intersection of the plurality of edge point fitting straight line equations;
[0014] Obtaining a minimum row coordinate value a1 and a maximum row coordinate value a2 of the intersection points of the plurality of edge point fitting straight line equations;
[0015] Obtaining a minimum column coordinate value b1 and a maximum column coordinate value b2 of the intersection points of the plurality of edge point fitting straight line equations;
[0016] Take the point (a1, b1) as the upper left intersection, the point (a1, b2) as the upper right intersection, the point (a2, b1) as the lower left intersection, and the point (a2, b2) as the lower right intersection.
[0017] Optionally, after judging whether the compressed image size is correct according to the Euclidean distances between adjacent four-corner intersections, the length and width of the original image, and the compressed image ratio control threshold, the method further includes:
[0018] If the compressed image size is incorrect, the image re-photographed by the industrial camera is obtained as a new original image.
[0019] Optionally, compressing the original image according to the fitting data set to obtain a compressed image includes:
[0020] Generating a convex polygonal envelope contour area on the original image according to the intersection points of the plurality of edge point fitting straight line equations;
[0021] Generate a completely black image of the same size and type as the original image, and crop the completely black image according to the convex polygon envelope contour area to obtain a cropped completely black image;
[0022] Filling the cropped all-black image with grayscale values to obtain a grayscale value image;
[0023] Performing image operations in a parallel iterative mode on the grayscale image and the original image to obtain a compressed image.
[0024] Optionally, performing image operation in a parallel iterative mode on the grayscale image and the original image to obtain a compressed image includes:
[0025] In a parallel iteration mode, losslessly intercepting the original image from four directions of up, down, left, and right according to the area of the gray value image to obtain an intercepted image;
[0026] The data of the captured image is stored in the grayscale image to obtain a compressed image.
[0027] Optionally, before fitting the edge point contour of the original image to obtain multiple edge point fitting straight line equations, the method further includes:
[0028] Obtaining transition edge points between the foreground and background of the original image by using an adaptive endpoint gradient algorithm;
[0029] 5% of the edge points at both ends of the transition edge points are removed, and the remaining edge points are retained on the original image as the edge points of the original image.
[0030] The second aspect of the present application discloses a method for image restoration, comprising:
[0031] Acquire a fitting data set and a compressed image, wherein the four corner intersection points in the fitting data set are respectively an upper left corner intersection point, a lower left corner intersection point, an upper right corner intersection point and a lower right corner intersection point, and the four boundary fitting straight line equations are respectively an upper boundary fitting straight line equation, a lower boundary fitting straight line equation, a left boundary fitting straight line equation and a right boundary fitting straight line equation;
[0032] Calculate the distance D1 from the upper left corner intersection to the upper boundary fitting straight line equation, the distance D2 from the lower left corner intersection to the left boundary fitting straight line equation, the distance D3 from the upper right corner intersection to the right boundary fitting straight line equation, and the distance D4 from the lower right corner intersection to the lower boundary fitting straight line equation;
[0033] Generate an upper left blank image according to the distance D1 and the distance D2;
[0034] Generate an upper right blank image according to the distance D1 and the distance D4;
[0035] Generate a lower left blank image according to the distance D2 and the distance D3;
[0036] Generate a lower right blank image according to the distance D3 and the distance D4;
[0037] Generate an upper blank image according to the distance D1 and the length value of the original image;
[0038] Generate a left blank image according to the distance D2 and the width value of the original image;
[0039] Generate a blank image according to the distance D3 and the length value of the original image;
[0040] Generate a right blank image according to the distance D4 and the width value of the original image;
[0041] Performing splicing and fusion processing on the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image to obtain a restored image;
[0042] The restored image and the original image are calibrated for image defect feature quantities.
[0043] Optionally, the step of performing splicing and fusing processing on the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image to obtain a restored image comprises:
[0044] Taking the upper left corner of the original image as the origin, calculating the offset of the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, and the right blank image;
[0045] According to the offset and the coordinates of the four corner intersections, the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image are spliced to obtain a spliced image;
[0046] Grayscale value interpolation is performed on the remaining area of the stitched image that fails to cover the entire image to obtain a restored image.
[0047] The third aspect of the present application discloses an image compression device, comprising:
[0048] An original image unit, used to obtain an original image, where the original image is an image taken by an industrial camera;
[0049] A fitting unit, used for fitting the edge point contour of the original image to obtain multiple edge point fitting straight line equations;
[0050] A row and column processing unit, used for performing row and column processing on the intersection points of the plurality of edge point fitting straight line equations to obtain the coordinates of the four corner intersection points;
[0051] A calculation unit, used for calculating the equations of four boundary fitting lines of the original image;
[0052] A judging unit, configured to judge whether the compressed image size is correct according to the Euclidean distance between adjacent four corner intersections, the length and width of the original image, and a compressed image ratio control threshold;
[0053] A storage unit, for storing the size and type of the original image, the coordinates of the intersection points of the plurality of edge point fitting straight line equations, the coordinates of the four corner intersection points and the four boundary fitting straight line equations into a fitting data set if the compressed image size is correct;
[0054] A compression unit is used to compress the original image according to the fitting data set to obtain a compressed image.
[0055] The fourth aspect of the present application discloses an image restoration device, comprising:
[0056] an acquisition unit, used to acquire the fitting data set and the compressed image obtained as in the first aspect, wherein the four corner intersection points in the fitting data set are respectively the upper left corner intersection point, the lower left corner intersection point, the upper right corner intersection point and the lower right corner intersection point, and the four boundary fitting straight line equations are respectively the upper boundary fitting straight line equation, the lower boundary fitting straight line equation, the left boundary fitting straight line equation and the right boundary fitting straight line equation;
[0057] a distance calculation unit, for respectively calculating the distance D1 from the upper left corner intersection to the upper boundary fitting straight line equation, the distance D2 from the lower left corner intersection to the left boundary fitting straight line equation, the distance D3 from the upper right corner intersection to the right boundary fitting straight line equation, and the distance D4 from the lower right corner intersection to the lower boundary fitting straight line equation;
[0058] A blank image unit is used to generate an upper left blank image according to the distance D1 and the distance D2; generate an upper right blank image according to the distance D1 and the distance D4; generate a lower left blank image according to the distance D2 and the distance D3; generate a lower right blank image according to the distance D3 and the distance D4; generate an upper blank image according to the distance D1 and the length value of the original image; generate a left blank image according to the distance D2 and the width value of the original image; generate a lower blank image according to the distance D3 and the length value of the original image; generate a right blank image according to the distance D4 and the width value of the original image;
[0059] a splicing unit, configured to splice and fuse the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image to obtain a restored image;
[0060] The calibration unit is used to calibrate the image defect feature quantity between the restored image and the original image.
[0061] A fifth aspect of the present application provides an electronic device, including:
[0062] Processor, memory, input-output unit, and bus;
[0063] The processor is connected to the memory, the input and output unit, and the bus;
[0064] The memory stores a program, and the processor calls the program to execute the first aspect and any optional image compression method of the first aspect or the second aspect and any optional image restoration method of the second aspect.
[0065] In a sixth aspect, the present application provides a computer-readable storage medium on which a program is stored. When the program is executed on a computer, the method of the first aspect and any optional image compression method of the first aspect or the second aspect and any optional image restoration method of the second aspect is performed.
[0066] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0067] The image compression method of the present application first obtains the original image, which is an image taken by an industrial camera; secondly, the edge point contour of the original image is fitted to obtain multiple edge point fitting straight line equations; then the intersection of the multiple edge point fitting straight line equations is processed in rows and columns to obtain the coordinates of the four corner intersections; then the four boundary fitting straight line equations of the original image are calculated; further, the compressed image size is judged to be correct based on the Euclidean distance between the adjacent four corner intersections, the length and width of the original image, and the compressed image ratio card control threshold; if the compressed image size is correct, the size and type of the original image, the coordinates of the intersection of the multiple edge point fitting straight line equations, the coordinates of the four corner intersections, and the four boundary fitting straight line equations are stored in the fitting data set; finally, the original image is compressed according to the fitting data set to obtain a compressed image. The present application performs fine fitting on the edge point contour of the original image, and the multiple edge point fitting straight line equations obtained can more accurately describe the geometric features in the image, especially the boundary information, can reduce the influence of noise and unnecessary details on subsequent processing, and improve the accuracy of image processing. The compressed size of the image is determined based on the coordinates of the four corner intersections and the boundary fitting straight line equation, ensuring that the compression process can be based on the actual content and structure of the image. Compared with simple proportional scaling, it can better retain the important information of the image and reduce unnecessary storage space. By calculating the Euclidean distance between adjacent four corner intersections and comparing it with the length, width and compression ratio of the original image, it can be judged in real time whether the size of the compressed image meets expectations. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0069] Figure 1 A schematic diagram of an embodiment of the image compression method of the present application;
[0070] Figure 2 A schematic diagram of another embodiment of the image compression method of the present application;
[0071] Figure 3 A schematic diagram of an embodiment of the method for image restoration of the present application;
[0072] Figure 4 A schematic diagram of another embodiment of the method for image restoration of the present application;
[0073] Figure 5 A schematic diagram of an embodiment of an image compression device of the present application;
[0074] Figure 6 A schematic diagram of an embodiment of the device for image restoration of the present application;
[0075] Figure 7 This is a schematic diagram of an embodiment of an electronic device of the present application. DETAILED DESCRIPTION
[0076] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0077] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0078] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0079] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0080] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0081] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.
[0082] In the context of intelligent manufacturing, the new display industry has put forward higher requirements for the capture and storage of display screen images. In order to accurately capture and analyze every detail of the display screen, high-resolution cameras have become standard. The pictures taken by these cameras are often huge, and a set of image data can easily reach several GB or even tens of GB. For large-scale intelligent manufacturing workshops, such data storage requirements are undoubtedly a huge test for hardware resources. Traditional storage solutions, such as directly using large-capacity hard drives for storage, are simple and direct. Another solution is to compress the image through an algorithm to reduce the storage space occupied. Among them, for the second solution, the compression process of the existing compression algorithm is often accompanied by a loss of image accuracy, resulting in a deviation between the restored image and the original image, affecting the subsequent quality inspection and analysis work.
[0083] Based on this, the present application discloses a method and related device for image compression and restoration, which are used to improve the efficiency and quality of image compression and restoration.
[0084] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0085] The method of the present application can be applied to a server, a device, a terminal or other devices with logic processing capabilities, and the present application does not limit this. For the convenience of description, the following description is made by taking the execution subject as an example of a terminal.
[0086] See also Figure 1 The present application provides an embodiment of an image compression method, comprising:
[0087] 101. Obtain an original image, where the original image is an image taken by an industrial camera;
[0088] In this embodiment, after the industrial camera and other related hardware in the intelligent manufacturing darkroom are installed and deployed, the industrial camera takes a picture of the product, and the image obtained by taking the picture is the original image. According to the needs of industrial production, industrial cameras are generally high-resolution cameras, so the memory resources occupied by the original image are also relatively large. The size of the image group composed of multiple original images is larger, and the hard disk storage requirements are higher. Therefore, in order to reduce the pressure on storage resources, the original image should be compressed.
[0089] 102. Fit the edge point contours of the original image to obtain multiple edge point fitting straight line equations;
[0090] In this embodiment, the edge of the original image is the area in the image where the grayscale or color changes most dramatically, and contains information such as the outline of the object in the image. The clarity and continuity of the edge have an important impact on image compression. In addition, there is a large amount of redundant information in the edge area. In order to ensure the quality of compression, it is necessary to first fit the edge point contour of the original image and obtain multiple edge point fitting straight line equations. The fitting process of the edge point contour makes the edge representation of the original image more concise and efficient. In the subsequent compression process, multiple edge point fitting straight line equations can be stored without storing the data of each edge point, thereby improving the compression efficiency. It should be noted that the obtained multiple edge point fitting straight line equations are as follows:
[0091] r∙N r +c∙N c -D ist =0;
[0092] Among them, (r, c) is the row and column coordinates of the edge point, N ris the vector of the normal equation of the fitted line corresponding to the row coordinate r, N c is the vector of the normal equation of the fitted line corresponding to the column coordinate c, D ist It is the distance from the origin of the coordinate system to the fitted straight line. The origin of the coordinate system is determined in advance according to actual needs when calculating the equation of the fitted straight line.
[0093] 103. Perform row and column processing on the intersection points of the linear equations of multiple edge points to obtain the coordinates of the four corner intersection points;
[0094] In this embodiment, the intersection of the four corners is one of the criteria for determining the size of the compressed image. The linear equations fitted by multiple edge points have eliminated redundant data, leaving important data that should be stored. The rectangular area formed by the intersection of the four corners can completely cover the important data, ensuring a lossless compressed image.
[0095] 104. Calculate the equations of four boundary fitting lines of the original image;
[0096] In this embodiment, the equations of the fitted lines of the four boundaries of the original image are calculated in order to subsequently calculate the distances from the four corner intersections to the four boundaries of the original image, and the specific compression size can be calculated based on the distances. The compression sizes are stored and sorted, and after obtaining the compression sizes of a large number of original images, a more reasonable unified compression size is summarized according to the data analysis algorithm, and the image can be compressed based on the unified compression size in the future, which reduces a lot of analysis and calculation time, and can also be adjusted on the basis of the unified compression size to improve the compression quality.
[0097] 105. Determine whether the compressed image size is correct according to the Euclidean distance between adjacent four corner intersections, the length and width of the original image, and the compressed image ratio control threshold;
[0098] In this embodiment, the basis for judging whether the compressed image size is correct is the compressed image ratio card control threshold inequality, as follows:
[0099] ;
[0100] Among them, d i (i=1,2,3,4) is the Euclidean distance between adjacent intersection points of the four corners, D x is the product of the original image length x and the mapping value, D y It is the product of the width y of the original image and the mapping value. The mapping value is the magnification of the original image when the industrial camera takes the image. L is the compression ratio control threshold.
[0101] According to the above-mentioned compressed image ratio card control threshold inequality, when the inequality holds, it means that the size of the compressed image is reasonable and meets the industrial production conditions; when the inequality does not hold, it means that there is a problem with the compressed image size, which may be due to the abnormal fitting of the edge point contour in step 102. A new original image taken by the industrial camera should be obtained again, and the new original image should be processed again according to the methods of steps 102 to 105.
[0102] 106. If the compressed image size is correct, the size and type of the original image, the coordinates of the intersection points of the multiple edge point fitting line equations, the coordinates of the four corner intersection points and the four boundary fitting line equations are stored in the fitting data set;
[0103] In this embodiment, if it is determined that it cannot be established in step 105, that is, the compressed image size is correct and the subsequent compression process can continue, the size and type of the original image obtained in step 101, the coordinates of the intersection of the multiple edge point fitting straight line equations obtained in step 102, the coordinates of the four corner intersections obtained in step 103, and the four boundary fitting straight line equations of the original image obtained in step 104 are stored in the fitting data set, so that the data in the fitting data set can be used to compress the image in the subsequent steps. It should be noted that the size, type and four boundary fitting straight line equations of the original image are used to ensure the quality of lossless compression, the coordinates of the intersection of the multiple edge point fitting straight line equations are used to confirm the range of important information in the original image, and the coordinates of the four corner intersections are used to specifically locate the compression position and limit the size of the compressed image.
[0104] 107. Compress the original image according to the fitted data set to obtain a compressed image.
[0105] In this embodiment, the polygonal envelope is formed according to the coordinates of the intersection of the equations of the multiple edge point fitting lines, and the coordinates of the four corner intersections are taken to generate a rectangular area, which covers the polygonal envelope. The original image is cropped with the rectangular area as the boundary, the original image content within the polygonal envelope is retained, and the part beyond the polygonal envelope is removed and discarded, and finally a compressed image is generated. The type of the compressed image is consistent with the original image. After cropping and appropriate data retention, the size of the compressed image is significantly smaller than the original image.
[0106] In this embodiment, the method of image compression first obtains the original image, which is an image taken by an industrial camera; secondly, the edge point contour of the original image is fitted to obtain multiple edge point fitting straight line equations; then the intersection of the multiple edge point fitting straight line equations is processed in rows and columns to obtain the coordinates of the four corner intersections; then the four boundary fitting straight line equations of the original image are calculated; further, the compressed image size is judged to be correct according to the Euclidean distance between the adjacent four corner intersections, the length and width of the original image, and the compressed image ratio card control threshold; if the compressed image size is correct, the size and type of the original image, the coordinates of the intersection of the multiple edge point fitting straight line equations, the coordinates of the four corner intersections, and the four boundary fitting straight line equations are stored in the fitting data set; finally, the original image is compressed according to the fitting data set to obtain a compressed image. This application performs fine fitting on the edge point contour of the original image, and the multiple edge point fitting straight line equations obtained can more accurately describe the geometric features in the image, especially the boundary information, can reduce the influence of noise and unnecessary details on subsequent processing, and improve the accuracy of image processing. The compressed size of the image is determined based on the coordinates of the four corner intersections and the boundary fitting straight line equation, ensuring that the compression process can be based on the actual content and structure of the image. Compared with simple proportional scaling, it can better retain the important information of the image and reduce unnecessary storage space. By calculating the Euclidean distance between adjacent four corner intersections and comparing it with the length, width and compression ratio of the original image, it can be judged in real time whether the size of the compressed image meets expectations.
[0107] See also Figure 2 , the present application provides another embodiment of an image compression method, comprising:
[0108] 201. Obtain an original image, where the original image is an image taken by an industrial camera;
[0109] Step 201 in this embodiment is similar to step 101 in the above embodiment and will not be described again here.
[0110] 202. Obtain transition edge points between the foreground and background of the original image through an adaptive endpoint gradient algorithm;
[0111] 203. Eliminate 5% of the edge points at both ends of the transition edge points, and keep the remaining edge points on the original image as the edge points of the original image;
[0112] In this embodiment, the adaptive endpoint gradient algorithm is an edge detection algorithm based on the gradient change of the image endpoint. In the original image, the edge is usually manifested as a sharp change in the gradient value. The adaptive endpoint gradient algorithm identifies these areas with significant gradient changes by calculating the gradient between each pixel in the image and its neighboring pixel points. The magnitude and direction of the gradient can indicate the strength and direction of the edge. The adaptive endpoint gradient algorithm first converts the original image into a grayscale image, because edge detection is usually performed on a grayscale image. Then, the gradient operator is used to calculate the gradient strength and direction of each pixel in the image. Which pixels belong to edge points is determined according to the magnitude of the gradient. Pixels whose gradient values exceed a preset threshold are considered edge points, and these points mark the transition between the foreground and the background. Then, 5% of the edge points at both ends of the transition edge points are removed, and the remaining edge points are retained on the original image as the edge points of the original image. For example, if there are 1000 edge points in total, 50 points are removed at the beginning and the end. Finally, the remaining edge points are regarded as the edge points of the optimized original image, and these points more accurately represent the transition area between the foreground and the background in the original image.
[0113] 204. Fitting the edge point contours of the original image to obtain multiple edge point fitting straight line equations;
[0114] Step 204 in this embodiment is similar to step 102 in the above embodiment and will not be described again here.
[0115] 205. Taking the upper left corner of the original image as the origin, obtaining the intersection of multiple edge point fitting straight line equations;
[0116] 206. Obtain the minimum row coordinate value a1 and the maximum row coordinate value a2 of the intersection points of the equations of the multiple edge point fitting lines;
[0117] 207. Obtain the minimum column coordinate value b1 and the maximum column coordinate value b2 of the intersection points of the equations of the multiple edge point fitting lines;
[0118] 208. Take point (a1, b1) as the upper left intersection point, point (a1, b2) as the upper right intersection point, point (a2, b1) as the lower left intersection point, and point (a2, b2) as the lower right intersection point;
[0119] In this embodiment, the row coordinates and column coordinates are sorted respectively, and the maximum and minimum values are taken, and then the maximum and minimum values of the row coordinates and the maximum and minimum values of the column coordinates are arranged and combined respectively to obtain the coordinates of the four corner intersections: the upper left corner intersection (a1, b1), the upper right corner intersection (a1, b2), the lower left corner intersection (a2, b1) and the lower right corner intersection (a2, b2). It should be noted that the compressed image size can be further optimized based on the coordinates of the four corner intersections, that is, the specified pixel size is set according to the inclination angle of the original image, and then the upper left corner intersection is expanded toward the second quadrant by a specified pixel size, the upper right corner intersection is expanded toward the first quadrant by a specified pixel size, the lower left corner intersection is expanded toward the third quadrant by a specified pixel size, and the lower right corner intersection is expanded toward the fourth quadrant by a specified pixel size, and the compressed size is reasonably expanded according to the specified pixel size to improve the compression accuracy.
[0120] 209. Calculate the equations of four boundary fitting lines of the original image;
[0121] Step 209 in this embodiment is similar to step 104 in the above embodiment and will not be described again here.
[0122] 210. Determine whether the size of the compressed image is correct according to the Euclidean distance between adjacent four corner intersections, the length and width of the original image, and the compressed image ratio control threshold;
[0123] 211. If the compressed image size is correct, the size and type of the original image, the coordinates of the intersection points of the multiple edge point fitting line equations, the coordinates of the four corner intersection points and the four boundary fitting line equations are stored in the fitting data set;
[0124] 212. If the compressed image size is incorrect, obtain an image re-photographed by an industrial camera as a new original image;
[0125] Steps 210 to 212 in this embodiment are similar to steps 105 to 106 in the above-mentioned embodiment, and are not described again here.
[0126] 213. Generate a convex polygonal envelope contour area on the original image according to the intersection of multiple edge point fitting straight line equations;
[0127] In this embodiment, edge points are fitted to obtain multiple edge point fitting straight line equations, and the multiple edge point fitting straight line equations are intertwined to generate multiple intersections. A convex polygonal envelope contour area is obtained by connecting the intersections clockwise or counterclockwise.
[0128] 214. Generate a completely black image of the same size and type as the original image, and crop the completely black image according to the convex polygon envelope contour area to obtain a cropped completely black image;
[0129] In the embodiment, a rectangular all-black image of the same size and type as the original image is generated, and then the all-black image is cropped according to the size and shape of the convex polygon envelope contour area in step 213 to obtain a cropped convex polygon all-black image, and the cropped all-black image will be used as a container to store the image content data on the original image.
[0130] 215. Fill the cropped all-black image with gray values to obtain a gray value image;
[0131] In this embodiment, the grayscale value filling is performed on the cropped all-black image in order to be able to store the image content data of the original image in the container of the cropped all-black image through an image algorithm. After the all-black image is filled with grayscale values, the grayscale value image can perform effective image operations with the original image, thereby storing the image content data on the original image in the container of the all-black image.
[0132] 216. In a parallel iteration mode, the original image is losslessly intercepted from four directions according to the gray value image area from top to bottom, left to right, to obtain an intercepted image;
[0133] In this embodiment, the parallel iteration mode refers to capturing the original image from four directions (up, down, left, and right) simultaneously or in parallel to obtain the captured image, so as to ensure the smoothness or consistency of the border of the captured image. Lossless capture means that the remaining image content data except the color on the original image is completely retained according to the shape of the area of the gray value image.
[0134] 217. Store the data of the captured image into a grayscale image to obtain a compressed image.
[0135] In this embodiment, after cropping, the data in the original image is stored in the gray value image to generate a compressed image, and the compressed image is stored. Storing the data of the original image in the form of a gray value image can further effectively remove redundant information and compress the image content and size.
[0136] In this embodiment, the image compression method first obtains an original image, which is an image taken by an industrial camera; obtains transition edge points between the foreground and the background of the original image through an adaptive endpoint gradient algorithm; removes 5% of the edge points at both ends of the transition edge points, and retains the remaining edge points on the original image as edge points of the original image; fits the edge point contours of the original image to obtain multiple edge point fitting straight line equations; takes the upper left corner position of the original image as the origin, obtains the intersection of the multiple edge point fitting straight line equations; obtains the minimum row coordinate a1 and the maximum row coordinate a2 of the intersection of the multiple edge point fitting straight line equations; obtains the minimum column coordinate b1 and the maximum column coordinate b2 of the intersection of the multiple edge point fitting straight line equations; takes point (a1, b1) as the upper left corner intersection, takes point (a1, b2) as the upper right corner intersection, takes point (a2, b1) as the lower left corner intersection, and takes point (a2, b2) as the lower right corner intersection; calculates the four boundary fitting straight line equations of the original image; and calculates the four boundary fitting straight line equations according to the four corners. The Euclidean distance between adjacent intersections, the length and width of the original image, and the compressed image ratio control threshold are used to determine whether the compressed image size is correct; if the compressed image size is correct, the size and type of the original image, the coordinates of the intersection of multiple edge point fitting straight line equations, the coordinates of the four corner intersections, and the four boundary fitting straight line equations are stored in the fitting data set; if the compressed image size is incorrect, the image re-photographed by the industrial camera is obtained as a new original image; a convex polygon envelope contour area is generated on the original image according to the intersection of multiple edge point fitting straight line equations; a full black image of the same size and type as the original image is generated, and the full black image is cropped according to the convex polygon envelope contour area to obtain a cropped full black image; the cropped full black image is filled with grayscale values to obtain a grayscale image; in a parallel iteration mode, the original image is losslessly intercepted from the four directions of up, down, left, and right according to the area of the grayscale image to obtain a intercepted image; the data of the intercepted image is stored in the grayscale image to obtain a compressed image. This application performs fine fitting on the edge point contours of the original image, and the obtained multiple edge point fitting straight line equations can more accurately describe the geometric features in the image, especially the boundary information, and can reduce the impact of noise and unnecessary details on subsequent processing, thereby improving the accuracy of image processing. The compressed size of the image is determined based on the coordinates of the four-corner intersection points and the boundary fitting straight line equations, ensuring that the compression process can be based on the actual content and structure of the image. Compared with simple proportional scaling, it can better retain important information of the image while reducing unnecessary storage space. By calculating the Euclidean distance between adjacent four-corner intersection points and comparing them with the length, width and compression ratio of the original image, it is possible to determine in real time whether the size of the compressed image meets expectations.
[0137] See also Figure 3 The present application provides an embodiment of a method for image restoration, comprising:
[0138] 301. Get Figure 1 or Figure 2 The fitting data set and the compressed image obtained in the illustrated embodiment, the four corner intersection points in the fitting data set are respectively the upper left corner intersection point, the lower left corner intersection point, the upper right corner intersection point and the lower right corner intersection point, and the four boundary fitting straight line equations are respectively the upper boundary fitting straight line equation, the lower boundary fitting straight line equation, the left boundary fitting straight line equation and the right boundary fitting straight line equation;
[0139] In this embodiment, the fitting data of step 106 or step 211 and the compressed image of step 107 or step 217 are obtained in order to restore the original image according to the size and type of the original image, the four corner intersections in the fitting data, the four boundary fitting line equations and the compressed image. The restoration direction is determined according to the type of the original image to ensure that the type of the restored image is consistent with the original image. Then, the data of the coordinates of the four corner intersections and the four boundary fitting line equations are extracted.
[0140] 302. Calculate the distance D1 from the upper left corner intersection to the upper boundary fitting straight line equation, the distance D2 from the lower left corner intersection to the left boundary fitting straight line equation, the distance D3 from the upper right corner intersection to the right boundary fitting straight line equation, and the distance D4 from the lower right corner intersection to the lower boundary fitting straight line equation;
[0141] In this embodiment, after extracting data in step 301, the distances from the four corner intersections to the corresponding boundary fitting straight line equations are first calculated according to the following formula:
[0142] ;
[0143] Among them, Di (i=1,2,3,4) is the distance from the intersection of the four corners to the corresponding boundary fitting straight line equation: when i=1, D1 is the distance from the upper left corner intersection to the upper boundary fitting straight line equation; when i=2, D2 is the distance from the lower left corner intersection to the left boundary fitting straight line equation; when i=3, D3 is the distance from the upper right corner intersection to the right boundary fitting straight line equation; when i=4, D4 is the distance from the lower right corner intersection to the lower boundary fitting straight line equation. (r', c') are the coordinates of the four corner intersections, N r’ is the vector of the normal equation of the boundary fitting line corresponding to the row coordinate r', N c’ is the vector of the normal equation of the boundary fitting line corresponding to the column coordinate c', D ist ' is the distance from the origin of the coordinate system to the fitting straight line. The origin of the coordinate system is selected according to actual needs.
[0144] 303. Generate an upper left blank image according to the distance D1 and the distance D2; generate an upper right blank image according to the distance D1 and the distance D4; generate a lower left blank image according to the distance D2 and the distance D3; generate a lower right blank image according to the distance D3 and the distance D4; generate an upper blank image according to the distance D1 and the length value of the original image; generate a left blank image according to the distance D2 and the width value of the original image; generate a lower blank image according to the distance D3 and the length value of the original image; generate a right blank image according to the distance D4 and the width value of the original image;
[0145] In this embodiment, in order to restore the size of the compressed image to the size of the original image, it is necessary to add multiple blank images around the compressed image to fill the size, and then fill the content of the blank images in the subsequent steps to restore the original image content. Therefore, first, the upper left blank image is generated with the distance D1 as the width and the distance D2 as the length, the upper right blank image is generated with the distance D1 as the width and the distance D4 as the length, the lower left blank image is generated with the distance D3 as the width and the distance D2 as the length, the lower right blank image is generated with the distance D3 as the width and the distance D4 as the length, the upper left blank image is generated with the distance D1 as the width and the distance D2 as the length, the upper blank image is generated with the distance D1 as the width and the length of the original image as the length, the left blank image is generated with the width of the original image as the width and the distance D2 as the length, the lower blank image is generated with the distance D3 as the width and the length of the original image as the length, and the right blank image is generated with the width of the original image as the width and the distance D4 as the length.
[0146] 304. Perform splicing and fusion processing on the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image to obtain a restored image;
[0147] In this embodiment, the multiple blank images generated in step 303 are spliced and fused with the compressed image to obtain a spliced image of the same size as the original image, and then the content on the blank image is filled according to algorithms such as gray value interpolation to achieve image restoration.
[0148] 305. Calibrate image defect feature quantities between the restored image and the original image.
[0149] In this embodiment, the image defect feature quantity calibration is to ensure that the restored image is visually and quantitatively consistent with the original image, and to minimize errors and distortions caused by compression, processing or restoration. Key feature information is extracted from the original image, which may include pixel value distribution, color histogram, texture features, shape features, etc. Similarly, corresponding feature information is extracted from the restored image for comparison with the features of the original image. The extracted original image features and restored image features are compared to analyze the differences between the two. If the difference between the restored image and the original image is too large, the restored image is repaired according to the original image, and the reason for the large difference is analyzed, and the reason is input into the image processing learning model. The image restoration method of this scheme is correspondingly optimized according to the algorithm output by the image processing learning model.
[0150] In this embodiment, the method for image restoration first obtains a fitting data set and a compressed image, wherein the four corner intersection points in the fitting data set are respectively an upper left corner intersection point, a lower left corner intersection point, an upper right corner intersection point and a lower right corner intersection point, and the four boundary fitting straight line equations are respectively an upper boundary fitting straight line equation, a lower boundary fitting straight line equation, a left boundary fitting straight line equation and a right boundary fitting straight line equation; respectively calculate a distance D1 from the upper left corner intersection point to the upper boundary fitting straight line equation, a distance D2 from the lower left corner intersection point to the left boundary fitting straight line equation, a distance D3 from the upper right corner intersection point to the right boundary fitting straight line equation, and a distance D4 from the lower right corner intersection point to the lower boundary fitting straight line equation; generate an upper left blank image according to the distance D1 and the distance D2; and generate a lower left blank image according to the distance D1 and the distance D4. The distance D4 generates an upper right blank image; the distance D2 and the distance D3 generate a lower left blank image; the distance D3 and the distance D4 generate a lower right blank image; the distance D1 and the length value of the original image generate an upper blank image; the distance D2 and the width value of the original image generate a left blank image; the distance D3 and the length value of the original image generate a lower blank image; the distance D4 and the width value of the original image generate a right blank image; the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image are spliced and fused to obtain a restored image; the restored image and the original image are calibrated for image defect feature quantities. This method can accurately determine the deviation between the image edge and the fitted straight line by calculating the distance from the intersection of the four corners to the equation of the fitted straight line of each boundary. These distance information are used to generate each blank image, thereby ensuring the high consistency of the restored image in the edge part and reducing the edge blur or distortion that may be caused by compression or processing. Secondly, blank images in eight directions are generated according to the distances from the four corner points to the border, and they are spliced and fused with the compressed image. This regional and targeted restoration method not only improves the integrity of the restored image, but also ensures a smooth transition between regions, avoiding seams or color differences caused by direct splicing. Calibration of image defect feature quantities between the restored image and the original image can further correct possible minor deviations or defects in the restored image, ensuring that the final image is close to or even reaches the quality of the original image.
[0151] See also Figure 4 , the present application provides another embodiment of an image restoration method, comprising:
[0152] 401, Get Figure 1 or Figure 2The fitting data set and the compressed image obtained in the illustrated embodiment, the four corner intersection points in the fitting data set are respectively the upper left corner intersection point, the lower left corner intersection point, the upper right corner intersection point and the lower right corner intersection point, and the four boundary fitting straight line equations are respectively the upper boundary fitting straight line equation, the lower boundary fitting straight line equation, the left boundary fitting straight line equation and the right boundary fitting straight line equation;
[0153] 402. Calculate the distance D1 from the upper left corner intersection to the upper boundary fitting straight line equation, the distance D2 from the lower left corner intersection to the left boundary fitting straight line equation, the distance D3 from the upper right corner intersection to the right boundary fitting straight line equation, and the distance D4 from the lower right corner intersection to the lower boundary fitting straight line equation;
[0154] 403. Generate an upper left blank image according to the distance D1 and the distance D2; generate an upper right blank image according to the distance D1 and the distance D4; generate a lower left blank image according to the distance D2 and the distance D3; generate a lower right blank image according to the distance D3 and the distance D4; generate an upper blank image according to the distance D1 and the length value of the original image; generate a left blank image according to the distance D2 and the width value of the original image; generate a lower blank image according to the distance D3 and the length value of the original image; generate a right blank image according to the distance D4 and the width value of the original image;
[0155] Steps 401 to 403 in this embodiment are similar to steps 301 to 303 in the above-mentioned embodiment, and are not described again here.
[0156] 404. Taking the upper left corner of the original image as the origin, calculate the offset of the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, and the right blank image;
[0157] In this embodiment, the specific steps of step 304 for stitching multiple blank images with the compressed image are as follows: take the upper left corner position of the rectangle of the original image as the origin, calculate the offsets of the multiple blank images, and calculate according to the size and origin position of each blank image: the row offset of the upper left blank image is 0, and the column offset is 0; the row offset of the upper right blank image is distance D2+the length value of the original image, and the column offset is 0; the row offset of the lower left blank image is 0, and the column offset is distance D1+the width value of the original image; the row offset of the lower right blank image is distance D2+the length value of the original image, and the column offset is distance D1+the width value of the original image; the row offset of the upper blank image is distance D2, and the column offset is 0; the row offset of the left blank image is 0, and the column offset is distance D1; the row offset of the lower blank image is distance D2, and the column offset is distance D1+the width value of the original image; the row offset of the right blank image is distance D2+the length value of the original image, and the column offset is distance D1. It should be noted that, relative to the origin of the upper left corner of the rectangle of the original image, the offset of the compressed image is: the row offset is the distance D2, and the column offset is the distance D1.
[0158] 405. According to the offset and the coordinates of the four corner intersections, the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image are spliced to obtain a spliced image.
[0159] In this embodiment, the plurality of blank images and the compressed image are arranged and combined according to the offset of each blank image calculated in step 405, so that the plurality of blank images and the compressed image can be seamlessly spliced together.
[0160] 406. Perform grayscale value interpolation on the remaining area of the spliced image that fails to cover the entire image to obtain a restored image;
[0161] In this embodiment, in the gray value interpolation algorithm, the gray value data of the pixel points to be interpolated in the remaining area that fails to cover the entire image can be set to 0 or set to a gray value similar to the nearest 4 adjacent points according to the specific situation. The gray value calculation formula similar to the nearest 4 adjacent points is as follows:
[0162] ;
[0163] Among them, (u, v) is the pixel to be interpolated, (u1, v1) is the first adjacent point, (u2, v1) is the second adjacent point, (u1, v2) is the third adjacent point, (u2, v2) is the fourth adjacent point, G(u, v) is the gray value of the pixel to be interpolated, G(Q 11 ) is the gray value of the first adjacent point, G(Q 21) is the gray value of the second adjacent point, G(Q 21 ) is the gray value of the third adjacent point, G(Q 22 ) is the gray value of the fourth adjacent point.
[0164] 407. Calibrate image defect feature quantities between the restored image and the original image.
[0165] Step 407 in this embodiment is similar to step 305 in the above embodiment and will not be described again here.
[0166] In this embodiment, a fitting data set and a compressed image are first obtained, wherein the four corner intersection points in the fitting data set are respectively the upper left corner intersection point, the lower left corner intersection point, the upper right corner intersection point and the lower right corner intersection point, and the four boundary fitting straight line equations are respectively the upper boundary fitting straight line equation, the lower boundary fitting straight line equation, the left boundary fitting straight line equation and the right boundary fitting straight line equation; the distance D1 from the upper left corner intersection point to the upper boundary fitting straight line equation, the distance D2 from the lower left corner intersection point to the left boundary fitting straight line equation, the distance D3 from the upper right corner intersection point to the right boundary fitting straight line equation, and the distance D4 from the lower right corner intersection point to the lower boundary fitting straight line equation are respectively calculated; an upper left blank image is generated according to the distance D1 and the distance D2; an upper right blank image is generated according to the distance D1 and the distance D4; a lower left blank image is generated according to the distance D2 and the distance D3; a lower right blank image is generated according to the distance D3 and the distance D4; and a lower right blank image is generated according to the distance D1 and the original image. The upper blank image is generated according to the length value of the original image; the left blank image is generated according to the distance D2 and the width value of the original image; the lower blank image is generated according to the distance D3 and the length value of the original image; the right blank image is generated according to the distance D4 and the width value of the original image; the upper left corner position of the original image is used as the origin to calculate the offset of the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, and the right blank image; according to the offset and the coordinates of the four corner intersections, the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image are spliced to obtain a spliced image; the gray value of the remaining area that the spliced image fails to cover the entire image is interpolated to obtain a restored image; the restored image and the original image are calibrated for image defect feature quantities. This method can accurately determine the deviation between the image edge and the fitted straight line by calculating the distance from the four corner intersections to the respective boundary fitting straight line equations. This distance information is used to generate each blank image, thereby ensuring the high consistency of the restored image at the edge and reducing the edge blur or distortion that may occur during compression or processing. Secondly, blank images in eight directions are generated based on the distance from the four corner points to the boundary, and they are spliced and fused with the compressed image. This regional and targeted restoration method not only improves the integrity of the restored image, but also ensures a smooth transition between regions, avoiding seams or color differences caused by direct splicing. Calibration of the image defect feature quantity between the restored image and the original image can further correct the slight deviations or defects that may exist in the restored image, ensuring that the final image is close to or even reaches the level of the original image in quality.
[0167] See also Figure 5 The present application provides an embodiment of an image compression device, comprising:
[0168] The original image unit 501 is used to obtain an original image, where the original image is an image taken by an industrial camera;
[0169] A fitting unit 502 is used to fit the edge point contour of the original image to obtain multiple edge point fitting straight line equations;
[0170] A row and column processing unit 503 is used to perform row and column processing on the intersection points of the multiple edge point fitting straight line equations to obtain the coordinates of the four corner intersection points;
[0171] A calculation unit 504 is used to calculate the equations of four boundary fitting lines of the original image;
[0172] A judging unit 505 is used to judge whether the compressed image size is correct according to the Euclidean distance between adjacent four corner intersections, the length and width of the original image, and the compressed image ratio control threshold;
[0173] The storage unit 506 is used to store the size and type of the original image, the coordinates of the intersection points of the multiple edge point fitting straight line equations, the coordinates of the four corner intersection points and the four boundary fitting straight line equations into the fitting data set if the compressed image size is correct;
[0174] The compression unit 507 is used to compress the original image according to the fitting data set to obtain a compressed image.
[0175] Optionally, the row and column processing unit 503 is specifically used for:
[0176] Taking the upper left corner of the original image as the origin, obtain the intersection of multiple edge point fitting straight line equations;
[0177] Get the minimum row coordinate value a1 and the maximum row coordinate value a2 of the intersection points of the fitting straight line equations of multiple edge points;
[0178] Get the minimum column coordinate value b1 and the maximum column coordinate value b2 of the intersection points of the fitting straight line equations of multiple edge points;
[0179] Take the point (a1, b1) as the upper left intersection, the point (a1, b2) as the upper right intersection, the point (a2, b1) as the lower left intersection, and the point (a2, b2) as the lower right intersection.
[0180] Optionally, after the judging unit 505, the method further includes:
[0181] The re-acquisition unit 508 is used to acquire an image re-photographed by the industrial camera as a new original image if the compressed image size is incorrect.
[0182] Optionally, the compression unit 507 is specifically used for:
[0183] Generate a convex polygonal envelope contour area on the original image according to the intersection points of multiple edge point fitting straight line equations;
[0184] Generate a completely black image with the same size and type as the original image, and crop the completely black image according to the convex polygon envelope contour area to obtain a cropped completely black image;
[0185] Fill the cropped all-black image with gray values to obtain a gray value image;
[0186] The grayscale image and the original image are subjected to image operations in a parallel iterative mode to obtain a compressed image.
[0187] Optionally, the compression unit 507 is specifically used for:
[0188] In a parallel iteration mode, the original image is losslessly intercepted from four directions according to the gray value image area to obtain the intercepted image;
[0189] The data of the captured image is stored in a grayscale image to obtain a compressed image.
[0190] Optionally, before the fitting unit 502, the method further includes:
[0191] The transition edge point unit 509 is used to obtain the transition edge points between the foreground and the background of the original image by using an adaptive endpoint gradient algorithm;
[0192] The elimination unit 510 is used to eliminate 5% of the edge points at both ends of the transition edge points, and retain the remaining edge points on the original image as the edge points of the original image.
[0193] See also Figure 6 The present application provides an embodiment of an image compression device, comprising:
[0194] Acquisition unit 601, used to acquire Figure 1 or Figure 2 The fitting data set and the compressed image obtained in the illustrated embodiment, the four corner intersection points in the fitting data set are respectively the upper left corner intersection point, the lower left corner intersection point, the upper right corner intersection point and the lower right corner intersection point, and the four boundary fitting straight line equations are respectively the upper boundary fitting straight line equation, the lower boundary fitting straight line equation, the left boundary fitting straight line equation and the right boundary fitting straight line equation;
[0195] The distance calculation unit 602 is used to respectively calculate the distance D1 from the upper left corner intersection point to the upper boundary fitting straight line equation, the distance D2 from the lower left corner intersection point to the left boundary fitting straight line equation, the distance D3 from the upper right corner intersection point to the right boundary fitting straight line equation, and the distance D4 from the lower right corner intersection point to the lower boundary fitting straight line equation;
[0196] The blank image unit 603 is used to generate an upper left blank image according to the distance D1 and the distance D2; generate an upper right blank image according to the distance D1 and the distance D4; generate a lower left blank image according to the distance D2 and the distance D3; generate a lower right blank image according to the distance D3 and the distance D4; generate an upper blank image according to the distance D1 and the length value of the original image; generate a left blank image according to the distance D2 and the width value of the original image; generate a lower blank image according to the distance D3 and the length value of the original image; generate a right blank image according to the distance D4 and the width value of the original image;
[0197] The stitching unit 604 is used to stitch and fuse the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image to obtain a restored image;
[0198] The calibration unit 605 is used to calibrate the image defect feature quantity between the restored image and the original image.
[0199] Optionally, the splicing unit 604 is specifically used for:
[0200] Taking the upper left corner of the original image as the origin, calculate the offset of the upper left blank image, upper right blank image, lower left blank image, lower right blank image, upper blank image, left blank image, lower blank image, and right blank image;
[0201] According to the offset and the coordinates of the four corner intersections, the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image are spliced to obtain a spliced image;
[0202] The grayscale value of the remaining area where the stitched image fails to cover the entire image is interpolated to obtain a restored image.
[0203] See also Figure 7 , the present application provides an electronic device, comprising:
[0204] Processor 701 , memory 702 , input / output unit 703 , and bus 704 .
[0205] The processor 701 is connected to the memory 702 , the input and output unit 703 , and the bus 704 .
[0206] The memory 702 stores a program, and the processor 701 calls the program to execute the following steps: Figure 1 , Figure 2 and Figure 3 and Figure 4 Image compression and restoration methods in .
[0207] The present application provides a computer-readable storage medium, on which a program is stored, and when the program is executed on a computer, the program performs the following steps: Figure 1 , Figure 2 and Figure 3 and Figure 4 Image compression and restoration methods in .
[0208] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0209] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0210] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0211] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0212] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or 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 a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the various embodiments of the present application. 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. Various media that can store program codes.
Claims
1. A method for image compression, characterized in that: include: Acquire an original image, where the original image is an image taken by an industrial camera; Fitting the edge point contours of the original image to obtain multiple edge point fitting straight line equations; Performing row and column processing on the intersection points of the plurality of edge point fitting straight line equations to obtain the coordinates of the four corner intersection points; Calculating four boundary fitting straight line equations of the original image; Determining whether the size of the compressed image is correct according to the Euclidean distance between adjacent intersection points of the four corners, the length and width of the original image, and the compressed image ratio control threshold; If the compressed image size is correct, the size and type of the original image, the coordinates of the intersections of the plurality of edge point fitting straight line equations, the coordinates of the four corner intersections and the four boundary fitting straight line equations are stored in the fitting data set; The original image is compressed according to the fitting data set to obtain a compressed image.
2. The method according to claim 1, characterized in that The performing row and column processing on the intersection points of the plurality of edge point fitting straight line equations to obtain the coordinates of the four corner intersection points comprises: Taking the upper left corner of the original image as the origin, obtaining the intersection of the plurality of edge point fitting straight line equations; Obtaining a minimum row coordinate value a1 and a maximum row coordinate value a2 of the intersection points of the plurality of edge point fitting straight line equations; Obtaining a minimum column coordinate value b1 and a maximum column coordinate value b2 of the intersection points of the plurality of edge point fitting straight line equations; Take the point (a1, b1) as the upper left intersection, the point (a1, b2) as the upper right intersection, the point (a2, b1) as the lower left intersection, and the point (a2, b2) as the lower right intersection.
3. The method according to claim 1, characterized in that After judging whether the compressed image size is correct according to the Euclidean distances between adjacent four-corner intersections, the length and width of the original image, and the compressed image ratio control threshold, the method further includes: If the compressed image size is incorrect, the image re-photographed by the industrial camera is obtained as a new original image.
4. The method according to claim 1, characterized in that: The compressing the original image according to the fitting data set to obtain a compressed image comprises: Generating a convex polygonal envelope contour area on the original image according to the intersection points of the plurality of edge point fitting straight line equations; Generate a completely black image of the same size and type as the original image, and crop the completely black image according to the convex polygon envelope contour area to obtain a cropped completely black image; Filling the cropped all-black image with grayscale values to obtain a grayscale value image; Performing image operations in a parallel iterative mode on the grayscale image and the original image to obtain a compressed image.
5. The method according to claim 4, characterized in that The performing of image operations in a parallel iterative mode on the grayscale image and the original image to obtain a compressed image comprises: In a parallel iteration mode, losslessly intercepting the original image from four directions of up, down, left, and right according to the area of the gray value image to obtain an intercepted image; The data of the captured image is stored in the grayscale image to obtain a compressed image.
6. The method according to claim 1, characterized in that Before fitting the edge point contour of the original image to obtain multiple edge point fitting straight line equations, the method further includes: Obtaining transition edge points between the foreground and background of the original image by using an adaptive endpoint gradient algorithm; 5% of the edge points at both ends of the transition edge points are removed, and the remaining edge points are retained on the original image as the edge points of the original image.
7. A method for image restoration, characterized in that: include: Obtaining a fitting data set and a compressed image obtained by the method according to any one of claims 1 to 6, wherein the four corner intersection points in the fitting data set are respectively an upper left corner intersection point, a lower left corner intersection point, an upper right corner intersection point and a lower right corner intersection point, and the four boundary fitting straight line equations are respectively an upper boundary fitting straight line equation, a lower boundary fitting straight line equation, a left boundary fitting straight line equation and a right boundary fitting straight line equation; Calculate the distance D1 from the upper left corner intersection to the upper boundary fitting straight line equation, the distance D2 from the lower left corner intersection to the left boundary fitting straight line equation, the distance D3 from the upper right corner intersection to the right boundary fitting straight line equation, and the distance D4 from the lower right corner intersection to the lower boundary fitting straight line equation; Generate an upper left blank image according to the distance D1 and the distance D2; Generate an upper right blank image according to the distance D1 and the distance D4; Generate a lower left blank image according to the distance D2 and the distance D3; Generate a lower right blank image according to the distance D3 and the distance D4; Generate an upper blank image according to the distance D1 and the length value of the original image; Generate a left blank image according to the distance D2 and the width value of the original image; Generate a blank image according to the distance D3 and the length value of the original image; Generate a right blank image according to the distance D4 and the width value of the original image; Performing splicing and fusion processing on the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image to obtain a restored image; The restored image and the original image are calibrated for image defect feature quantities.
8. The method according to claim 7, characterized in that The step of performing splicing and fusing processing on the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image to obtain a restored image comprises: Taking the upper left corner of the original image as the origin, calculating the offset of the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, and the right blank image; According to the offset and the coordinates of the four corner intersections, the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image are spliced to obtain a spliced image; Grayscale value interpolation is performed on the remaining area of the stitched image that fails to cover the entire image to obtain a restored image.
9. An image compression device, characterized in that: The device comprises: An original image unit, used to obtain an original image, where the original image is an image taken by an industrial camera; A fitting unit, used for fitting the edge point contour of the original image to obtain multiple edge point fitting straight line equations; A row and column processing unit, used for performing row and column processing on the intersection points of the plurality of edge point fitting straight line equations to obtain the coordinates of the four corner intersection points; A calculation unit, used for calculating the equations of four boundary fitting lines of the original image; A judging unit, configured to judge whether the compressed image size is correct according to the Euclidean distance between adjacent four corner intersections, the length and width of the original image, and a compressed image ratio control threshold; A storage unit, for storing the size and type of the original image, the coordinates of the intersection points of the plurality of edge point fitting straight line equations, the coordinates of the four corner intersection points and the four boundary fitting straight line equations into a fitting data set if the compressed image size is correct; A compression unit is used to compress the original image according to the fitting data set to obtain a compressed image.
10. An image restoration device, characterized in that: The device comprises: an acquisition unit, used to acquire a fitting data set and a compressed image obtained by the method according to any one of claims 1 to 6, wherein the four corner intersection points in the fitting data set are respectively an upper left corner intersection point, a lower left corner intersection point, an upper right corner intersection point and a lower right corner intersection point, and the four boundary fitting straight line equations are respectively an upper boundary fitting straight line equation, a lower boundary fitting straight line equation, a left boundary fitting straight line equation and a right boundary fitting straight line equation; a distance calculation unit, for respectively calculating the distance D1 from the upper left corner intersection to the upper boundary fitting straight line equation, the distance D2 from the lower left corner intersection to the left boundary fitting straight line equation, the distance D3 from the upper right corner intersection to the right boundary fitting straight line equation, and the distance D4 from the lower right corner intersection to the lower boundary fitting straight line equation; A blank image unit is used to generate an upper left blank image according to the distance D1 and the distance D2; generate an upper right blank image according to the distance D1 and the distance D4; generate a lower left blank image according to the distance D2 and the distance D3; generate a lower right blank image according to the distance D3 and the distance D4; generate an upper blank image according to the distance D1 and the length value of the original image; generate a left blank image according to the distance D2 and the width value of the original image; generate a lower blank image according to the distance D3 and the length value of the original image; generate a right blank image according to the distance D4 and the width value of the original image; a splicing unit, configured to splice and fuse the upper left blank image, the upper right blank image, the lower left blank image, the lower right blank image, the upper blank image, the left blank image, the lower blank image, the right blank image and the compressed image to obtain a restored image; The calibration unit is used to calibrate the image defect feature quantity between the restored image and the original image.
11. An electronic device, characterized in that: include: Processor, memory, input-output unit, and bus; The processor is connected to the memory, the input and output unit, and the bus; The memory stores a program, and the processor calls the program to execute the image compression method according to any one of claims 1 to 6 or the image restoration method according to any one of claims 7 to 8.
12. A computer-readable storage medium having a program stored thereon, wherein when the program is executed on a computer, the program executes the image compression method according to any one of claims 1 to 6 or the image restoration method according to any one of claims 7 to 8.
Citation Information
Patent Citations
Image compression method and device, image decompression method and device, and storage medium
CN115695821A
Camera focusing definition evaluation method and system
CN117197435A