Image watermark adding and detecting method and device, electronic equipment and storage medium

By performing rotation and inverse rotation transformations on the image, the problem of watermarks easily disappearing after modification is solved, achieving robust reversibility and efficient processing of watermarks.

CN114022340BActive Publication Date: 2026-01-06KE COM (BEIJING) TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111328039.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-10
Publication Date
2026-01-06
Estimated Expiration
2041-11-10

AI Technical Summary

Technical Problem

In existing technologies, image watermarks are prone to disappearing or being lost after modification, making them unrecognizable and lacking robust reproducibility.

Method used

By performing a preset number of rotation transformations on the original image to be watermarked, combined with the watermark detection method and device, the rotation transformation is used to fuse the pixel values ​​of the watermark with the corresponding pixel values ​​in the rotated pixel matrix, and then performing a preset number of inverse rotation transformations to generate a restored pixel matrix to add the watermark.

Benefits of technology

It achieves robust and reversible watermarking, reducing the chance of watermark loss even after image modification, improving watermark robustness, and is fast and time-saving.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114022340B_ABST
    Figure CN114022340B_ABST
Patent Text Reader

Abstract

This disclosure provides a method and apparatus for adding watermarks to images, a method and apparatus for detecting watermarks in images, an electronic device, and a storage medium. The method for adding watermarks to images includes: performing a preset number of rotation transformations on an initial pixel matrix corresponding to the original image to which the watermark is to be added, resulting in a rotated pixel matrix, wherein the rotation transformation includes a right-hand rotation or a left-hand rotation; fusing the pixel values ​​of the watermark with the pixel values ​​at corresponding positions in the rotated pixel matrix, resulting in a fused pixel matrix; performing the preset number of inverse rotation transformations on the fused pixel matrix, resulting in a restored pixel matrix with the watermark added; and obtaining a target image with the watermark added based on the restored pixel matrix. This disclosure enables robust reversibility of the watermark added to the image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of image processing technology, and in particular to a method and apparatus for adding watermarks to images, a method and apparatus for detecting watermarks in images, electronic devices, and storage media. Background Technology

[0002] With the widespread adoption of near-eye display devices, images and videos are being used extensively across various industries. As these images and videos become more widely used, the importance of copyright protection is becoming increasingly apparent. Adding invisible watermarks to image frames in images or videos can effectively control image copying and facilitate the tracing of unauthorized use.

[0003] In existing technologies, the watermarking techniques used to add watermarks to images often result in uneven pixel distribution due to algorithmic flaws. When an image with an invisible watermark is modified (e.g., by adding a mask, graffiti, or resizing), the watermark may disappear or become missing, rendering it unrecognizable.

[0004] Therefore, how to make the watermark added to the image robust and reversible is a technical problem worthy of attention. Summary of the Invention

[0005] This disclosure provides a method and apparatus for adding watermarks to images, a method and apparatus for detecting watermarks in images, an electronic device, and a storage medium, so that the watermarks added to the images have robust reversibility.

[0006] One aspect of this disclosure provides a method for adding a watermark to an image, comprising: performing a preset number of rotation transformations on an initial pixel matrix corresponding to the original image to which the watermark is to be added, to obtain a rotated pixel matrix, wherein the rotation transformation includes a right-hand rotation transformation or a left-hand rotation transformation; fusing the pixel values ​​of the watermark with the pixel values ​​at corresponding positions in the rotated pixel matrix to obtain a fused pixel matrix; performing the preset number of inverse rotation transformations on the fused pixel matrix to obtain a restored pixel matrix with the watermark added; and obtaining a target image with the watermark added based on the restored pixel matrix.

[0007] Another aspect of this disclosure provides a method for detecting watermarks in an image, comprising: determining a target pixel matrix of the target image based on an acquired target image with an added watermark; performing a preset number of rotation transformations on the target pixel matrix to obtain a detection pixel matrix after rotation transformation, wherein the rotation transformation includes a right rotation transformation or a left rotation transformation; and obtaining the watermark in the target image based on the detection pixel matrix.

[0008] In another aspect of this disclosure, an apparatus for adding a watermark to an image is provided, comprising: a rotation transformation unit, configured to perform a preset number of rotation transformations on an initial pixel matrix corresponding to the original image to which the watermark is to be added, to obtain a rotated pixel matrix, wherein the rotation transformation includes a right-hand rotation transformation or a left-hand rotation transformation; a pixel fusion unit, configured to fuse the pixel values ​​of the watermark with the pixel values ​​at corresponding positions in the rotated pixel matrix, to obtain a fused pixel matrix; an inverse transformation unit, configured to perform the preset number of inverse rotation transformations on the fused pixel matrix to obtain a restored pixel matrix with the watermark added; and an output unit, configured to obtain a target image with the watermark added based on the restored pixel matrix.

[0009] In another aspect of this disclosure, a watermark detection device for an image is provided, comprising: a pixel matrix determination unit, configured to determine a target pixel matrix of the target image based on an acquired target image with an added watermark; a detection transformation unit, configured to perform a preset number of rotation transformations on the target pixel matrix to obtain a rotationally transformed detection pixel matrix, wherein the rotation transformation includes a right-hand rotation transformation or a left-hand rotation transformation; and a detection output unit, configured to obtain the watermark in the target image based on the detection pixel matrix.

[0010] In another aspect of this disclosure, an electronic device is provided, comprising: a memory for storing a computer program; and a processor for executing the computer program stored in the memory, wherein when the computer program is executed, it implements the method for adding a watermark to an image or the method for detecting a watermark in an image as described in this disclosure.

[0011] In another aspect of the present disclosure, a computer-readable storage medium is provided having a computer program stored thereon, characterized in that, when executed by a processor, the computer program implements the method for adding a watermark to an image or the method for detecting a watermark in an image as described in the present disclosure.

[0012] Based on this disclosure, there are methods and apparatus for adding watermarks to images, methods and apparatus for detecting watermarks in images, electronic devices, and storage media. When adding a watermark to a target image, firstly, since the watermark pixel information is randomly distributed to various positions throughout the pixel matrix, the watermark information can be hidden. Furthermore, when the watermarked image is modified (graffiti, occlusion, etc.), the probability of watermark information loss can be reduced, ensuring that the watermark can be successfully detected and restored, thus improving the robustness of the watermark.

[0013] The technical solutions of this disclosure will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description

[0014] The accompanying drawings, which form part of this specification, illustrate embodiments of this disclosure and, together with the description, serve to explain the principles of this disclosure.

[0015] This disclosure will become clearer with reference to the accompanying drawings and the following detailed description, wherein:

[0016] Figure 1 This is a flowchart of one embodiment of the method for adding watermarks to images disclosed herein;

[0017] Figure 2 This is a flowchart of another embodiment of the method for adding watermarks to images disclosed herein;

[0018] Figure 3a This is an example of the original image to which the watermark is to be added;

[0019] Figure 3b Yes Figure 3a The image after pixel padding;

[0020] Figure 3c Yes Figure 3b The image after undergoing a preset number of rotation transformations;

[0021] Figure 3d Yes Figure 3c Image after watermarking;

[0022] Figure 3e Yes Figure 3d The image after undergoing a preset number of inverse rotation transformations;

[0023] Figure 3f Yes Figure 3e The image after watermark detection;

