Image transformation methods, apparatus, devices, and storage media
By segmenting the encoded image into rectangles and calculating the transformation matrix, the problem of the encoded image not fitting the placement position is solved, achieving accurate transformation of irregular quadrilaterals and reducing deformation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-06
- Publication Date
- 2026-04-03
AI Technical Summary
Existing image transformation methods cannot make the encoded image fit the corresponding placement position, resulting in distortion problems.
The original encoded image is divided into several rectangles. The transformation matrix is calculated based on the vertex coordinates of the rectangles and transformed to the target position. The transformed image is then combined.
It enables accurate placement of encoded images in irregular quadrilateral positions, reducing distortion and avoiding loss of image quality and overlay of other content.
Smart Images

Figure CN118364838B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing, and more particularly to an image transformation method, apparatus, device, and storage medium. Background Technology
[0002] Encoded images (such as QR codes and barcodes) serve as a crucial entry point connecting online and offline worlds, and have been applied to all aspects of our lives. In some promotional materials and application interfaces, there is a need for distorted coded images, meaning the coded images are placed in irregular quadrilateral shapes.
[0003] Current image transformation methods can only perform basic image transformations such as moving, scaling, and rotating, but cannot make the coded image fit the corresponding placement position, resulting in distortion problems. Summary of the Invention
[0004] The main objective of this invention is to provide an image transformation method, apparatus, device, and storage medium, aiming to solve the problem that current image transformation methods cannot make the encoded image fit the corresponding placement position, resulting in distortion.
[0005] To achieve the above objectives, the present invention provides an image transformation method, the method comprising:
[0006] Based on the preset number of segments, the original encoded image is divided into several rectangles to obtain the first set of rectangles, and the target transformed image is divided into several rectangles to obtain the second set of rectangles;
[0007] The transformation matrix of the first rectangle and the second rectangle is calculated based on the vertex coordinates of the first rectangle in the first rectangle set and the vertex coordinates of the second rectangle in the second rectangle set.
[0008] Based on the transformation matrix, the corresponding first rectangle is transformed to the position of the second rectangle;
[0009] The transformed first rectangle is combined to obtain the transformed coded image.
[0010] Optionally, the step of dividing the original encoded image into several rectangles based on a preset number of divisions includes:
[0011] Based on the preset number of segments, the original encoded image is segmented along the horizontal / vertical direction to obtain sub-images;
[0012] Based on the preset number of segments, the sub-image is segmented along the vertical / horizontal direction to obtain the plurality of rectangles.
[0013] Optionally, the step of calculating the transformation matrix of the first rectangle and the second rectangle based on the vertex coordinates of the first rectangle in the first rectangle set and the vertex coordinates of the second rectangle in the second rectangle set includes:
[0014] Divide the first rectangle and the second rectangle into an upper triangle and a lower triangle respectively by using diagonals;
[0015] The upper triangle of the first rectangle is designated as the first part, the lower triangle of the first rectangle as the second part, the upper triangle of the second rectangle as the third part, and the lower triangle of the second rectangle as the fourth part.
[0016] The transformation matrix from the first part to the third part is calculated based on the vertex coordinates of the first part and the vertex coordinates of the third part, and is denoted as the first transformation matrix.
[0017] The transformation matrix from the second part to the fourth part is calculated based on the vertex coordinates of the second part and the vertex coordinates of the fourth part, and is denoted as the second transformation matrix.
[0018] The step of transforming the corresponding first rectangle to the position of the second rectangle based on the transformation matrix includes:
[0019] Based on the first transformation matrix, the first part is transformed to the position where the third part is located;
[0020] Based on the second transformation matrix, the second part is transformed to the position where the fourth part is located;
[0021] The transformed first part and the second part are combined to obtain the transformed first rectangle.
[0022] Optionally, the transformed coded image is applied to promotional materials or application interfaces, and the step of combining the transformed first rectangles to obtain the transformed coded image includes:
[0023] The transformed coded image is converted into coded data, and the coded data is then recognized.
[0024] If recognition fails, adjust the number of segments and execute the following steps: based on the preset number of segments, divide the original encoded image into several rectangles to obtain the first set of rectangles, and divide the target transformed image into several rectangles to obtain the second set of rectangles.
[0025] Optionally, the step of dividing the original encoded image into several rectangles (denoted as the first rectangle) based on a preset number of divisions, and dividing the target transformed image into several rectangles (denoted as the second rectangle), includes the following steps before:
[0026] The original encoded image is identified to obtain the corresponding text content;
[0027] Get the length of the text content;
[0028] The number of segments is calculated based on the length of the text content.
[0029] Optionally, the step of calculating the number of segments based on the length of the text content includes:
[0030] The number of segments is obtained by dividing the length of the text content by a preset segmentation threshold.
[0031] Optionally, the step of adjusting the number of segments includes:
[0032] The number of segments is incremented by a preset number of steps to obtain the adjusted number of segments.
[0033] This invention also proposes an image transformation device, the device comprising:
[0034] The segmentation module is used to segment the original encoded image into several rectangles based on a preset number of segments to obtain a first set of rectangles, and to segment the target transformed image into several rectangles to obtain a second set of rectangles.
[0035] The calculation module is used to calculate the transformation matrix of the first rectangle and the second rectangle based on the vertex coordinates of the first rectangle in the first rectangle set and the vertex coordinates of the second rectangle in the second rectangle set.
[0036] The transformation module is used to transform the corresponding first rectangle to the position of the second rectangle based on the transformation matrix;
[0037] The combination module is used to combine the transformed first rectangles to obtain the transformed coded image.
[0038] This invention also proposes a device, which includes a memory, a processor, and an image transformation program stored in the memory and executable on the processor. When the image transformation program is executed by the processor, it implements the image transformation method described above.
[0039] This invention also proposes a computer-readable storage medium storing an image transformation program, which, when executed by a processor, implements the image transformation method described above.
[0040] The image transformation method, apparatus, device, and storage medium proposed in this invention, based on a preset number of segments, divides the original coded image into several rectangles to obtain a first set of rectangles, and divides the target transformed image into several rectangles to obtain a second set of rectangles. A transformation matrix is calculated based on the vertex coordinates of the first rectangle in the first set and the vertex coordinates of the second rectangle in the second set. Based on the transformation matrix, the corresponding first rectangle is transformed to the position of the second rectangle. The transformed first rectangles are then combined to obtain the transformed coded image. This invention, by dividing the original coded image into several rectangles, transforming these rectangles, and then combining the transformed rectangles to obtain the transformed coded image, can transform the original coded image into an irregular quadrilateral image, ensuring that the transformed coded image fits the appropriate placement and does not cover other content in promotional materials or application interfaces. Furthermore, dividing the original coded image into several rectangles for transformation reduces the overall deformation of the original coded image, thus ensuring that the coded image does not experience distortion during the transformation process. Attached Figure Description
[0041] Figure 1 This is a schematic diagram of the functional modules of the device to which the image transformation device of the present invention belongs;
[0042] Figure 2 This is a schematic diagram illustrating the principle of image encoding transformation.
[0043] Figure 3 This is a flowchart illustrating a first exemplary embodiment of the image transformation method of the present invention;
[0044] Figure 4 This is a schematic diagram of the image transformation process of the image transformation method of the present invention;
[0045] Figure 5 This is a flowchart illustrating a second exemplary embodiment of the image transformation method of the present invention;
[0046] Figure 6 A schematic diagram of image segmentation using the image transformation method of the present invention;
[0047] Figure 7 This is a flowchart illustrating a third exemplary embodiment of the image transformation method of the present invention;
[0048] Figure 8 This is a flowchart illustrating a fourth exemplary embodiment of the image transformation method of the present invention;
[0049] Figure 9 This is a flowchart illustrating a fifth exemplary embodiment of the image transformation method of the present invention;
[0050] Figure 10This is a flowchart illustrating a sixth exemplary embodiment of the image transformation method of the present invention;
[0051] Figure 11 This is a schematic diagram of the image transformation process of the present invention;
[0052] Figure 12 This is a comparison diagram of the effects of the image transformation method of the present invention with other image transformation methods.
[0053] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0054] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0055] The main solution of this invention is as follows: Based on a preset number of segments, the original encoded image is divided into several rectangles to obtain a first set of rectangles, and the target transformed image is divided into several rectangles to obtain a second set of rectangles; the transformation matrix of the first rectangle and the second rectangle is calculated based on the vertex coordinates of the first rectangle in the first set and the vertex coordinates of the second rectangle in the second set; based on the transformation matrix, the corresponding first rectangle is transformed to the position of the second rectangle; the transformed first rectangles are combined to obtain the transformed encoded image. This invention, by dividing the original encoded image into several rectangles, transforming these rectangles, and then combining the transformed rectangles to obtain the transformed encoded image, can transform the original encoded image into an irregular quadrilateral image, thus ensuring that the transformed encoded image fits the corresponding placement position and does not cover other content in promotional materials or application interfaces. Furthermore, dividing the original encoded image into several rectangles for transformation can reduce the overall deformation of the original encoded image, thereby ensuring that the encoded image does not experience distortion during the transformation process.
[0056] The embodiments of the present invention take into account that current image transformation methods can only achieve basic image transformations such as moving, scaling, and rotating, but cannot make the encoded image fit the corresponding placement position, resulting in covering other content in promotional materials or application interfaces, or distortion problems that lead to scanning failure.
[0057] Therefore, this invention proposes a solution by dividing the original encoded image into several rectangles, transforming these rectangles, and then combining the transformed rectangles to obtain the transformed encoded image. This transforms the original encoded image into an irregular quadrilateral image, ensuring the transformed image fits its intended placement without obscuring other content in promotional materials or the application interface. Furthermore, dividing the original encoded image into several rectangles for transformation reduces the overall distortion of the original image, thus preventing distortion during the transformation process.
[0058] Specifically, refer to Figure 1 , Figure 1 This is a functional module diagram of the device to which the image transformation device of the present invention belongs. The image transformation device can be a data processing device independent of the device itself, which can be carried on the device in hardware or software form. The device can be a smart mobile terminal with data processing capabilities, such as a mobile phone or tablet computer, or it can be a fixed device or server with data processing capabilities.
[0059] In this embodiment, the device to which the image transformation device belongs includes at least an output module 110, a processor 120, a memory 130, and a communication module 140.
[0060] The memory 130 stores the operating system and image transformation program; the output module 110 may be a display screen, etc. The communication module 140 may include a WIFI module and a Bluetooth module, etc., and communicates with external devices or servers through the communication module 140.
[0061] When the image transformation program in memory 130 is executed by the processor, it performs the following steps:
[0062] Based on the preset number of segments, the original encoded image is divided into several rectangles to obtain the first set of rectangles, and the target transformed image is divided into several rectangles to obtain the second set of rectangles;
[0063] The transformation matrix of the first rectangle and the second rectangle is calculated based on the vertex coordinates of the first rectangle in the first rectangle set and the vertex coordinates of the second rectangle in the second rectangle set.
[0064] Based on the transformation matrix, the corresponding first rectangle is transformed to the position of the second rectangle;
[0065] The transformed first rectangle is combined to obtain the transformed coded image.
[0066] Furthermore, when the image transformation program in memory 130 is executed by the processor, it also performs the following steps:
[0067] Based on the preset number of segments, the original encoded image is segmented along the horizontal / vertical direction to obtain sub-images;
[0068] Based on the preset number of segments, the sub-image is segmented along the vertical / horizontal direction to obtain the plurality of rectangles.
[0069] Furthermore, when the image transformation program in memory 130 is executed by the processor, it also performs the following steps:
[0070] Divide the first rectangle and the second rectangle into an upper triangle and a lower triangle respectively by using diagonals;
[0071] The upper triangle of the first rectangle is designated as the first part, the lower triangle of the first rectangle as the second part, the upper triangle of the second rectangle as the third part, and the lower triangle of the second rectangle as the fourth part.
[0072] The transformation matrix from the first part to the third part is calculated based on the vertex coordinates of the first part and the vertex coordinates of the third part, and is denoted as the first transformation matrix.
[0073] The transformation matrix from the second part to the fourth part is calculated based on the vertex coordinates of the second part and the vertex coordinates of the fourth part, and is denoted as the second transformation matrix.
[0074] Based on the first transformation matrix, the first part is transformed to the position where the third part is located;
[0075] Based on the second transformation matrix, the second part is transformed to the position where the fourth part is located;
[0076] The transformed first part and the second part are combined to obtain the transformed first rectangle.
[0077] Furthermore, when the image transformation program in memory 130 is executed by the processor, it also performs the following steps:
[0078] The transformed coded image is converted into coded data, and the coded data is then recognized.
[0079] If recognition fails, adjust the number of segments and execute the following steps: based on the preset number of segments, divide the original encoded image into several rectangles to obtain the first set of rectangles, and divide the target transformed image into several rectangles to obtain the second set of rectangles.
[0080] Furthermore, when the image transformation program in memory 130 is executed by the processor, it also performs the following steps:
[0081] The original encoded image is identified to obtain the corresponding text content;
[0082] Get the length of the text content;
[0083] The number of segments is calculated based on the length of the text content.
[0084] Furthermore, when the image transformation program in memory 130 is executed by the processor, it also performs the following steps:
[0085] The number of segments is obtained by dividing the length of the text content by a preset segmentation threshold.
[0086] Furthermore, when the image transformation program in memory 130 is executed by the processor, it also performs the following steps:
[0087] The number of segments is incremented by a preset number of steps to obtain the adjusted number of segments.
[0088] This embodiment, through the above-described scheme, specifically divides the original encoded image into several rectangles based on a preset number of segments to obtain a first set of rectangles, and divides the target transformed image into several rectangles to obtain a second set of rectangles. Based on the vertex coordinates of the first rectangles in the first set and the vertex coordinates of the second rectangles in the second set, a transformation matrix is calculated for the first and second rectangles. Based on the transformation matrix, the corresponding first rectangles are transformed to the positions of the second rectangles. The transformed first rectangles are then combined to obtain the transformed encoded image. This embodiment of the invention, by dividing the original encoded image into several rectangles, transforming these rectangles, and then combining the transformed rectangles to obtain the transformed encoded image, can complete the transformation of the original encoded image into an irregular quadrilateral image, thus ensuring that the transformed encoded image fits the appropriate placement position and does not cover other content in promotional materials or application interfaces. Furthermore, dividing the original encoded image into several rectangles for transformation reduces the overall deformation of the original encoded image, thereby ensuring that the encoded image does not experience distortion during the transformation process.
[0089] Currently, HTML5 uses canvas to draw images. Basic canvas transformations (translation, scaling, rotation) can transform a square into a parallelogram, and any irregular quadrilateral can be obtained by combining two parallelograms. (See reference...) Figure 2 , Figure 2 This diagram illustrates the principle of image transformation. The QR code image is divided into two parts along a diagonal, with each part representing half of a parallelogram. Therefore, each part is transformed into a parallelogram, and then half of each parallelogram is combined to form the final QR code image.
[0090] However, using canvas transformations to obtain irregular encoded images can lead to distortion of the encoded images.
[0091] Therefore, in light of the above problems, and based on the above-described device architecture, but not limited to it, an embodiment of the method of the present invention is proposed.
[0092] The execution subject of the method in this embodiment can be an image transformation device. This image transformation device can be a device that is independent of the device and capable of data processing. It can be carried on the device in the form of hardware or software.
[0093] Reference Figure 3 , Figure 3 This is a flowchart illustrating a first exemplary embodiment of the image transformation method of the present invention. The image transformation method includes:
[0094] Step S40: Based on the preset number of segments, the original encoded image is divided into several rectangles to obtain the first set of rectangles, and the target transformed image is divided into several rectangles to obtain the second set of rectangles.
[0095] The original encoded image that needs to be transformed can be a barcode, a QR code, or other images with information. In this embodiment of the invention, a QR code is used as an example.
[0096] Reference Figure 4 , Figure 4 This is a schematic diagram of the image transformation process of the image transformation method of the present invention.
[0097] First, place the original encoded image (left QR code image) and the target transformed image (right promotional image) on the specified coordinate system.
[0098] The original encoded image and the target transformed image are regarded as two quadrilaterals. First, the vertex coordinates of the two quadrilaterals are obtained and denoted as R1(A1, B1, C1, D1) and R2(A2, B2, C2, D2) respectively. The transformation correspondence is: A1->A2, B1->B2, C1->C2, D1->D2.
[0099] To ensure the recognizability of the encoding during the transformation process, the original encoded image can be divided into multiple small rectangles, each of which is then transformed and finally stitched together to form a complete encoded image, thus reducing the overall distortion of the image.
[0100] Specifically, based on a preset number of segments, the original encoded image is divided into several rectangles, and the rectangles into which the original encoded image is divided are denoted as the first rectangle set. At the same time, based on a preset number of segments, the target transformed image is divided into several rectangles, and the rectangles into which the target transformed image is divided are denoted as the second rectangle set, so that each first rectangle in the first rectangle set corresponds to each second rectangle in the second rectangle set.
[0101] One implementation method involves uniformly dividing the original encoded image into several rectangles in the horizontal and vertical directions, denoted as the first rectangle set. Then, the target transformed image is divided into several rectangles in the same way, denoted as the second rectangle set. This allows the first rectangle to be transformed to the position of the second rectangle, thereby transforming the original encoded image to the position of the target transformed image.
[0102] In another implementation, image processing algorithms, such as segmentation algorithms (e.g., watershed algorithm, edge detection), can be used to segment the original encoded image into rectangular regions with clear boundaries, denoted as the first set of rectangles. Simultaneously, the target transformed image is divided into several rectangles, denoted as the second set of rectangles, ensuring that the first and second rectangles correspond to each other.
[0103] After dividing the image into several rectangles, the vertex coordinates of the first rectangle can be obtained based on the original encoded image and the dividing method; the vertex coordinates of the second rectangle can also be obtained based on the target transformed image and the dividing method.
[0104] Step S50: Calculate the transformation matrix of the first rectangle and the second rectangle based on the vertex coordinates of the first rectangle in the first rectangle set and the vertex coordinates of the second rectangle in the second rectangle set.
[0105] The first set of rectangles consists of several rectangles in the original encoded image, and the second set of rectangles consists of several rectangles in the target transformed image. The rectangles in the original encoded image all have corresponding rectangles in the target transformed image.
[0106] The parameters required for transformations such as translation, rotation, and scaling can be calculated based on the vertex coordinates of the first and second rectangles. These parameters include the translation amount, rotation angle, and scaling ratio in each direction.
[0107] Based on the calculated parameters, a transformation matrix can be constructed, which describes the translation, rotation, and scaling operations.
[0108] For example, if the vertex coordinates of a first rectangle are A(x1,y1), B(x2,y2), C(x3,y3), and D(x4,y4), and the vertex coordinates of a corresponding second rectangle are A'(x1',y1'), B'(x2',y2'), C'(x3',y3'), and D'(x4',y4'), then the parameters can be calculated based on the above coordinate information, thereby constructing the transformation matrix.
[0109] Step S60: Based on the transformation matrix, transform the corresponding first rectangle to the position of the second rectangle.
[0110] Specifically, using the calculated transformation matrix, the first rectangle is transformed by moving, rotating, and scaling it until it coincides with the second rectangle. This completes the accurate transformation from the first rectangle to the second rectangle.
[0111] Since the first rectangle set contains several first rectangles, multiple transformation matrix calculations and multiple image transformations are required.
[0112] Step S70: Combine the transformed first rectangles to obtain the transformed coded image.
[0113] The original encoded image is transformed by local regions and then reassembled into the transformed encoded image.
[0114] This embodiment, through the above-described scheme, divides the original encoded image into several rectangles based on a preset number of segments, obtaining a first set of rectangles, and divides the target transformed image into several rectangles, obtaining a second set of rectangles. Based on the vertex coordinates of the first rectangles in the first set and the vertex coordinates of the second rectangles in the second set, a transformation matrix is calculated for the first and second rectangles. Based on the transformation matrix, the corresponding first rectangles are transformed to the positions of the second rectangles. The transformed first rectangles are then combined to obtain the transformed encoded image. This embodiment of the invention, by dividing the original encoded image into several rectangles, transforming these rectangles, and then combining the transformed rectangles to obtain the transformed encoded image, can complete the transformation of the original encoded image into an irregular quadrilateral image, thus ensuring that the transformed encoded image fits the appropriate placement position and does not cover other content in promotional materials or application interfaces. Furthermore, dividing the original encoded image into several rectangles for transformation reduces the overall deformation of the original encoded image, thereby ensuring that the encoded image does not experience distortion during the transformation process.
[0115] Reference Figure 5 , Figure 5 This is a flowchart illustrating a second exemplary embodiment of the image transformation method of the present invention.
[0116] Based on the above Figure 3 In the embodiment shown, step S40, which involves dividing the original encoded image into several rectangles based on a preset number of segments, includes:
[0117] Step S41: Based on the preset number of segments, the original encoded image is segmented along the horizontal / vertical direction to obtain sub-images.
[0118] Step S42: Based on the preset number of segments, the sub-image is segmented along the vertical / horizontal direction to obtain the plurality of rectangles.
[0119] For example, the original encoded image can be divided horizontally to obtain sub-images based on a preset number of segments, and then the sub-images can be divided vertically to obtain several rectangles based on the preset number of segments.
[0120] For example, the original encoded image can be divided vertically to obtain sub-images based on a preset number of segments, and then the sub-images can be divided horizontally to obtain several rectangles based on the preset number of segments.
[0121] For example, the original encoded image can be divided horizontally into sub-images based on a preset number of segments, and then the sub-images can be divided horizontally into several rectangles based on the preset number of segments.
[0122] For example, the original encoded image can be divided vertically into sub-images based on a preset number of segments, and then the sub-images can be divided vertically into several rectangles based on the preset number of segments.
[0123] Reference Figure 6 , Figure 6 A schematic diagram of image segmentation in the image transformation method of this invention.
[0124] Where, assuming Figure 6 The vertex coordinates of the original encoded image are A(x,y), B(x,y), C(x,y), and D(x,y).
[0125] exist Figure 6 In this example, vectors are used to segment the image. Assume the preset number of segments is N.
[0126] (a) First, obtain vectors AD and BC, and divide the two vectors into N equal parts;
[0127] (b) Then, based on each equal division, the vector in the AB direction is divided into N equal parts, thus dividing the original encoded image into N to the power of N parts.
[0128] Divide the directions of vector AD and vector BC into N equal parts. The values of each part are AD_X, BC_X, AD_Y, and BC_Y. The values of each part can be calculated using the following equation:
[0129] AD_X = (Dx - Ax) / N;
[0130] AD_Y = (Dy - Ay) / N;
[0131] BC_X = (Cx - Bx) / N;
[0132] BC_Y = (Cy - Cy) / N;
[0133] (c) Based on the division values obtained in (b), divide the AB vector direction into N equal parts and obtain the coordinates of all points after division. For example, to obtain the coordinates of point pq in the figure:
[0134] The first step is to obtain the coordinates of the p-th point along the directions of vectors AD and BC, denoted as AD_p(x,y) and BC_p(x,y) respectively. The calculation formulas are as follows:
[0135] AD_p.x=A.x+AD_X*p, AD_p.y=A.y+AD_Y*p;
[0136] BC_p.x=B.x+BC_X*p, BC_p.y=B.y+BC_Y*p;
[0137] The second step is to obtain the coordinates of the q-th point along the vector direction from AD_p to BC_p, denoted as pq(x,y). The calculation formula is as follows:
[0138] pq.x=AD_p.x+(BC_p.x-AD_p.x) / N*q;
[0139] pq.y=AD_p.y+(BC_p.y-AD_p.y) / N*q;
[0140] By iterating through (c), the coordinates of all points after the segmentation can be obtained.
[0141] This invention, through horizontal / vertical segmentation of the original encoded image, yields several rectangles, enabling localized image processing. Each rectangle represents a local region in the original image, allowing for more precise and focused processing of that specific area.
[0142] Reference Figure 7 , Figure 7 This is a flowchart illustrating a third exemplary embodiment of the image transformation method of the present invention.
[0143] Based on the above Figure 3 In the embodiment shown, step S50, which involves calculating the transformation matrix of the first rectangle and the second rectangle based on the vertex coordinates of the first rectangle in the first rectangle set and the vertex coordinates of the second rectangle in the second rectangle set, includes:
[0144] Step S51: Divide the first rectangle and the second rectangle into an upper triangle and a lower triangle respectively by using diagonals.
[0145] Among them, according to Figure 2The principle of image transformation in this paper is that, based on the transformation of the first rectangle, the first rectangle can be divided into an upper triangle and a lower triangle by the diagonal. Then, the transformation matrix is calculated for the upper triangle and the lower triangle respectively. The transformation operation is performed based on the transformation matrix. In this way, the transformation of the coded image from a square to an irregular quadrilateral can be achieved more accurately.
[0146] Step S52: The upper triangle of the first rectangle is designated as the first part, the lower triangle of the first rectangle is designated as the second part, the upper triangle of the second rectangle is designated as the third part, and the lower triangle of the second rectangle is designated as the fourth part.
[0147] Step S53: Calculate the transformation matrix from the first part to the third part based on the vertex coordinates of the first part and the vertex coordinates of the third part, and denote it as the first transformation matrix.
[0148] Step S54: Calculate the transformation matrix from the second part to the fourth part based on the vertex coordinates of the second part and the vertex coordinates of the fourth part, and denote it as the second transformation matrix.
[0149] Taking the triangle below as an example, set the coordinates of the vertices of the second part to T1(SA1, SB1, SC1) and the coordinates of the vertices of the fourth part to T2(SA2, SB2, SC2). Calculate the six values a, b, c, d, e, and f based on the matrix calculation formula below.
[0150]
[0151] X2 = a*X1 + c*Y1 + e*1
[0152] Y2=b*X1+d*Y1+f*1
[0153]
[0154] Substituting the coordinates of points T1 and T2 into the calculation formula yields two sets of three linear equations, from which the values of a, b, c, d, e, and f can be calculated.
[0155]
[0156] Then, call the canvas's transform(a,b,c,d,e,f) method to perform basic image transformations, which will convert the lower part of the QR code into the target shape.
[0157] The same process is used in the above part: first calculate the transformation matrix, and then perform the transformation.
[0158] Reference Figure 8 , Figure 8This is a flowchart illustrating a fourth exemplary embodiment of the image transformation method of the present invention.
[0159] Based on the above Figure 3 In the embodiment shown, step S60, transforming the corresponding first rectangle to the position of the second rectangle based on the transformation matrix, includes:
[0160] Step S61: Based on the first transformation matrix, transform the first part to the position where the third part is located.
[0161] Step S62: Based on the second transformation matrix, transform the second part to the position where the fourth part is located.
[0162] Step S63: Combine the transformed first part and the second part to obtain the transformed first rectangle.
[0163] The transformed upper triangle and the transformed lower triangle are combined to obtain the transformed first rectangle.
[0164] This invention breaks down complex transformations into basic transformations, making them easy to understand and use. Furthermore, by dividing the original encoded image into several rectangles, and then further dividing each rectangle into upper and lower triangles along its diagonal, and performing transformations on each triangle separately, the overall distortion of the image is reduced, thus ensuring that the encoded image does not experience distortion during the transformation process.
[0165] Reference Figure 9 , Figure 9 This is a flowchart illustrating a fifth exemplary embodiment of the image transformation method of the present invention.
[0166] Based on the above Figure 3 In the embodiment shown, the transformed coded image is applied to promotional materials or application interfaces. Step S70, after combining the transformed first rectangles to obtain the transformed coded image, includes:
[0167] Step S80: Convert the transformed coded image into coded data and recognize the coded data;
[0168] The encoded data includes, but is not limited to, base64 data.
[0169] Step S90: If recognition fails, adjust the number of segments and execute the following steps: Based on the preset number of segments, divide the original encoded image into several rectangles to obtain the first set of rectangles, and divide the target transformed image into several rectangles to obtain the second set of rectangles.
[0170] If recognition fails, it means that segmenting the original encoded image based on the current number of segments and performing image transformation will still result in image distortion. Therefore, it is necessary to adjust the number of segments, segment the original encoded image again, and perform image transformation until recognition is successful.
[0171] The embodiments of the present invention, by re-segmenting and transforming images, can better adapt to different types of coded images, optimize the effect of image processing, and thus increase the chance of successful recognition.
[0172] Reference Figure 10 , Figure 10 This is a flowchart illustrating a sixth exemplary embodiment of the image transformation method of the present invention.
[0173] Based on the above Figure 9 In the embodiment shown, step S40, which involves dividing the original encoded image into several rectangles (denoted as the first rectangle) based on a preset number of divisions, and dividing the target transformed image into several rectangles (denoted as the second rectangle), includes the following steps before:
[0174] Step S10: Recognize the original encoded image to obtain the corresponding text content;
[0175] Step S20: Obtain the length of the text content;
[0176] Step S30: Calculate the number of segments based on the length of the text content.
[0177] In order to improve the efficiency of image transformation and reduce the number of image transformations, the text content corresponding to the encoded image is first identified, the number of segments N for the first segment is determined according to the length L of the text content, and the number of segments is calculated based on the length L of the text content.
[0178] As one implementation, step S30, calculating the number of segments based on the length of the text content, includes:
[0179] Step S31: Divide the length of the text content by a preset segmentation threshold to obtain the number of segments.
[0180] Assuming the preset segmentation threshold is 40, the equation for calculating the number of segments is: N = L / 40, and the result is rounded up.
[0181] In one implementation, if the identification fails in step S90, the number of segments is adjusted, wherein adjusting the number of segments includes:
[0182] Step S91: Increment the number of segments by a preset number of steps to obtain the adjusted number of segments. Assuming the preset number of steps is 1, if recognition fails, increment the number of segments by 1 to obtain the adjusted number of segments, and then execute the following steps: Based on the preset number of segments, segment the original encoded image into several rectangles to obtain the first set of rectangles, and segment the target transformed image into several rectangles to obtain the second set of rectangles.
[0183] In this embodiment of the invention, before segmenting the original encoded image, the original encoded image is identified to obtain the corresponding text content, the length of the text content is obtained, and the number of segments is calculated based on the length of the text content, thereby improving the efficiency of image transformation and reducing the number of image transformation operations.
[0184] Reference Figure 11 , Figure 11 This is a schematic diagram illustrating the image transformation process of this invention.
[0185] Step S10000: Image segmentation. Based on the preset number of segments, the original encoded image is segmented into several rectangles to obtain the first rectangle set, and the target transformed image is segmented into several rectangles to obtain the second rectangle set;
[0186] Step S20000: Calculate coordinates. Calculate the coordinates of the first and second rectangles after the division.
[0187] Step S30000: Calculate the transformation matrix. The transformation matrix between the first rectangle in the first rectangle set and the second rectangle in the second rectangle set is calculated based on their corresponding vertex coordinates.
[0188] Step S40000: Apply the transformation matrix. Based on the transformation matrix, transform the corresponding first rectangle to the position of the second rectangle.
[0189] Step S50000: Combine the images. Combine the transformed first rectangles to obtain the transformed coded image.
[0190] Step S60000: Recognize the QR code and determine whether the QR code recognition was successful.
[0191] If identification fails in step S70000, adjust the number of segments and re-execute step S10000.
[0192] Step S80000: If recognition is successful, the transformation is completed.
[0193] With this invention, when producing related promotional materials or application interfaces, the QR code can be placed in the correct position, and the QR code recognition rate is 100% without any distortion.
[0194] by Figure 12 For example, Figure 12 This is a comparison diagram of the effects of the image transformation method of the present invention with other image transformation methods.
[0195] The blank space in the middle of the promotional image is where the QR code is placed.
[0196] The image in the upper right corner did not use this method; instead, it was simply dragged and stretched. The resulting QR code could not be well integrated with the material and covered other content in the image, thus reducing the user experience.
[0197] The image on the right did not use this method; instead, it was simply dragged and stretched, resulting in information loss and the inability to scan the code.
[0198] The image in the lower right corner is transformed using the method of this invention, so that the QR code fits the placement position well and can be scanned successfully.
[0199] Furthermore, this application also proposes an image transformation device, which includes:
[0200] The segmentation module is used to segment the original encoded image into several rectangles based on a preset number of segments to obtain a first set of rectangles, and to segment the target transformed image into several rectangles to obtain a second set of rectangles.
[0201] The calculation module is used to calculate the transformation matrix of the first rectangle and the second rectangle based on the vertex coordinates of the first rectangle in the first rectangle set and the vertex coordinates of the second rectangle in the second rectangle set.
[0202] The transformation module is used to transform the corresponding first rectangle to the position of the second rectangle based on the transformation matrix;
[0203] The combination module is used to combine the transformed first rectangles to obtain the transformed coded image.
[0204] The principle and implementation process of image transformation in this embodiment are explained in the above embodiments and will not be repeated here.
[0205] Furthermore, this application also proposes an apparatus comprising a memory, a processor, and an image transformation program stored in the memory and executable on the processor. When the image transformation program is executed by the processor, it implements the steps of the image transformation method described above.
[0206] Since this image transformation program employs all the technical solutions of all the aforementioned embodiments when executed by the processor, it possesses at least all the beneficial effects brought about by all the technical solutions of all the aforementioned embodiments, which will not be elaborated upon here.
[0207] Furthermore, embodiments of this application also propose a computer-readable storage medium storing an image transformation program, which, when executed by a processor, implements the steps of the image transformation method described above.
[0208] Since this image transformation program employs all the technical solutions of all the aforementioned embodiments when executed by the processor, it possesses at least all the beneficial effects brought about by all the technical solutions of all the aforementioned embodiments, which will not be elaborated upon here.
[0209] This embodiment, through the above-described scheme, specifically divides the original encoded image into several rectangles based on a preset number of segments to obtain a first set of rectangles, and divides the target transformed image into several rectangles to obtain a second set of rectangles. Based on the vertex coordinates of the first rectangles in the first set and the vertex coordinates of the second rectangles in the second set, a transformation matrix is calculated for the first and second rectangles. Based on the transformation matrix, the corresponding first rectangles are transformed to the positions of the second rectangles. The transformed first rectangles are then combined to obtain the transformed encoded image. This embodiment of the invention, by dividing the original encoded image into several rectangles, transforming these rectangles, and then combining the transformed rectangles to obtain the transformed encoded image, can complete the transformation of the original encoded image into an irregular quadrilateral image, thus ensuring that the transformed encoded image fits the appropriate placement position and does not cover other content in promotional materials or application interfaces. Furthermore, dividing the original encoded image into several rectangles for transformation reduces the overall deformation of the original encoded image, thereby ensuring that the encoded image does not experience distortion during the transformation process.
[0210] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or approach that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or approach. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or approach that includes that element.
[0211] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0212] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, controlled terminal, or network device, etc.) to execute the methods of each embodiment of the present invention.
[0213] The above are merely preferred embodiments of the present invention and do not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. An image transformation method, characterized in that, The method includes the following steps: Based on the preset number of segments, the original encoded image is divided into several rectangles to obtain the first set of rectangles, and the target transformed image is divided into several rectangles to obtain the second set of rectangles; The step of dividing the original encoded image into several rectangles based on a preset number of divisions includes: Based on the preset number of segments, the original encoded image is segmented along the horizontal / vertical direction to obtain sub-images; Based on the preset number of segments, the sub-image is divided along the vertical / horizontal direction to obtain the plurality of rectangles; The transformation matrix of the first rectangle and the second rectangle is calculated based on the vertex coordinates of the first rectangle in the first rectangle set and the vertex coordinates of the second rectangle in the second rectangle set. The step of calculating the transformation matrix of the first rectangle and the second rectangle based on the vertex coordinates of the first rectangle in the first rectangle set and the vertex coordinates of the second rectangle in the second rectangle set includes: Divide the first rectangle and the second rectangle into an upper triangle and a lower triangle respectively by using diagonals; The upper triangle of the first rectangle is designated as the first part, the lower triangle of the first rectangle as the second part, the upper triangle of the second rectangle as the third part, and the lower triangle of the second rectangle as the fourth part. The transformation matrix from the first part to the third part is calculated based on the vertex coordinates of the first part and the vertex coordinates of the third part, and is denoted as the first transformation matrix. The transformation matrix from the second part to the fourth part is calculated based on the vertex coordinates of the second part and the vertex coordinates of the fourth part, and is denoted as the second transformation matrix. Based on the first transformation matrix, the first part is transformed to the position where the third part is located; Based on the second transformation matrix, the second part is transformed to the position where the fourth part is located; The transformed first part and the second part are combined to obtain the transformed first rectangle; Based on the transformation matrix, the corresponding first rectangle is transformed to the position of the second rectangle; The transformed first rectangle is combined to obtain the transformed coded image; The transformed coded image is used in promotional materials or application interfaces. The step of combining the transformed first rectangles to obtain the transformed coded image includes: The transformed coded image is converted into coded data, and the coded data is then recognized. If recognition fails, adjust the number of segments and execute the following steps: based on the preset number of segments, divide the original encoded image into several rectangles to obtain the first set of rectangles, and divide the target transformed image into several rectangles to obtain the second set of rectangles.
2. The method according to claim 1, characterized in that, The steps preceding the step of dividing the original encoded image into several rectangles (denoted as the first rectangle) based on a preset number of divisions, and dividing the target transformed image into several rectangles (denoted as the second rectangle) include: The original encoded image is identified to obtain the corresponding text content; Get the length of the text content; The number of segments is calculated based on the length of the text content.
3. The method according to claim 2, characterized in that, The step of calculating the number of segments based on the length of the text content includes: The number of segments is obtained by dividing the length of the text content by a preset segmentation threshold.
4. The method according to claim 2, characterized in that, The steps for adjusting the number of segments include: The number of segments is incremented by a preset number of steps to obtain the adjusted number of segments.
5. An image transformation device, characterized in that, The device includes: The segmentation module is used to segment the original encoded image into several rectangles based on a preset number of segments to obtain a first set of rectangles, and to segment the target transformed image into several rectangles to obtain a second set of rectangles. The segmentation module is also used to segment the original encoded image along the horizontal / vertical direction based on the preset number of segments to obtain sub-images; Based on the preset number of segments, the sub-image is divided along the vertical / horizontal direction to obtain the plurality of rectangles; The calculation module is used to calculate the transformation matrix of the first rectangle and the second rectangle based on the vertex coordinates of the first rectangle in the first rectangle set and the vertex coordinates of the second rectangle in the second rectangle set. The calculation module is further configured to divide the first rectangle and the second rectangle into an upper triangle and a lower triangle respectively by using diagonals; The upper triangle of the first rectangle is designated as the first part, the lower triangle of the first rectangle as the second part, the upper triangle of the second rectangle as the third part, and the lower triangle of the second rectangle as the fourth part. The transformation matrix from the first part to the third part is calculated based on the vertex coordinates of the first part and the vertex coordinates of the third part, and is denoted as the first transformation matrix. The transformation matrix from the second part to the fourth part is calculated based on the vertex coordinates of the second part and the vertex coordinates of the fourth part, and is denoted as the second transformation matrix. Based on the first transformation matrix, the first part is transformed to the position where the third part is located; Based on the second transformation matrix, the second part is transformed to the position where the fourth part is located; The transformed first part and the second part are combined to obtain the transformed first rectangle; The transformation module is used to transform the corresponding first rectangle to the position of the second rectangle based on the transformation matrix; The combination module is used to combine the transformed first rectangles to obtain the transformed coded image; The transformed coded image is used in promotional materials or application interfaces. The combination module is also used to convert the transformed coded image into coded data and to identify the coded data. If recognition fails, adjust the number of segments and execute the following steps: based on the preset number of segments, divide the original encoded image into several rectangles to obtain the first set of rectangles, and divide the target transformed image into several rectangles to obtain the second set of rectangles.
6. An image transformation device, characterized in that, The image transformation device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the image transformation method as described in any one of claims 1-4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the image transformation method as described in any one of claims 1-4.
Citation Information
Patent Citations
Apparatus for 3D object creation and thereof Method
KR1020160117406A