[0024] Figure 3g Yes Figure 3e Example image of graffiti;

[0025] Figure 3h Yes Figure 3e Example image of occlusion;

[0026] Figure 4 This is a flowchart of one embodiment of the watermark detection method in images disclosed herein;

[0027] Figure 5 This is a schematic diagram of one embodiment of the apparatus for adding watermarks to images disclosed herein;

[0028] Figure 6 This is a schematic diagram of another embodiment of the apparatus for adding watermarks to images disclosed herein;

[0029] Figure 7This is a schematic diagram of the structure of one embodiment of the watermark detection device in the image disclosed herein;

[0030] Figure 8 This is a schematic diagram of the structure of one application embodiment of the electronic device disclosed herein. Detailed Implementation

[0031] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that, unless otherwise specifically stated, the relative arrangement, numerical expressions, and values ​​of the components and steps set forth in these embodiments do not limit the scope of the present disclosure.

[0032] Those skilled in the art will understand that the terms "first," "second," etc., in the embodiments of this disclosure are only used to distinguish different steps, devices, or modules, and do not represent any specific technical meaning, nor do they indicate a necessary logical order between them.

[0033] It should also be understood that in the embodiments disclosed herein, "multiple" can refer to two or more, and "at least one" can refer to one, two or more.

[0034] It should also be understood that any component, data or structure mentioned in the embodiments of this disclosure can generally be understood as one or more unless expressly defined or given to the contrary in the context.

[0035] Furthermore, the term "and / or" in this disclosure is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. Additionally, the character " / " in this disclosure generally indicates that the preceding and following related objects have an "or" relationship.

[0036] It should also be understood that the description of the various embodiments in this disclosure emphasizes the differences between the various embodiments, and the similarities or similarities can be referred to each other. For the sake of brevity, they will not be described in detail.

[0037] At the same time, it should be understood that, for ease of description, the dimensions of the various parts shown in the accompanying drawings are not drawn according to actual scale.

[0038] The following description of at least one exemplary embodiment is merely illustrative and is in no way intended to limit this disclosure or its application or use.

[0039] Techniques, methods, and equipment known to those skilled in the art may not be discussed in detail, but where appropriate, such techniques, methods, and equipment should be considered part of the specification.

[0040] It should be noted that similar labels and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be discussed further in subsequent figures.

[0041] The embodiments disclosed herein can be applied to electronic devices such as terminal devices, computer systems, and servers, and can operate together with a wide range of other general-purpose or special-purpose computing system environments or configurations. Examples of well-known terminal devices, computing systems, environments, and / or configurations suitable for use with electronic devices such as terminal devices, computer systems, and servers include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, handheld or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputer systems, mainframe computer systems, and distributed cloud computing environments including any of the above systems, etc.

[0042] Electronic devices such as terminal devices, computer systems, and servers can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, program modules can include routines, programs, object programs, components, logic, data structures, etc., which perform specific tasks or implement specific abstract data types. Computer systems / servers can be implemented in distributed cloud computing environments, where tasks are executed by remote processing devices linked through communication networks. In distributed cloud computing environments, program modules can reside on local or remote computing system storage media, including storage devices.

[0043] Exemplary methods

[0044] Figure 1 This is a flowchart of one embodiment of the method for adding watermarks to images disclosed herein. Figure 1 The method shown includes steps S110, S120, S130, and S140. Each step is explained below.

[0045] S110. Perform a preset number of rotation transformations on the initial pixel matrix corresponding to the original image to which the watermark is to be added, to obtain a rotated pixel matrix, wherein the rotation transformation includes a right rotation transformation or a left rotation transformation.

[0046] It should be noted that the pixel matrix involved in the method of this disclosure embodiment can be stored in a two-dimensional array so that the execution subject (e.g., processor) can read it from memory. The preset number of rotation transformations can be set as needed, and this disclosure does not limit it; for example, it is preferably 2 to 4 times.

[0047] Furthermore, this disclosure does not limit the form of the elements in the initial pixel matrix. For example, for a grayscale image, the element can be a numerical value; for a color image in RGB mode, the element can be in the form of (r, g, b); for a color image in ARGB mode, the element can be in the form of (r, g, b, a).

[0048] S120. The pixel values ​​of the watermark are fused with the pixel values ​​at the corresponding positions in the rotated pixel matrix to obtain a fused pixel matrix.

[0049] It should be noted that the watermark can be set according to user needs, and this disclosure does not impose any restrictions on it. For example, if the user is a real estate company, and the target image to which the watermark is to be added is an image of the real estate company's buildings, then the name of the real estate company can be used as the watermark.

[0050] S130. Perform the preset number of inverse rotation transformations on the fused pixel matrix to obtain the restored pixel matrix with the watermark added.

[0051] S140. Based on the restored pixel matrix, a target image with the watermark added is obtained.

[0052] The method for adding watermarks to images based on the above embodiments of this disclosure firstly rotates the initial pixel matrix corresponding to the original image, then fuses the watermark pixel values, and then performs an inverse rotation transformation. This results in the watermark pixel values ​​being randomly distributed to various positions throughout the pixel matrix, thus achieving watermark hiding. In addition, due to the random distribution of watermark pixels, when the watermarked image is modified (graffiti, occlusion, etc.), the probability of watermark loss can be reduced, ensuring that the watermark can be successfully detected and restored, thereby improving the robustness of the watermark.

[0053] The following is about Figure 1 The principles of right-hand and left-hand rotation transformations, as well as the implementation principle of hidden watermarks, are explained in the embodiments.

[0054] The principles of right-hand and left-hand rotation transformations:

[0055] Specifically, taking an initial pixel matrix of order 3 M1 as an example,

[0056]

[0057] When rotated 45° clockwise around the center of the matrix, the 3rd order matrix M1 will become a 5th order matrix M2 (after rotation, negative elements, such as -5, can be inserted around the original matrix elements):

[0058]

[0059] It should be noted here that the "surrounding" of the original matrix element is not limited to all adjacent elements, nor is it limited to pixels adjacent to the original pixel. Specifically, for example, combining matrices M1 and M2, the vertex positions (M2[0][0], M2[0][4], M2[4][0], M2[4][4]) in M2 are not adjacent to any original pixel, but negative elements are still inserted here; the elements located at the vertex positions (M1[0][0], M1[0][2], M1[2][0], M1[2][2]) in M1 are not all surrounded by negative elements. For example, the element 7 located at the position of M1[2][0] is not surrounded by negative elements, but only the adjacent positions above, below and to the right are surrounded by negative elements.

[0060] In addition, the symbols “+” and “-” in matrix M2 and matrices M4 and M5 mentioned below are only used to indicate the positive or negative nature of the corresponding elements and have no other meaning.

[0061] The inventors discovered that the initial pixel matrix might contain elements with values ​​of 0 (such as pixels of black color). Inserting elements with values ​​of 0 or other positive values ​​could easily lead to confusion between the inserted elements and the original elements in the rotated pixel matrix. Therefore, they proposed inserting negative elements, which makes it easier to distinguish between the original matrix elements and the inserted elements. Then, the 5th-order matrix M2 is traversed row by row from left to right, and the non-negative elements are added to a new 3rd-order matrix M3 in left-to-right, top-to-bottom order.

[0062]

[0063] The above process first performs a 45-degree right rotation on matrix M1, and then rearranges its elements; this is called a right rotation of matrix M1. To restore matrix M3 to matrix M1, we need to perform the inverse right rotation operation on matrix M3, i.e., a left rotation.

[0064] Based on the above research, it was found that the right and left rotation transformations of a 3rd order matrix have the following properties: when a 3rd order matrix is ​​subjected to a right rotation transformation once, it can be restored by a left rotation transformation once; when a 3rd order matrix is ​​subjected to m right rotation transformations, it can be restored by m left rotation transformations.

[0065] It has been verified that the properties of the right and left rotation transformations of the above-mentioned 3rd order matrix can be extended to N-order matrices: when an N-order matrix is ​​subjected to m right rotation transformations, it can be restored by m left rotation transformations.

[0066] Based on the above analysis, it can be seen that the left rotation transformation and the right rotation transformation are each other's inverse rotation transformations. That is, when the rotation transformation is a right rotation transformation, the corresponding inverse rotation transformation is a left rotation transformation; conversely, when the rotation transformation is a left rotation transformation, the corresponding inverse rotation transformation is a right rotation transformation.

[0067] The principle behind hiding watermarks:

[0068] Some elements in matrix M3 are marked, for example, by replacing the original values ​​with -1. It's important to note that replacing some elements in M3 with -1 simulates adding the watermark's pixel value to the corresponding position in the pixel matrix. The position of the -1 replacement can be arbitrary; that is, the watermark can be added to any position in the initial pixel matrix of the target image.

[0069] For example, let matrix M3[1][1] = -1, M3[1][2] = -1, and we get matrix M4:

[0070]

[0071] Then, by performing a left rotation transformation on matrix M4, we can obtain matrix M5:

[0072]

[0073] Comparing matrix M5 with the original matrix M1, it can be seen that the positions of the marked elements are randomly distributed within matrix M5, while the other elements are restored to their original positions.

[0074] By performing a right-hand rotation on the initial pixel matrix M1 to make its elements unordered, we obtain matrix M3. Then, we mark some elements in matrix M3 (simulating watermarking), resulting in matrix M4. Finally, we perform a left-hand rotation on matrix M4 to obtain matrix M5, which is the pixel matrix with the watermark added. Since the -1 pixel value used as the simulated watermark is randomly distributed throughout the pixel matrix, the watermark can be hidden. Furthermore, when the watermarked image is modified, the probability of watermark information loss is reduced, improving the robustness of the watermark.

[0075] In addition, when using the method of adding watermarks to an image according to this disclosure, the calculation process only involves a few transformations of the pixel matrix, so the processing speed is fast and the time consumption is short (the time is basically controlled at the millisecond level), which improves the efficiency of adding watermarks.

[0076] exist Figure 1Based on the embodiment, before step S110, the following steps may be included: detecting whether the row dimension and column dimension of the pixel matrix of the original image are equal; if the row dimension and column dimension of the pixel matrix of the original image are equal, the pixel matrix of the original image is used as the initial pixel matrix; otherwise, if the row dimension and column dimension of the pixel matrix of the original image are not equal, the row or column with the smaller dimension is padded to obtain the initial pixel matrix.

[0077] Depending on the circumstances, the above-mentioned "padding of rows or columns with smaller dimensions in the row and column dimensions" can be achieved in any available manner. For example, if the row dimension of the initial pixel matrix is ​​greater than the column dimension, pixels can be added column by column after the last column of the initial pixel matrix until the column dimension matches the row dimension. As another example, if the row dimension of the initial pixel matrix is ​​less than the column dimension, pixels can be added row by row after the last row of the initial pixel matrix until the row dimension matches the column dimension.

[0078] In an optional example, such as Figure 3a The original image to be watermarked shown has a resolution of 1000*1200 (i.e., Figure 3b If the original image region 301 is given, then the corresponding initial pixel matrix is ​​a matrix of 1000 rows * 1200 columns. Therefore, 200 * 1000 pixels can be added after the 1000th row to obtain a 1200 * 1200 pixel matrix as the initial pixel matrix. Specifically, this can be implemented by inserting pixels into the initial pixel matrix using an algorithm; alternatively, refer to... Figure 3b The pixel padding area 302 in the image can have pixel values ​​of (R:0, G:0, B:0), which is black. For cases where the row dimension is greater than the column dimension, refer to the example above; further details are omitted here.

[0079] In an optional example, the row and column dimensions of the initial pixel matrix can be detected by comparing the row and column dimensions of the two-dimensional array storing the initial pixel matrix.

[0080] By determining the row and column dimensions of the pixel matrix corresponding to the original image and performing pixel padding as described above, we can ensure that the pixel matrix of the original image is a square matrix, thus ensuring that rotation or inverse rotation transformations based on the pixel matrix can be implemented in subsequent steps.

[0081] exist Figure 1 Based on the embodiments, and based on the principles of the right-hand and left-hand rotation transformations described above, step S110, "performing a preset number of rotation transformations on the initial pixel matrix corresponding to the original image to which the watermark is to be added, to obtain a rotated pixel matrix, wherein the rotation transformation includes a right-hand or left-hand rotation transformation," can be implemented in the following available ways.

[0082] For example, when the rotation transformation is a first-direction rotation transformation, the initial pixel matrix corresponding to the original image to which the watermark is to be added undergoes a preset number of rotation transformations, including:

[0083] Step A: Rotate the initial pixel matrix 45 degrees in the plane along the second direction, using the center of the initial pixel matrix as the rotation axis. Then, insert negative elements around the original pixels of the initial pixel matrix to obtain a transformed N-order pixel matrix. The order of the initial pixel matrix before transformation is n, where N equals 2n-1, and both N and n are positive integers. Step B: Traverse the transformed N-order pixel matrix row by row from left to right and from top to bottom. Add the non-negative elements encountered to a new matrix in the same order, obtaining a first pixel matrix after one first-direction transformation. The order of the first pixel matrix after one first-direction transformation is the same as the order of the initial pixel matrix before transformation. Step C: Record the position of the original pixel in the transformed N-order pixel matrix to complete one first-direction transformation of the initial pixel matrix. Iterate through steps A to C until a preset number of first-direction transformations of the initial pixel matrix are completed.

[0084] Specifically, if the first direction rotation transformation is a right-hand rotation transformation, then the second direction is clockwise; if the first direction rotation transformation is a left-hand rotation transformation, then the second direction is counterclockwise.

[0085] In an optional example, based on the above implementation of step S110, for Figure 3b The original image shown is subjected to three right-hand rotations on its initial pixel matrix. The resulting pixel matrix can be used to obtain... Figure 3c The image shown.

[0086] It should be noted that in each iteration, step C can use matrix markers M[][] to record the position of each original pixel in the currently transformed N-order pixel matrix. For example, M[1][3] represents the position of an original pixel in the 2nd row and 4th column of the currently transformed N-order pixel matrix. The row and column numbers of the matrix start from 0. For example, if N equals 5, it means that the currently transformed N-order pixel matrix is ​​a 5-order matrix. The row numbers of this 5-order matrix are from top to bottom, taking values ​​from 0 to 4, with 0 representing the first row. The column numbers are similar, taking values ​​from 0 to 4 from left to right, with 0 representing the first column.

[0087] In step D above, "iteration" refers to continuing to execute corresponding steps based on the results of the preceding steps; that is, the result of each iteration serves as the initial value for the next iteration. Specifically, in the first step A, the initial pixel matrix is ​​rotated 45 degrees (clockwise or counterclockwise) in the plane, with the center of the initial pixel matrix as the rotation axis. Therefore, in the second iteration, the first pixel matrix obtained in step B needs to be rotated 45 degrees (clockwise or counterclockwise) in the plane, with the center of the first pixel matrix as the rotation axis. Other steps follow the same principle.

[0088] The preset number of times can be set according to needs, and this disclosure does not impose any restrictions. For example, it is preferably 3 to 4 times.

[0089] As mentioned earlier, through the above multiple rotation transformations, the pixel values ​​of the watermark can be randomly distributed in the restored pixel matrix, which is beneficial for hiding the watermark information in the future. It can also reduce the probability of watermark information loss when the watermarked image is modified, thereby improving the robustness of the watermark.

[0090] like Figure 2 As shown, in Figure 1 Based on the embodiment, step S120 may include steps S1201 and S1202. Each step will be described below.

[0091] S1201. Determine the corresponding position of the watermark in the rotating pixel matrix based on the content and size of the watermark.

[0092] It should be noted that the watermark can be text, and the content, font size, and pixel values ​​of the text can be set according to requirements; this disclosure does not impose any restrictions on this. The font size is used to measure the size of the pixel area occupied by the text in the rotated pixel matrix, and the pixel value (grayscale value) is used to represent the color of each pixel corresponding to the text.

[0093] In one optional example, determining the watermark addition position in the rotated pixel matrix can be achieved by: establishing a Cartesian coordinate system based on the rotated pixel matrix; and determining the watermark addition position in the Cartesian coordinate system based on the received watermark addition position indication and the content and font size of the text.

[0094] For example, a Cartesian coordinate system XOY can be established based on the origin of the coordinates at position M[0][0] in the rotated pixel matrix M. The watermark position indicator can be, for example, located at the center of the image, at the lower left corner of the image, or at the lower right corner of the image; taking the image center as an example, the center coordinates of the rotated pixel matrix based on the Cartesian coordinate system XOY are determined, and then the pixel coordinates occupied by the watermark are determined based on the center coordinates and the content and font size of the text, which is the watermark addition position, i.e., the corresponding position of the watermark in the rotated pixel matrix.

[0095] S1202. Based on the corresponding position of the watermark in the rotating pixel matrix, the pixel value of the watermark is fused with the pixel value of the corresponding position in the rotating pixel matrix.

[0096] If understood, the above "pixel value fusion" can be achieved in the following way. For example, in an optional example, in the rotated pixel matrix, the pixel value of the text is superimposed with the pixel value located at the corresponding position in the rotated pixel matrix. Specifically, based on the optional example in step S1201, in the Cartesian coordinate system XOY established based on the rotated pixel matrix, the pixel value of the text is superimposed with the pixel value of the pixel located at the pixel coordinates occupied by the watermark text in the rotated pixel matrix.

[0097] Taking the rotational transformation as a right-handed transformation as an example, in Figure 3c By adding a watermark to the rotated pixel matrix corresponding to the image shown, as described in the example above, we can obtain the following result: Figure 3d The image shown has been watermarked.

[0098] exist Figure 1 Based on the above three embodiments, step S130, "performing the fused pixel matrix inverse rotation transformation the preset number of times to obtain the restored pixel matrix with the watermark added," can be implemented in the following available ways.

[0099] For example, when the rotation transformation is a third-direction rotation transformation, the fused pixel matrix undergoes the preset number of inverse rotation transformations, including: Step ①, creating a new N-order pixel matrix, where the initial elements are all negative; Step ②, traversing the fused pixel matrix row by row in a left-to-right, top-to-bottom order, and then adding the traversed pixels to the new N-order pixel matrix according to the positions of the original pixels in the transformed N-order pixel matrix, replacing the negative elements at the corresponding positions; Step ③, using the center of the new N-order pixel matrix... Using the rotation axis as the center, rotate the new N-order pixel matrix 45 degrees in the fourth direction in the plane, and then delete the pixel rows and columns with all negative values ​​in the new N-order pixel matrix to complete one inverse rotation transformation of the fused pixel matrix, resulting in a second pixel matrix after one inverse rotation transformation, wherein the order of the second pixel matrix is ​​equal to n, where n is the order of the initial pixel matrix before the transformation, and n is a positive integer; Step ④: Iterate through steps ① to ③ until the preset number of inverse rotation transformations of the fused pixel matrix are completed.

[0100] Specifically, if the third-direction rotation transformation is a right-hand rotation transformation, then the fourth direction is counterclockwise; if the third-direction rotation transformation is a left-hand rotation transformation, then the fourth direction is clockwise.

[0101] In an optional example, based on the above implementation of step S130, for Figure 3d The fused pixel matrix corresponding to the fused image shown undergoes three left-hand rotations. The resulting restored pixel matrix can be used to obtain... Figure 3e The image shown has an invisible watermark.

[0102] exist Figure 1 Based on the above three embodiments, step S140 "obtaining the target image with the watermark added based on the restored pixel matrix" can be implemented in the following ways, depending on the circumstances.

[0103] For example, if the row dimension and column dimension of the pixel matrix of the original image are not equal, determine the first position of the newly added pixel row or pixel column in the pixel matrix of the original image; delete the pixel row or pixel column corresponding to the first position from the restored pixel matrix; and use the modified restored pixel matrix to determine the target image to which the watermark is added. In an optional example, refer to... Figure 3e The image shown can be modified by deleting the pixel rows in the pixel padding area (first position) based on the example method described above.

[0104] Alternatively, for example, if the row dimension and column dimension of the pixel matrix of the original image are equal, the target image to which the watermark is added can be directly determined using the restored pixel matrix.

[0105] By performing the above operations, we can ensure that the output image corresponds to the original image, rather than an intermediate image with pixel padding.

[0106] The method for adding watermarks to an image disclosed herein involves first performing rotation transformation, watermark pixel fusion, and inverse rotation transformation on the initial pixel matrix. This allows the watermark pixels to be randomly distributed across the entire pixel matrix, thereby achieving watermark hiding (i.e., realizing an invisible watermark effect). Furthermore, when the watermarked image is modified (e.g., ...), the watermark is still present. Figure 3g The graffiti shown, such as Figure 3h When the image is occluded (as shown), the probability of missing watermark information can be reduced, ensuring that the watermark can be successfully detected and restored, thus improving the robustness of the watermark. Secondly, since the watermarking process only involves a few transformations of the pixel matrix, the processing speed is fast and the time consumption is short (average time 500 milliseconds), improving the efficiency of watermarking. In addition, the watermark pixels are randomly distributed throughout the pixel matrix, making it imperceptible to the human eye to distinguish between an image with a watermark added using the method disclosed herein and an image without a watermark, resulting in better fidelity.

[0107] Figure 4 This is a flowchart of an embodiment of the image watermark detection method of this disclosure, wherein the image to be detected, which has a watermark, is an image using the method described above in this disclosure. Figure 1 The watermark is added using the method for adding watermarks to images described in Embodiment 3. Figure 4 The detection method shown includes steps S410 to S430.

[0108] S410. Based on the acquired target image with added watermark, determine the target pixel matrix of the target image;

[0109] S420. Perform a preset number of rotation transformations on the target pixel matrix to obtain a rotated detection pixel matrix, wherein the rotation transformation includes a right rotation transformation or a left rotation transformation.

[0110] S430. Based on the detected pixel matrix, the watermark in the target image is obtained.

[0111] If understood, based on the foregoing descriptions of the right-hand and left-hand transformation principles in this disclosure, and the aforementioned provisions of this disclosure... Figure 1 As can be seen from the three embodiments, due to the inverse rotation transformation, the position of the pixel value of the watermark is randomly distributed in the restored pixel matrix. Therefore, it is necessary to restore the position of the pixel value of the watermark from the random distribution state to the distribution state of the fusion stage through another rotation transformation.

[0112] Without knowing the preset number of times, the target pixel matrix can be rotated and transformed successively, and then it can be confirmed whether the position of the watermark pixel value is restored from the random distribution state to the distribution state of the fusion stage.

[0113] The watermark detection method in the image disclosed in this embodiment only requires rotating the target pixel matrix corresponding to the target image with the added watermark to restore the hidden watermark information. This method is simpler and more efficient because it does not rely on the original image. Furthermore, since the rotation transformation calculation is a lightweight operation, it is relatively quick (average time is 300 milliseconds).

[0114] exist Figure 4 Based on the embodiment, step S410 can be implemented in the following way: detect whether the row dimension and column dimension of the pixel matrix of the target image are equal; if the row dimension and column dimension of the pixel matrix of the target image are equal, use the pixel matrix of the target image as the target pixel matrix; otherwise, if the row dimension and column dimension of the pixel matrix of the target image are not equal, pad the row or column with the smaller dimension to obtain the target pixel matrix.

[0115] If understood, the pixel matrix of the target image can be obtained from a storage unit (e.g., the processor's memory), whereby the processor can process the read target image to obtain the pixel matrix of the image and store it in memory or other external storage as a two-dimensional array.

[0116] As described above, by determining the row and column dimensions of the pixel matrix of the target image and padding the pixel rows and columns based on the determination results, it can be ensured that the target pixel matrix is ​​a square matrix, thereby enabling subsequent rotation transformations based on the target pixel matrix to be implemented.

[0117] exist Figure 4 Based on the embodiments, step S420 can be implemented in the following available ways.

[0118] For example, when the rotation transformation is a first-direction rotation transformation, performing a preset number of rotation transformations on the target pixel matrix includes: Step I, rotating the target pixel matrix 45 degrees in the plane along the second direction with the center of the target pixel matrix as the rotation axis, and then inserting negative value elements around the original pixels of the target pixel matrix to obtain a transformed N-order pixel matrix; wherein, the order N is equal to the order of the target pixel matrix multiplied by 2 and then subtracted by 1, and N is a positive integer; Step II, traversing the transformed N-order pixel matrix row by row in the order from left to right and from top to bottom, adding the non-negative value elements encountered in the traversal to a new matrix in the order from left to right and from top to bottom, completing one rotation transformation of the target pixel matrix along the first direction, and obtaining a target pixel matrix after one rotation transformation along the first direction; wherein, the order of the target pixel matrix after one rotation transformation along the first direction is the same as the order of the target pixel matrix before the transformation; Step III, iteratively executing steps I to II until the preset number of rotation transformations along the first direction on the target pixel matrix is ​​completed.

[0119] Specifically, if the first direction rotation transformation is a right-hand rotation transformation, then the second direction is clockwise; if the first direction rotation transformation is a left-hand rotation transformation, then the second direction is counterclockwise.

[0120] In an optional example, for Figure 3e The watermarked target image shown can be obtained through three right-hand rotations, based on the implementation of step S420 described above. Figure 3d The image shown displays the watermark.

[0121] Furthermore, watermark pixel values ​​typically include transparency in addition to pixel information. For example, watermark pixel values ​​can be represented as RGBA, where R, G, and B are pixel sub-units, R represents red, G represents green, and B represents blue; while A is the first letter of alpha, representing transparency. Therefore, if a rotation transformation is directly used to restore the watermark, even if the watermark is restored, it may be difficult to see due to its high transparency.

[0122] To solve the problem of unclear watermarks, based on Figure 4 Based on the embodiments, the watermark detection method in the image further includes the following steps: 1) traversing the pixel matrix displaying the image watermark row by row in order from left to right and from top to bottom; 2) modifying the pixel values ​​based on the matching relationship between the pixel values ​​of the pixel sub-units in the traversed pixels and preset conditions; wherein, the preset conditions are: based on the watermark pixel information, determining that the pixel value of one color pixel sub-unit is simultaneously greater than the pixel values ​​of the other two color pixel sub-units.

[0123] More preferably, for step 2) above, if the pixel value of the pixel sub-unit in the traversed pixel meets the preset condition, the pixel value of the pixel sub-unit in the pixel is set to the first preset pixel value; if the pixel value of the pixel sub-unit in the traversed pixel does not meet the preset condition, the pixel value of the pixel sub-unit in the pixel is set to the second preset pixel value.

[0124] In an optional example, refer to Figure 3d The text content of watermark 303 is "This is a watermark". The pixel value of the watermark is RGBA(0,255,0,20), that is, the pixel value (grayscale value) of the green (G) pixel subunit is 255; therefore, the preset condition here can be expressed as G>R&&G>B. Based on this preset condition, the pixel matrix displaying the image watermark is traversed row by row in a left-to-right, top-to-bottom order. The pixel values ​​of the pixel subunits in the pixels that meet the preset condition are all set to 255, that is, white RGB(255, 255, 255); the pixel values ​​of the pixel subunits in the pixels that do not meet the preset condition are all set to 0, that is, black RGB(0, 0, 0). The processed image is as follows. Figure 3f As shown, the watermark is clearer (the text of the watermark is "This is a watermark") and easier to identify.

[0125] The image watermark detection method of this disclosure embodiment only requires rotating the target pixel matrix corresponding to the target image with the added watermark to restore the pixel value position distribution of the watermark. It does not depend on the original image and is therefore simpler. In addition, since the calculation of rotation transformation is a lightweight operation, it takes less time (average time is 300 milliseconds) and is therefore more efficient.

[0126] Furthermore, the watermark detection method in images using embodiments of this disclosure can be applied to, for example... Figure 3g , 3h When detecting a target image with added watermarks that has been modified (e.g., graffiti) or obscured (e.g., a black mask with 80% transparency), the watermark can still be clearly detected because the pixel values ​​of the watermark are randomly distributed throughout the image, and due to optimization based on the aforementioned preset conditions. Figure 3e As shown in the figure, the watermark can be detected more accurately and presented clearly.

[0127] Exemplary device

[0128] It should be understood that the methods for adding watermarks to images described in the foregoing embodiments herein can also be similarly applied to the following image watermarking apparatus for similar extensions; and the methods for detecting watermarks in images described in the foregoing embodiments herein can also be similarly applied to the following image watermark detection apparatus for similar extensions. For simplicity, they are not described in detail.

[0129] Figure 5 This is a schematic diagram of one embodiment of the apparatus for adding watermarks to images disclosed herein. Figure 5 As shown, the device 500 for adding a watermark to an image includes: a rotation transformation unit 510, used to perform a preset number of rotation transformations on the initial pixel matrix corresponding to the original image to which the watermark is to be added, to obtain a rotated pixel matrix, wherein the rotation transformation includes a right-hand rotation transformation or a left-hand rotation transformation; a pixel fusion unit 520, used to fuse the pixel values ​​of the watermark with the pixel values ​​at corresponding positions in the rotated pixel matrix, to obtain a fused pixel matrix; an inverse transformation unit 530, used to perform the preset number of inverse rotation transformations on the fused pixel matrix, to obtain a restored pixel matrix with the watermark added; and an output unit 540, used to obtain a target image with the watermark added based on the restored pixel matrix.

[0130] In an optional example, the apparatus further includes a dimension verification unit, used to detect whether the row dimension and column dimension of the pixel matrix of the original image are equal; if the row dimension and column dimension of the pixel matrix of the original image are equal, the pixel matrix of the original image is used as the initial pixel matrix; otherwise, if the row dimension and column dimension of the pixel matrix of the original image are not equal, the row or column with the smaller dimension is padded to obtain the initial pixel matrix.

[0131] In an optional example, when the rotation transformation is a first-direction rotation transformation, the rotation transformation unit 510 is used to: A. Rotate the initial pixel matrix 45 degrees in the plane along the second direction with the center of the initial pixel matrix as the rotation axis, and then insert negative value elements around the original pixels of the initial pixel matrix to obtain a transformed N-order pixel matrix; wherein, the order of the initial pixel matrix before the transformation is n, the order N is equal to 2n-1, and N and n are both positive integers; B. Traverse the transformed N-order pixel matrix row by row in the order from left to right and from top to bottom, and add the non-negative value elements encountered in the order from left to right and from top to bottom. Add the pixel to a new matrix to obtain a first pixel matrix after a first directional transformation; wherein the order of the first pixel matrix after the first directional transformation is the same as the order of the initial pixel matrix before the transformation; C. Record the position of the original pixel in the transformed N-order pixel matrix to complete a first directional transformation of the initial pixel matrix; D. Iteratively execute steps A to C until a preset number of first directional transformations of the initial pixel matrix are completed; wherein, if the first directional rotation transformation is a right-hand rotation transformation, the second direction is clockwise, and if the first directional rotation transformation is a left-hand rotation transformation, the second direction is counterclockwise.

[0132] Figure 6 This is a schematic diagram of another embodiment of the apparatus for adding watermarks to images disclosed herein. Figure 6 As shown, the pixel fusion unit 520 includes: a watermark addition position determination subunit 5201, used to determine the corresponding position of the watermark in the rotating pixel matrix according to the content and size of the watermark; and a watermark fusion subunit 5202, used to fuse the pixel value of the watermark with the pixel value of the corresponding position in the rotating pixel matrix based on the corresponding position of the watermark in the rotating pixel matrix.

[0133] In an optional example, the watermark includes text, and the watermark fusion subunit 5202 is further configured to: superimpose the pixel value of the text with the pixel value located at the corresponding position in the rotated pixel matrix.

[0134] In an optional example, when the rotation transformation is a third-direction rotation transformation, the inverse transformation unit 530 is used to: ① create a new N-order pixel matrix, wherein the initial elements are all negative elements; ② traverse the fused pixel matrix row by row in a left-to-right, top-to-bottom order, and then add the traversed pixels to the new N-order pixel matrix according to the positions of the original pixels in the transformed N-order pixel matrix, replacing the negative elements at the corresponding positions; ③ rotate the new N-order pixel matrix 45 degrees in the fourth direction in the plane with the center of the new N-order pixel matrix as the rotation axis, and then delete the... The new N-order pixel matrix consists of rows and columns of pixels with all negative values. A first inverse rotation transformation is performed on the fused pixel matrix to obtain a second pixel matrix after the first inverse rotation transformation. The order of the second pixel matrix is ​​equal to n, where n is the order of the initial pixel matrix before the transformation, and n is a positive integer. ④ Iteratively execute steps ① to ③ until a preset number of inverse rotation transformations are performed on the fused pixel matrix. If the third-direction rotation transformation is a right-hand rotation, the fourth direction is counter-clockwise; if the third-direction rotation transformation is a left-hand rotation, the fourth direction is clockwise.

[0135] In an optional example, the output unit 540 is further configured to: if the row dimension and column dimension of the pixel matrix of the original image are not equal, determine the first position of the newly added pixel row or pixel column in the pixel matrix of the original image; delete the pixel row or pixel column corresponding to the first position from the restored pixel matrix; determine the target image to which the watermark is added using the modified restored pixel matrix; or, if the row dimension and column dimension of the pixel matrix of the original image are equal, directly determine the target image to which the watermark is added using the restored pixel matrix.

[0136] The device for adding watermarks to an image disclosed herein adds a watermark to a target image. First, by performing rotation transformation, watermark pixel fusion, and inverse rotation transformation on the initial pixel matrix, the watermark pixels can be randomly distributed to various positions throughout the pixel matrix, thereby achieving watermark hiding (i.e., achieving the effect of an invisible watermark). Furthermore, when the watermarked image is modified (e.g., ...), the watermarked pixels are still present. Figure 3g The graffiti shown, such as Figure 3h When the image is occluded (as shown), the probability of missing watermark information can be reduced, ensuring that the watermark can be successfully detected and restored, thus improving the robustness of the watermark. Secondly, since the watermarking process only involves a few transformations of the pixel matrix, the processing speed is fast and the time consumption is short (average time 500 milliseconds), improving the efficiency of watermarking. In addition, the watermark pixels are randomly distributed throughout the pixel matrix, making it imperceptible to the human eye to distinguish between an image with a watermark added using the method disclosed herein and an image without a watermark, resulting in better fidelity.

[0137] Figure 7 This is a schematic diagram of the structure of one embodiment of the watermark detection device in the image disclosed herein. For example... Figure 7 As shown, the watermark detection device 700 in an image includes: a pixel matrix determination unit 710, used to determine the target pixel matrix of the target image based on the acquired target image with added watermark; a detection transformation unit 720, used to perform a preset number of rotation transformations on the target pixel matrix to obtain a rotation-transformed detection pixel matrix, wherein the rotation transformation includes a right rotation transformation or a left rotation transformation; and a detection output unit 730, used to obtain the watermark in the target image based on the detection pixel matrix.

[0138] In an optional example, the pixel matrix determining unit 710 is further configured to: detect whether the row dimension and column dimension of the pixel matrix of the target image are equal; if the row dimension and column dimension of the pixel matrix of the target image are equal, use the pixel matrix of the target image as the target pixel matrix; if the row dimension and column dimension of the pixel matrix of the target image are not equal, pad the row or column with the smaller dimension to obtain the target pixel matrix.

[0139] In an optional example, when the rotation transformation is a first-direction rotation transformation, the detection transformation unit 720 is used to: I. Rotate the target pixel matrix 45 degrees in the plane along the second direction with the center of the target pixel matrix as the rotation axis, and then insert negative value elements around the original pixels of the target pixel matrix to obtain a transformed N-order pixel matrix; wherein, the order N is equal to the order of the target pixel matrix multiplied by 2 and then subtracted by 1, and N is a positive integer; II. Traverse the transformed N-order pixel matrix row by row in the order from left to right and from top to bottom, and sort the non-negative value elements encountered in the traversal in the order from left to right and from top to bottom. The order of the elements is added to a new square matrix, completing one rotation transformation of the target pixel matrix along the first direction, resulting in a target pixel matrix after one rotation transformation along the first direction; wherein, the order of the target pixel matrix after one rotation transformation along the first direction is the same as the order of the target pixel matrix before the transformation; III. Iteratively execute steps I to II until the target pixel matrix is ​​rotated a preset number of times along the first direction; wherein, if the first direction rotation transformation is a right rotation transformation, the second direction is clockwise, and if the first direction rotation transformation is a left rotation transformation, the second direction is counterclockwise.

[0140] In an optional example, the detection output unit 730 includes: a traversal subunit for traversing the detection pixel matrix row by row in a left-to-right, top-to-bottom order; and a pixel modification subunit for modifying the pixel values ​​based on the matching relationship between the pixel values ​​of the traversed pixel subunits and preset conditions to obtain the watermark in the target image; wherein the preset conditions are: based on the pixel values ​​of the watermark, determining that the pixel values ​​of one color pixel subunit are simultaneously greater than the pixel values ​​of the other two color pixel subunits.

[0141] In an optional example, the pixel modification subunit is further configured to: set all pixel values ​​of the pixel subunits in the traversed pixels to a first preset pixel value if the pixel value of the pixel subunit in the traversed pixels meets the preset condition; and set all pixel values ​​of the pixel subunits in the traversed pixels to a second preset pixel value if the pixel value of the pixel subunit in the traversed pixels does not meet the preset condition.

[0142] The image watermark detection device according to the embodiments of this disclosure only needs to perform a rotation transformation on the target pixel matrix corresponding to the target image with the added watermark during watermark detection. This allows for the restoration of the hidden watermark information without relying on the original image, making it simpler and more efficient. Furthermore, since the rotation transformation calculation is a lightweight operation, it takes less time (an average of 300 milliseconds).

[0143] Exemplary electronic devices

[0144] In addition, this disclosure also provides an electronic device, including:

[0145] Memory, used to store computer programs;

[0146] A processor is configured to execute a computer program stored in the memory, wherein when the computer program is executed, it implements the method for adding a watermark to an image and the method for detecting a watermark in an image as described in any of the above embodiments of the present disclosure.

[0147] Figure 8 This is a schematic diagram of the structure of an application embodiment of the electronic device disclosed herein. Below, reference is made to… Figure 8 This describes an electronic device according to embodiments of the present disclosure. The electronic device may be either or both of a first device and a second device, or a standalone device independent of them, which may communicate with the first device and the second device to receive acquired input signals from them.

[0148] like Figure 8 As shown, the electronic device includes one or more processors and memory.

[0149] A processor can be a central processing unit (CPU) or other form of processing unit with data processing and / or instruction execution capabilities, and can control other components in an electronic device to perform desired functions.

[0150] The memory may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, random access memory (RAM) and / or cache memory. The non-volatile memory may include, for example, read-only memory (ROM), hard disk, flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and a processor may execute the program instructions to implement the methods for adding watermarks to images and the methods for detecting watermarks in images, as well as / or other desired functions, according to the various embodiments of this disclosure described above.

[0151] In one example, the electronic device may also include input devices and output devices, which are interconnected via a bus system and / or other forms of connection mechanism (not shown).

[0152] In addition, the input device may include, for example, a keyboard, a mouse, etc.

[0153] This output device can output various information to the outside, including determined distance information, direction information, etc. The output device may include, for example, a display, a speaker, a printer, and a communication network and its connected remote output devices, etc.

[0154] Of course, for the sake of simplicity, Figure 8 Only some of the components of the electronic device relevant to this disclosure are shown, omitting components such as buses, input / output interfaces, etc. In addition, the electronic device may include any other suitable components depending on the specific application.

[0155] In addition to the methods and devices described above, embodiments of this disclosure may also be computer program products, including computer program instructions that, when executed by a processor, cause the processor to perform the steps in the methods for adding watermarks to images and the methods for detecting watermarks in images according to various embodiments of this disclosure as described in the foregoing portion of this specification.

[0156] The computer program product can be written in any combination of one or more programming languages ​​to perform the operations of the embodiments of this disclosure. The programming languages ​​include object-oriented programming languages ​​such as Java and C++, as well as conventional procedural programming languages ​​such as C or similar languages. The program code can be executed entirely on a user's computing device, partially on a user's computing device, as a standalone software package, partially on a user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0157] Furthermore, embodiments of this disclosure may also be computer-readable storage media storing computer program instructions that, when executed by a processor, cause the processor to perform the steps in the methods for adding watermarks to images and the methods for detecting watermarks in images according to various embodiments of this disclosure as described in the foregoing portion of this specification.

[0158] The computer-readable storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may, for example, include, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0159] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as ROM, RAM, magnetic disk, or optical disk.

[0160] The basic principles of this disclosure have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in this disclosure are merely examples and not limitations, and should not be considered as essential features of each embodiment of this disclosure. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the scope of this disclosure to the necessity of employing the aforementioned specific details for implementation.

[0161] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For system embodiments, since they largely correspond to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0162] The block diagrams of devices, apparatuses, devices, and systems disclosed herein are merely illustrative examples and are not intended to require or imply that they must be connected, arranged, or configured in the manner shown in the block diagrams. As those skilled in the art will recognize, these devices, apparatuses, devices, and systems can be connected, arranged, and configured in any manner. Words such as “comprising,” “including,” “having,” etc., are open-ended terms meaning “including but not limited to,” and are used interchangeably with them. The terms “or” and “and” as used herein refer to the terms “and / or,” and are used interchangeably with them unless the context clearly indicates otherwise. The term “such as” as used herein refers to the phrase “such as but not limited to,” and is used interchangeably with it.

[0163] The methods and apparatus of this disclosure may be implemented in many ways. For example, they may be implemented by software, hardware, firmware, or any combination of software, hardware, and firmware. The above-described order of steps for the methods is for illustrative purposes only, and the steps of the methods of this disclosure are not limited to the order specifically described above unless otherwise specifically stated. Furthermore, in some embodiments, this disclosure may also be implemented as a program recorded on a recording medium, the program including machine-readable instructions for implementing the methods according to this disclosure. Thus, this disclosure also covers recording media storing programs for performing the methods according to this disclosure.

[0164] It should also be noted that in the apparatus, devices, and methods of this disclosure, the components or steps can be disassembled and / or recombined. These disassemblies and / or recombinations should be considered as equivalent solutions to this disclosure.

[0165] The above description of the disclosed aspects is provided to enable any person skilled in the art to make or use this disclosure. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein may be applied to other aspects without departing from the scope of this disclosure. Therefore, this disclosure is not intended to be limited to the aspects shown herein, but rather to be carried out within the widest scope consistent with the principles and novel features disclosed herein.

[0166] The above description has been given for purposes of illustration and description. Furthermore, this description is not intended to limit the embodiments of this disclosure to the forms disclosed herein. Although numerous exemplary aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, alterations, additions, and sub-combinations therein.

Claims

1. A method of adding a watermark to an image, characterized by, The method comprises the following steps: performing a preset number of rotation transformations on an initial pixel matrix corresponding to an original image to which a watermark is to be added, to obtain a rotated pixel matrix, wherein the rotation transformations comprise right rotation transformations or left rotation transformations; fusing pixel values of the watermark with pixel values at corresponding positions in the rotated pixel matrix, to obtain a fused pixel matrix; performing inverse rotation transformations on the fused pixel matrix for the preset number of times, to obtain a restored pixel matrix to which the watermark is added; based on the restored pixel matrix, obtaining a target image to which the watermark is added.

2. The method of claim 1, wherein, Before the step of performing a preset number of rotation transformations on an initial pixel matrix corresponding to an original image to which a watermark is to be added, the method comprises the following steps: detecting whether the row dimension and the column dimension of the pixel matrix of the original image are equal; if the row dimension and the column dimension of the pixel matrix of the original image are equal, taking the pixel matrix of the original image as the initial pixel matrix; otherwise, if the row dimension and the column dimension of the pixel matrix of the original image are not equal, padding the row or column with a smaller dimension to obtain the initial pixel matrix.

3. The method of claim 2, wherein when the rotation transformation is a first direction rotation transformation, the step of performing a preset number of rotation transformations on an initial pixel matrix corresponding to an original image to which a watermark is to be added comprises the following steps: A. taking the center of the initial pixel matrix as a rotation axis, rotating the initial pixel matrix by 45 degrees in a second direction in a plane, and then inserting negative value elements around original pixels of the initial pixel matrix, to obtain an N-order pixel square matrix after transformation; wherein the order of the initial pixel matrix before transformation is n, the order N is equal to 2n-1, and N and n are positive integers; B. traversing the N-order pixel square matrix after transformation row by row from left to right and from top to bottom, and adding non-negative value elements traversed to a new square matrix from left to right and from top to bottom, to obtain a first pixel square matrix after first direction transformation once; wherein the order of the first pixel square matrix after first direction transformation once is the same as the order of the initial pixel matrix before transformation; C. recording the position of the original pixel in the N-order pixel square matrix after transformation, to complete first direction transformation once on the initial pixel matrix; D. iteratively performing steps A to C until the preset number of first direction transformations on the initial pixel matrix is completed; wherein if the first direction rotation transformation is a right rotation transformation, the second direction is a clockwise direction, and if the first direction rotation transformation is a left rotation transformation, the second direction is an anticlockwise direction.

4. The method of claim 3, wherein when the rotation transformation is a third direction rotation transformation, the step of performing inverse rotation transformations on the fused pixel matrix for the preset number of times comprises the following steps: ① creating a new N-order pixel square matrix, wherein the initial elements are negative value elements; ② traversing the fused pixel matrix row by row from left to right and from top to bottom, and then adding pixels traversed to the new N-order pixel square matrix according to the position of the original pixel in the N-order pixel square matrix after transformation, to replace negative value elements at corresponding positions. ​ ​ ③, taking the center of the new N-order pixel square as a rotation axis, rotating the new N-order pixel square by 45 degrees in a fourth direction in the plane, and then deleting a pixel row with all negative values and a pixel column with all negative values in the new N-order pixel square, to complete one inverse rotation transformation of the fused pixel matrix, to obtain a second pixel square after one inverse rotation transformation, wherein an order of the second pixel square is equal to n, n is the order of the initial pixel matrix before transformation, and n is a positive integer; ④, iteratively performing the steps of ① to ③ until a preset number of inverse rotation transformations of the fused pixel matrix are completed; wherein, if the third direction rotation transformation is right rotation transformation, the fourth direction is counterclockwise, and if the third direction rotation transformation is left rotation transformation, the fourth direction is clockwise.

5. The method of claim 2, wherein, The target image with the watermark added is obtained based on the restored pixel matrix, including: If the row dimension and the column dimension of the pixel matrix of the original image are not equal, determining a first position of a newly added pixel row or a newly added pixel column in the pixel matrix of the original image; Deleting the pixel row or the pixel column corresponding to the first position from the restored pixel matrix; Determining the target image with the watermark added by using the modified restored pixel matrix; Or, If the row dimension and the column dimension of the pixel matrix of the original image are equal, directly determining the target image with the watermark added by using the restored pixel matrix.

6. A method of detecting a watermark in an image, characterized by, Including: Based on the obtained target image with the added watermark, determining a target pixel matrix of the target image; Performing a preset number of rotation transformations on the target pixel matrix to obtain a detection pixel matrix after rotation transformation, wherein the rotation transformation includes right rotation transformation or left rotation transformation; Based on the detection pixel matrix, obtaining the watermark in the target image; Wherein, the obtaining of the watermark in the target image based on the detection pixel matrix includes: Traversing the detection pixel matrix row by row in the order from left to right and from top to bottom; Based on a matching relationship between a pixel value of a pixel subunit in the traversed pixel and a preset condition, modifying the pixel value to obtain the watermark in the target image; wherein the pixel subunit includes color pixel subunits corresponding to different colors, and the preset condition is that based on the pixel value of the watermark, it is determined that the pixel value of one color pixel subunit is greater than the pixel values of the other two color pixel subunits.

7. The detection method according to claim 6, characterized in that, The target pixel matrix of the target image is determined based on the obtained target image with the added watermark, including: Detecting whether the row dimension and the column dimension of the pixel matrix of the target image are equal; If the row dimension and the column dimension of the pixel matrix of the target image are equal, taking the pixel matrix of the target image as the target pixel matrix; Otherwise, if the row dimension and the column dimension of the pixel matrix of the target image are not equal, padding the row or column with the smaller dimension to obtain the target pixel matrix.

8. The detection method according to claim 7, characterized in that, When the rotation transformation is the first direction rotation transformation, the performing of the preset number of rotation transformations on the target pixel matrix includes: I. taking the center of the target pixel matrix as a rotation axis, rotating the target pixel matrix by 45 degrees in a second direction in a plane, and then inserting negative value elements around the original pixels of the target pixel matrix to obtain an N-order pixel square matrix after conversion; wherein the order N is equal to the order of the target pixel matrix multiplied by 2 and then reduced by 1, and N is a positive integer; II. traversing the N-order pixel square matrix after conversion row by row from left to right and from top to bottom, adding the non-negative value elements traversed to a new square matrix from left to right and from top to bottom, completing a first direction rotation transformation of the target pixel matrix, and obtaining a target pixel matrix after a first direction rotation transformation; wherein the order of the target pixel matrix after a first direction rotation transformation is the same as the order of the target pixel matrix before conversion; III. iteratively performing steps I to II until a preset number of first direction rotation transformations of the target pixel matrix are completed. If the first direction rotation transformation is a right rotation transformation, the second direction is the clockwise direction, and if the first direction rotation transformation is a left rotation transformation, the second direction is the counterclockwise direction.

9. The detection method according to claim 6, characterized in that, The modification of the pixel value based on the matching relationship between the pixel value of the pixel sub-element in the traversed pixel and the preset condition includes: In the case that the pixel value of the pixel sub-element in the traversed pixel meets the preset condition, the pixel value of the pixel sub-element in the pixel is set to a first preset pixel value; In the case that the pixel value of the pixel sub-element in the traversed pixel does not meet the preset condition, the pixel value of the pixel sub-element in the pixel is set to a second preset pixel value.

10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the method of any one of claims 1-9.

Citation Information

Patent Citations

  • Image checking code generating method based on invertible matrix

    CN101882298A

  • Image processing method and system, storage medium and computing equipment

    CN113393358A