Disclosure of Invention
One or more embodiments of the present disclosure describe a method and an apparatus for writing and reading a digital watermark, which enhance robustness and security of the digital watermark by means of picture blocking and annular reading and writing.
According to a first aspect, there is provided a method for writing a digital watermark, comprising:
reading the first picture to obtain a bit group corresponding to each pixel point in the first picture, wherein the bit group is used for recording pixel values of corresponding pixel points;
acquiring a picture identification code generated aiming at the first picture;
dividing the first picture into a plurality of blocks of a predetermined size;
for each block, determining a first circular ring of a predetermined radius among the blocks;
determining pixel points corresponding to the preset positions on the first circular ring as initial pixel points, and writing preset mark codes in the preset lowest bit LSBs of the bit groups corresponding to the first number of pixel points along the first circular ring from the initial pixel points;
and after the first number of pixel points, sequentially writing the picture identification codes into LSBs corresponding to the pixel points covered by the first circular ring along the first circular ring.
In one embodiment, acquiring the picture identification code generated for the first picture comprises:
generating a copyright number for the first picture;
and encrypting the copyright number to obtain the picture identification code.
In one possible design, the first circle of predetermined radius is set to the largest inscribed circle of the block of predetermined size.
According to one embodiment, a first circle of a predetermined radius is determined in a block by: firstly, determining a reference position in a block, and then determining the position of the first circular ring according to the reference position and the preset radius, wherein the reference position comprises one of the following: the circle center position, the leftmost position of the ring, the rightmost position of the ring, the uppermost position of the ring and the lowermost position of the ring.
In one embodiment, the first number is determined according to the number of bits of the predetermined lowest bit LSB and the number of bits of the predetermined flag code.
According to one embodiment, the picture identification code is written in LSBs corresponding to the pixel points covered by the first circular ring for multiple times in a circulating manner.
According to one embodiment, the method further comprises determining a second ring in the block, the second ring being concentric with the first ring and having a second radius smaller than the predetermined radius of the first ring;
and writing the picture identification codes in the LSBs of the pixel points covered by the second circular ring in sequence along the second circular ring.
Further, a second circle may be determined in the block by first determining the second radius; and then determining the position of the second circular ring according to the circle center position of the first circular ring and the second radius.
According to a second aspect, there is provided a method of reading a digital watermark, comprising:
reading the second picture to obtain bit groups corresponding to all pixel points in the second picture, wherein the bit groups are used for recording pixel values of corresponding pixel points;
determining an alternative circular ring with a preset radius in the second picture;
sequentially taking each pixel point covered by the alternative circular ring as an alternative starting point, and reading the LSB (least significant bit) of the bit group of the pixel points with the preset first number along the alternative circular ring from the alternative starting point to obtain an alternative mark code;
under the condition that the alternative mark code is matched with a preset mark code, determining the alternative circular ring as a first circular ring, and determining a corresponding alternative starting point as a starting pixel point;
sequentially reading LSB bits corresponding to the pixels from the initial pixel after the first number of pixels from the initial pixel among the pixels covered by the first ring to obtain at least one group of digital codes;
forming a set of alternative digital codes at least according to the at least one group of digital codes;
and determining a picture identification code of the second picture according to the alternative digital coding set.
In one embodiment, an alternative circular ring with a preset radius is determined by forming a square block with the side length 2 times the preset radius in the second picture, and determining that an inscribed circle of the square block is a first alternative circular ring; the square is moved to determine a second alternative ring.
In one embodiment, the set of candidate digital codes is formed by adding the at least one set of digital codes to the set of candidate digital codes.
In another embodiment, the digital code with the highest degree of repetition is determined from the at least one group of digital codes and added to the set of candidate digital codes, thereby forming a set of candidate digital codes.
According to one embodiment, among the plurality of groups of digital codes included in the alternative digital code set, the digital code with the highest repetition degree is used as the picture identification code.
In one embodiment, the picture identification code is a copyright identification code, and the method further includes decrypting the copyright identification code to obtain an original copyright number.
According to one embodiment, the method further comprises:
determining a second circular ring in the first circular ring according to a preset second radius, wherein the second circular ring is a concentric circular ring of the first circular ring, and the second radius is smaller than the preset radius of the first circular ring;
and sequentially reading the LSB bits of all the pixel points covered by the second ring along the second ring to obtain at least one group of second digital codes.
In such a case, the at least one set of second digital codes is also added to the set of candidate digital codes, thereby forming a set of candidate digital codes.
According to a third aspect, there is provided a digital watermark writing apparatus comprising:
the image reading unit is configured to read the first image to obtain a bit group corresponding to each pixel point in the first image, and the bit group is used for recording pixel values of corresponding pixel points;
a picture code acquisition unit configured to acquire a picture identification code generated for the first picture;
a block dividing unit configured to divide the first picture into a plurality of blocks of a predetermined size;
a first ring determining unit configured to determine, for each of the blocks, a first ring of a predetermined radius among the blocks;
a flag code writing unit configured to determine a pixel point corresponding to a predetermined position on the first ring as an initial pixel point, and write a predetermined flag code in a predetermined lowest bit LSB of a bit group corresponding to a first number of pixel points along the first ring from the initial pixel point;
and the picture code writing unit is configured to continue to write the picture identification codes in the LSBs corresponding to the pixel points covered by the first circular ring along the first circular ring after the first number of pixel points.
According to a fourth aspect, there is provided a digital watermark reading apparatus comprising:
the picture reading unit is configured to read the second picture to obtain bit groups corresponding to the pixel points in the second picture, and the bit groups are used for recording the pixel values of the corresponding pixel points;
an alternative circle determining unit configured to determine an alternative circle with a predetermined radius in the second picture;
the alternative reading unit is configured to take each pixel point covered by the alternative circular ring as an alternative starting point in sequence, and read the preset lowest bit LSB of the bit group of the preset first number of pixel points along the alternative circular ring from the alternative starting point to obtain an alternative mark code;
the first circular ring determining unit is configured to determine the alternative circular ring as a first circular ring and determine a corresponding alternative starting point as a starting pixel point under the condition that the alternative marking code is matched with a preset mark code;
the first code reading unit is configured to continue to read LSB bits corresponding to the pixels in sequence along the first ring after the first number of pixels from the initial pixel among the pixels covered by the first ring to obtain at least one group of digital codes;
the coding set forming unit is configured to form a candidate digital coding set at least according to the at least one group of digital codes;
a picture code determination unit configured to determine a picture identification code of the second picture from the set of alternative digital codes.
According to a fifth aspect, there is provided a computer readable storage medium having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method of the first and second aspects.
According to a sixth aspect, there is provided a computing device comprising a memory and a processor, wherein the memory has stored therein executable code, and wherein the processor, when executing the executable code, implements the methods of the first and second aspects.
By the method and the device provided by the embodiment of the specification, the copyright information is written in the LSB of the picture pixel point in a blocking and annular writing mode. The copyright information written in the way can resist the influence of various image processing modes such as image matting, cutting, rotation and the like on the digital watermark, and the robustness and the safety of the spatial domain digital watermark are enhanced.
Detailed Description
The scheme provided by the specification is described below with reference to the accompanying drawings.
In order to protect the copyright of the picture, the picture is considered to be added with a watermark so as to prevent the picture from being stolen and used without authorization.
In one scheme, a conventional watermark is added to the picture. The principle of the scheme is to add a visible watermark, such as a graph Logo of a copyright side, to the picture. However, the conventional visual watermark has a very large visual impact on the picture, and may even block key parts of the picture. Moreover, the security of the watermark is not high, and a picture thief can remove the watermark by using a relevant tool, so that the security of the picture cannot be guaranteed. In addition, most of the visible watermarks are pictures determined in advance, and the copyright side cannot effectively manage the pictures in a thinning mode.
In another scheme, a digital watermark is added to the picture. The digital watermark is a technology which can secretly write information such as copyright and the like into the picture and has low influence on the visual effect of the picture, and is more suitable for copyright protection. Digital watermarking techniques can be divided into frequency domain algorithms and spatial domain algorithms.
The frequency domain algorithm is a method for writing digital copyright information into the frequency domain space of a picture. Specifically, the principle of this scheme is to transform a picture into the frequency domain space, for example, by DWT discrete wavelet transform, then superimpose the digital information onto the signals of the frequency domain space, and finally transform the signals of the frequency domain space back into the spatial domain, for example, using DWT inverse transform, to obtain an encryption map. The influence degree of the frequency domain algorithm on the picture vision is uncontrollable, the picture vision quality is difficult to guarantee, and most algorithms do not support blind extraction, namely, original image assistance is needed when digital information is extracted.
The space domain algorithm is a method for writing digital copyright information into a space domain of a picture. The spatial domain algorithm can control the visual influence on the picture and support blind reading, so that the method is more suitable for copyright protection scenes. Among the spatial algorithms, the most representative algorithm is the least Significant bit lsb (least Significant bit) algorithm.
As known to those skilled in the art, a picture is composed of pixels, each pixel typically having three channels of RGB, each channel recording pixel values of red (R), green (G), and blue (B) components of the pixel, respectively, each pixel value being recorded by a string of bits of a binary system. In a common picture recording method, the pixel value of each channel is between 0 and 255, and 8 bits (one byte) are used for recording.
In the bit group of the pixel point for recording the pixel value, the lowest bits are called the LSB bits. The change in the value of the LSB bits does not significantly change the visual appearance of the image. Therefore, digital information related to copyright can be written in LSB bits of picture pixels, which is the LSB algorithm. Generally, in the case of using an 8-bit group, the lowest 1 to 3 bits are taken as LSB bits.
Fig. 1 shows a schematic diagram of the LSB algorithm. More specifically, for the picture on the left side, it is assumed that pixel values of respective pixels are represented using bit groups of 8 bits. In the example of fig. 1, the least significant 1 bit of the bit group is taken as the LSB bit, and digital information (code 11001011 shown in bold) is written in the LSB bit of each pixel, so that copyright digital information is written in the picture in an invisible manner, forming a digital watermark.
However, the digital watermark added by the conventional LSB method is not robust enough. In the case of processing a picture, such as matting, cropping, rotating, blocking, or adding a visual watermark, these operations can easily destroy the digital watermark added by the conventional LSB algorithm.
Based on the observation, analysis and consideration, the inventor innovatively provides a new digital watermark reading and writing method, the scheme divides the picture into blocks on the basis of the LSB method, and digital information is circularly written in each block, so that the influence of processing operations such as cutting, matting, rotation and the like on the digital watermark is resisted.
Fig. 2 shows a flow chart of a method of writing a digital watermark according to an embodiment. The method can be executed by any device, equipment, platform, equipment cluster with computing and processing capability, for example, various servers related to picture storage and publishing. As shown in fig. 2, the method for writing a digital watermark in a picture at least includes the following steps.
First, in step 21, a picture to be written with a watermark is read. The process of reading the picture at least comprises the step of obtaining a bit group which corresponds to each pixel point in the picture and is used for recording the pixel value. For example, in the case of RGB three channels, the bit groups corresponding to the pixel points in each channel are read. As previously described, the pixel values and the bit numbers of the bit groups may be set differently depending on the contents of the picture itself, the picture storage format, and the like. In a common typical case, pixel values are recorded using 8-bit groups, i.e. one byte. Hereinafter, for convenience of description, the above-mentioned picture to be written with the watermark is referred to as a first picture.
Next, at step 22, a picture identification code generated for the first picture is acquired.
It is understood that the picture identification code is a string of binary codes for identifying the picture information.
In one example, the picture identification code is used to identify copyright information of the picture, such as a copyright owner, a copyright number, and the like.
In one example, the picture identification code is used to identify source information of the picture, such as operator information. For example, an operator ID that uploads the picture may be used as the picture identification code. Therefore, the source of the picture is tracked.
In one embodiment, the picture identification code is generated directly for the second picture as digital watermark information according to a predetermined rule.
In another embodiment, the picture identification code is used to identify copyright information. In such a case, a copyright number, e.g. denoted c, may first be generated for the first picture. The copyright number may be a combination of various characters such as numbers, letters, etc. for identifying copyright information of the first picture. Then, a preset encryption algorithm f is adopted to encrypt the copyright number c to obtain c, namely:
c*=f(c) (1)
and obtaining the copyright identification code based on the encryption result. The copyright identification code obtained in this way is an encrypted identification code, so that direct exposure of the copyright number is avoided, and the copyright management security and the confidentiality are improved.
In one embodiment, the picture identification code refers to copyright party information, so that a plurality of pictures owned by the same copyright party can share the same picture identification code. Thus, the generation of the picture identification code is simplified. In another embodiment, the above picture identification code is a unique identification code generated for each picture. Thus, each picture has its unique picture identification code. Thus, the pictures can be managed finely.
In one embodiment, a corresponding picture identification code is generated in advance for each picture (optionally, encrypted), and stored. When the digital watermark writing process is executed, the picture identification code which is generated and stored is directly read. In another embodiment, the picture identification code is generated for the picture to be written when the digital watermark writing process is performed.
The number of bits of the picture identification code can be set according to requirements, for example, the number of bits is set to 16-bit coding.
In addition, in step 23, the first picture is divided into a plurality of blocks with predetermined sizes. The size of the block can be preset as required, for example, preset as hbWidth wbIs rectangular. Then if the actual length and width of the first picture are h, respectivelyxAnd wxThen the first picture may be divided into N blocks, where:
where floor (x) denotes that x is rounded down.
In some cases, e.g. at hx/hbOr w orx/wbIn the case where an integer number is not available, there may be a small number of fragment portions in the edge region of the first picture that are insufficient to form one tile. In the following, only the complete block is processed.
Next, for each block, a circle of a predetermined radius is determined among the blocks, step 24. For convenience of description, the ring herein will be referred to as a first ring.
It is understood that the radius of the first circular ring is preset according to the size of the block in step 23. For example, in one embodiment, the first ring is set to be a maximum inscribed circle of the block of the predetermined size. For example, if the block is h in lengthbWidth wbThen the radius of the first circle is:
in another embodiment, the radius of the first ring may be set smaller than rθOther values of (a).
In one embodiment, the blocks of the predetermined size are square blocks, i.e. equal in length and width, assuming b. And, the radius of the first circular ring is set to b/2, i.e., the maximum inscribed circle of the square block. At this time, the position of the first ring in the block can be uniquely determined.
In other cases, the location of the first circle in the block is not unique. In such a case, step 23 may include first determining a reference position in the block, which may be a circle center position, a circle leftmost position, a circle rightmost position, a circle uppermost position, a circle lowermost position, and so on. Then, the position of the first circular ring is determined according to the reference position and the preset radius.
Fig. 3a and 3b show the first circle identified in the specific example. In the example of fig. 3a and 3b, the tiles each take the size of 20 (pixels) × 30 (pixels), with one pixel for each small grid in the figure. The radius of the first ring is set to the maximum inscribed circle radius, i.e., radius 10.
In the example shown in fig. 3a, assuming that the reference position is the leftmost position P of the circle and the reference position coordinates are (0,10), then based on the reference position coordinates and the preset radius 10, the first circle shown in the figure can be determined, which is tangent to both the top and bottom sides and the left side of the block.
In the example shown in fig. 3b, assuming that the reference position is a circle center position and the reference position coordinates are (15,10), then based on the reference position coordinates and the predetermined radius 10, a first circular ring as shown can be determined, which is located at the center of the block and tangent to the upper and lower edges of the block.
On the basis of determining the first ring, next, in step 25, the pixel point corresponding to the predetermined position on the first ring is determined as an initial pixel point, and from the initial pixel point, a predetermined flag code is written in the predetermined lowest bit LSB of the bit group corresponding to the first number of pixel points along the first ring. The process of writing the flag encoding is described below with reference to the schematic illustration of fig. 4, with the continuation of the example of fig. 3 b.
FIG. 4 shows a schematic diagram of write flag encoding in one embodiment. To write a mark code on the ring, the initial pixel to write is first determined. The starting pixel may be a pixel corresponding to a predetermined position of the ring, and the predetermined position may be predetermined, for example, in the example of fig. 4, the predetermined position is set as the uppermost position of the ring, so that the pixel a is determined as the starting pixel. Then, from the initial pixel point, writing a predetermined flag code in the LSB bit corresponding to a certain number of pixel points along the circular ring.
The mark code comprises a predetermined string of character codes for indicating the beginning of the digital watermark writing. The mark code is used as a mark of the beginning of the digital watermark and can provide an index for reading the subsequent digital watermark. To be useful as a marker, the marker code may be configured as a string of codes of particular significance that are easily identified, such as 11111111.
After the initial pixel point is determined, the flag code may be written in the LSB bits of the pixel point along the circular ring from the initial pixel point. The number of pixel points occupied by the flag coding is determined according to the number of bits of the LSB and the number of bits of the flag coding. For example, in one example, the flag is encoded as three bits, e.g., 111, and the LSB is also taken of the last 3 bits of the bit group of the pixel, then the LSB of the starting pixel can be used to write the flag code.
In the example of fig. 4, it is assumed that the flag code is 11111111 with 8 bits, and the LSB is the last 2 bits of the bit group of pixel points, then 4 pixel points are needed to write the flag code. At this time, the flag codes are sequentially written in the LSBs of the pixels covered by the circular ring from the initial pixel. In fig. 4, along the clockwise direction of the circular ring, the flag codes are written in the LSB bits of the initial pixel a and the subsequent pixels B, C, and D in sequence. Because the LSB of each pixel is the last 2 bits, 11 is written in the last two bits of the bit groups of a, B, C, and D, and thus, the LSB bits of 4 pixels constitute the flag code 11111111111.
It is to be understood that fig. 4 is merely an example. In fact, the position of the initial pixel point, the bit number and value of the mark code, and the bit number of the LSB bit can be set as required. Although the example of fig. 4 shows the writing in the clockwise direction of the circular ring, the writing in the counterclockwise direction may be performed in other examples.
After writing the mark codes, in step 26, the picture identification codes acquired in step 22 are sequentially written into the LSBs corresponding to the plurality of pixel points covered by the first ring along the first ring.
The following continues with the above example, and describes the writing process of the picture identification code in conjunction with the schematic diagram of fig. 5. In fig. 4, the flag code has been written in the pixel points a, B, C, D. And then, after the pixel points A, B, C and D, sequentially writing picture identification codes in the pixel point sequence covered by the first circular ring along the circular ring. The part of the pixels covered by the circle for writing the picture identification code is shown in fig. 5 by a gray grid. It will be appreciated that only the portion of the pixels covered by the circle after pixels a-D are shown in fig. 5, and that pixels covered by other portions of the circle may be similarly determined.
The pixel points covered by the circular ring can be determined in the following manner. It will be appreciated that the determination at step 24 is madeWhile the first ring is in use, the position of the circle center of the first ring is determined and marked as C (X)c,Yc). For any pixel point p (X) in the blockp,Yp) The distance D between the pixel point p and the center C of the circle can be calculated, and if the difference between the distance D and the radius r of the first ring is less than a predetermined threshold (the threshold can be set to a small value less than one pixel unit), the pixel point p is considered to be covered by the ring.
Therefore, along the first circular ring, the picture identification codes are sequentially written in the pixel point sequence covered by the circular ring. In one embodiment, after writing a complete string of picture id codes, the beginning pixel point of the circle is not yet returned, and the picture id codes can be written again along the first circle. In other words, the picture identification code may be written cyclically multiple times along the first circular ring. The number of times of writing depends on the number of digits of the picture identification code, the number of pixel points covered by one circle of the ring and the number of digits of the LSB. For example, if the number of bits of the picture id is 16 bits and the number of LSB bits is 2, then writing the picture id once requires using 8 consecutive pixels. If the number of the pixel points covered by the first ring is n, wherein the mark code occupies 4 pixel points, the number of the pixel points which can be used for writing the picture identification code is n-4, and the maximum writing frequency of the picture identification code is floor ((n-4)/8).
In one embodiment, the picture identification code may also be written in each pixel point covered by the first circular ring at predetermined intervals. The predetermined interval may be set as desired, for example, every other pixel, every 2 pixels, and so on.
Through the above mode, along first ring, the picture identification code is write in to the annular.
In one embodiment, in order to increase the writing amount of the picture identification code and further enhance the security, a second circular ring is further determined in the block, the second circular ring is a concentric circular ring of the first circular ring, and a second radius of the second circular ring is smaller than a predetermined radius of the first circular ring.
In one embodiment, the size of the second radius is also preset, and the position of the second ring can be determined directly according to the circle center position C of the first ring and the second radius.
In another embodiment, a ratio of the second radius to the radius of the first ring is preset, for example 50%. In such a case, the value of the second radius is determined according to the preset ratio, and then the position of the second ring is determined according to the position of the center of the circle and the value of the second radius.
And then, along the second ring, sequentially writing the picture identification codes into the LSBs of the pixel points covered by the second ring.
In one embodiment, similar to the first ring, a starting pixel point is first determined at a predetermined position of the second ring, and the picture identification codes are sequentially written in the sequence of pixel points covered by the second ring along the second ring from the starting pixel point.
In another implementation, the initial pixel point on the second ring is randomly selected, and then the picture id codes are sequentially written along the second ring.
In an alternative embodiment, in the second ring, starting from the starting pixel point, the flag code is written first, and then the picture identification code is written. Alternatively, in another embodiment, the logo encoding is not written any more, but only the picture identification code.
In one embodiment, the picture identification code is written in the pixel points covered by the second circular ring for multiple times in a circulating manner.
Continuing with the above example, the determination and writing of the second circle is described in conjunction with FIG. 6. FIG. 6 illustrates a schematic view of a second ring according to one embodiment. In the example of fig. 6, the second circular ring is set to have a radius of half that of the first circular ring. As previously mentioned, the radius of the first ring is 10, and the radius of the second ring is 5. After the position of the second ring is determined, the pixel points covered by the second ring can be determined, and the gray grid is used for showing partial pixel points covered by the second ring in the figure. In these pixel points, along the second ring (clockwise or counterclockwise), the picture identification codes are sequentially written in the LSB bits of the pixel points.
It is understood that if the writing amount of the picture identification code is further enhanced, more circles concentric with but smaller than the first circle, such as a third circle, a fourth circle, and so on, may also be determined in the block. The determination and writing manners of these rings are similar to those of the second ring, and are not described again.
The number of concentric rings required can be set as desired. In general, however, it is desirable that the total number of pixels covered by each ring for writing the logo code and/or the picture identification code is within a range, for example, preferably 20% to 40%, of the total number of pixels in the whole picture. Therefore, the writing amount of the picture identification code is ensured to be enough for reading and identifying, and the visual effect of the picture is not influenced as much as possible.
Through the above mode, the digital information is written in the LSB bit of the picture pixel point in a blocking and annular writing mode. The digital information written in the way can resist the influence of various picture processing modes such as matting, cutting, rotation and the like on the digital watermark. Such an advantage will be more apparent from the following description of the digital watermark reading process.
Fig. 7 shows a flow diagram of a method of reading a digital watermark, according to one embodiment. As shown, the method for reading the digital watermark at least comprises the following steps.
First, in step 71, a picture to be watermarked is read, hereinafter referred to as a second picture. And reading the second picture, namely obtaining a bit group which corresponds to each pixel point in the second picture and is used for recording the pixel value.
Next, at step 72, an alternative circle of predetermined radius r is determined in the second picture.
The predetermined radius r corresponds to the radius of the first circle in each block when the watermark is written, and is a value that has been determined when the watermark is written. However, since the second picture may have undergone some picture processing operations and thus no longer has a regular block arrangement when the watermark is written, it is difficult to locate the ring where the picture identification code may be written by block division. Thus, in different embodiments, circles of various predetermined radius sizes may be traversed in the second picture as alternative circles in a variety of ways. For example, 2r × 2r squares (i.e., the side length of the square is equal to the diameter of the circle) may be selected from the picture, and the circle inscribed in the square is determined to be the circle to be selected. The square is then moved in a manner to determine more alternative circles.
FIG. 8 illustrates a schematic diagram of determining an alternative circle according to one embodiment. In the example of fig. 8, starting from the upper left corner of the picture, an alternative circle 1 is identified in a 2r x 2r square. The square is then translated to the right, continuing to determine alternative circle 2 and alternative circle 3.
For each alternative circle, the following process steps are performed. That is, in step 73, each pixel point covered by the candidate ring is sequentially used as a candidate starting point, and from the candidate starting point, the predetermined lowest bit LSB of the bit group of the predetermined first number of pixel points is read along the candidate ring, so as to obtain the candidate mark code. It will be appreciated that the first number here corresponds to the number of pixels occupied by the mark encoding when the digital watermark is written, and is a value that has been determined when the digital watermark was written. Therefore, for a specific candidate ring, the LSB bits of the first number of pixels are read by taking each pixel point on the ring as a starting point, and the candidate flag code is obtained.
The resulting candidate logo code is then matched and compared with the predetermined logo code. In step 74, under the condition that the candidate mark code matches with the predetermined mark code, the current candidate ring is determined as the first ring, and the corresponding candidate starting point is determined as the starting pixel point.
The above process is described in conjunction with fig. 9. Fig. 9 shows that the candidate circle 3 in fig. 8 is taken as the current candidate circle, and the pixel points covered by the candidate circle are determined. Continuing with the example of fig. 4, assume that the predetermined flag is known to be coded as 11111111, and 4 pixels need to be occupied. Then, with any pixel point on the circle as a starting point, the LSB bits (e.g., the lowest 2 bits) of 4 pixels are read along the circle to obtain a string of candidate codes. Assuming that the LSBs of the 4 pixels abcd are read from the pixel a along the candidate circle to obtain the candidate code 00111111, which is different from the predetermined flag code, the next starting point is tried. Next, starting with the pixel b, along the candidate circle, the LSB of the 4 pixels bcde is read, and the candidate code 11111111 is obtained. Obviously, the candidate code is completely matched with the predetermined mark code, and thus it can be determined that the current candidate ring can be used as the first ring, and the current starting point b can be used as the starting pixel point.
It will be appreciated that if the relative position of the starting pixel point in the first circle is changed from the predetermined position at the time of writing, this means that the picture has undergone a rotation process. For example, in one example, as shown in fig. 4, in the digital watermark writing stage, the pixel at the uppermost position of the ring is selected as the starting pixel. During reading, as shown in fig. 9, the initial pixel point b deviates from the top of the ring. This means that the part of the picture containing the ring is rotated with respect to the original picture, for example by a certain angle to the right.
As above, the first ring and the starting pixel point on the first ring are determined. Next, in step 74, in the pixels covered by the first ring, after the first number of pixels from the initial pixel, the LSBs corresponding to the plurality of pixels are sequentially read along the first ring to obtain the digital code, which is used as the candidate digital code.
Still referring to fig. 9, after determining that the current candidate ring is the first ring and the pixel b is the starting pixel, the LSB bits are sequentially read from the pixel f (i.e., after 4 pixels from the starting pixel b) along the ring among the pixels covered by the ring, so as to obtain the digital code.
In one embodiment, in the digital watermark writing stage, the picture identification code is written once along the first ring after the writing flag is encoded. In such a case, correspondingly, in the reading phase, at step 74, LSB bits of a predetermined second number of pixel points are read, where the second number is the number of pixel points that need to be occupied by the picture identification code, and depends on the number of bits of the picture identification code and the number of LSB bits. For example, in the previous example, the picture id is a 16-bit code, and the LSB bit is 2 bits, so that the picture id needs to occupy 8 pixels, and the second number is 8. In such a case, the LSB bits of 8 pixels are read from the pixel point f to obtain a string of digital codes, which are used as candidate digital codes.
In one embodiment, in the digital watermark writing stage, the picture identification code is written at predetermined intervals. Accordingly, in the reading stage, reading is performed at the above-described predetermined intervals. The predetermined interval is set in advance, for example, every other pixel, every 2 pixels, and so on.
In another embodiment, in the digital watermark writing phase, the picture identification code is written along the first circular ring for multiple times in a circulating manner. In such a case, correspondingly, in the reading phase, at step 74, each time the LSB bits of a predetermined second number of pixel points are read, a set of digital codes is obtained, where the second number is the number of pixel points that the picture identification code needs to occupy. Thus, multiple sets of digital codes can be obtained by traversing the entire circumference. Or, a long string of digital codes is obtained by traversing the whole circumference, and then the long string of digital codes is divided into a plurality of groups of digital codes according to the preset digit number (namely, the digit number of the picture identification code).
For example, in one example, assume that the first ring covers 40 pixel points with 2 LSB bits. The mark code is 8 bits, occupies 4 pixel points, the picture identification code is 16 bits, and occupies 8 pixel points. Assuming that the initial pixel point is numbered as 1 in the pixel point sequence covered by the first circular ring, the flag code can be read from the LSB of the pixel points 1 to 4, and then the picture identification code is read from the pixel point 5. In the process of reading the picture identification code, LSB bits of each 8 pixel points form a group of 16-bit digital codes, and 4 groups of 16-bit digital codes can be obtained by traversing the whole circumference.
It is understood that according to the above steps, a plurality of first circles may be determined in the second picture. For each first ring, at least one set of numerical codes is determined, via step 74.
Then, in step 75, a set of candidate digital codes is formed at least according to the at least one group of digital codes; then, at step 76, a picture identification code for the second picture is determined from the set of alternate digital codes.
In one embodiment, for each first ring, the digital code with the highest repetition degree in the determined at least one group of digital codes is added as a candidate digital code to the candidate digital code set to form the candidate digital code set in step 75. Thus, the candidate number encoding set for the N first rings includes N candidate number encodings.
In another embodiment, for each first ring, the determined at least one set of digital codes is added directly to the set of candidate digital codes, thereby forming the set of candidate digital codes, step 75. For example, if each first torus can read k sets of digital codes, the set of candidate digital codes for N first tori contains N × k sets of candidate digital codes.
Then, at step 76, a picture identification code for the second picture is determined from the set of alternate digital codes. In one embodiment, the digital code with the highest repetition degree in the multiple groups of candidate digital codes contained in the candidate digital code set is used as the picture identification code. In another embodiment, the highest repetition degree is further determined. Under the condition that the highest repetition degree is greater than a preset threshold value, taking the corresponding digital code as a picture identification code; under the condition that the highest repetition degree does not reach the preset threshold value, the difference of the read digital codes is large, and the picture identification code cannot be accurately extracted.
In one embodiment, the picture identification code directly corresponds to the copyright number. In another embodiment, the picture identification code is obtained by encrypting the copyright number by adopting the encryption method of the formula (1). In such a case, after determining the picture identification code, the reading process further comprises using a decryption function f corresponding to the encryption function f in equation (1)-1And decrypting the picture identification code to obtain the original copyright number.
In one embodiment, during the digital watermark writing process, a second circular ring is also formed in the first circular ring, and the picture identification code is written in the second circular ring. Accordingly, during reading, after reading the digital code written in the first ring, reading can also be performed for the second ring.
Specifically, in one embodiment, a second circle is defined within the first circle at a predetermined second radius. The second ring is a concentric ring of the first ring and has a smaller radius than the first ring according to rules at the time of writing. Therefore, after the position of the first ring is determined, the second ring may be determined based on the center position of the first ring and the predetermined second radius.
On the basis of determining the second ring, the pixel points covered by the second ring can be determined. In one embodiment, the second ring is also written with the flag code, and at this time, similar to the reading manner of the first ring, the pixels written with the flag code are first retrieved in the second ring, and then after these pixels, the LSB bits of the pixels are extracted along the second ring, so as to obtain at least one group of digital codes. In another embodiment, the second ring is used only for writing of picture identification codes. At this time, the LSB bits of the pixels around the ring are read along the ring from any pixel of the second ring, and the digital information is extracted. In one embodiment, at least one set of digital codes of a predetermined length (the number of picture identification code bits) may be extracted from the digital information read from the second ring, which may be referred to as a second digital code, with reference to the starting code of the digital code read in the first ring.
In one embodiment, a plurality of second rings may be identified corresponding to the first rings. In one embodiment, the second digital codes read based on the respective second circular rings are added to the aforementioned set of alternative digital codes for determination of the picture identification code. In another embodiment, in the case where a plurality of sets of second digital codes are read on a per second circular ring basis, the digital code in which the degree of repetition is the highest may also be added to the aforementioned set of alternative digital codes.
In one embodiment, according to the rule of the digital watermark writing, a third ring, a fourth ring, and so on may be determined in the first ring. In one embodiment, the digital codes read based on the respective rings are added to the set of alternative digital codes, such that the alternative digital codes include multiple sets of digital codes read based on multiple rings of different sizes, different locations. Finally, a picture identification code is determined based on the entire set of alternate digital codes.
Fig. 10 shows a schematic diagram of the effect of the annular reading mode. In fig. 10, the left picture is the first picture, in which the picture identification code is written by the method shown in fig. 2. Assuming that someone has processed the first picture, a part of the picture content is cut out in a "scratch" manner, and the part of the picture is also rotated, thereby forming a second picture. It can be seen that, because the way of writing in blocks is adopted when the watermark is written in the first picture, some blocks are inevitably included in the cut picture part, and carry the digital information written in advance. In addition, since the digital information is written in the block in a ring-shaped manner, the written digital code can be read even if the picture portion is rotated.
Therefore, the digital watermark writing mode shown in fig. 2 and the reading mode shown in fig. 7 can resist the damage influence of various picture operations on the spatial domain digital watermark, and obviously enhance the robustness and the security of the spatial domain digital watermark.
According to an embodiment of another aspect, a device for writing a digital watermark is also provided. Fig. 11 shows a schematic block diagram of a digital watermark writing apparatus according to an embodiment. As shown in fig. 11, the writing apparatus 11 includes:
the image reading unit 111 is configured to read the first image to obtain a bit group corresponding to each pixel point in the first image, where the bit group is used to record a pixel value of a corresponding pixel point;
a picture code acquiring unit 112 configured to acquire a picture identification code generated for the first picture;
a block dividing unit 113 configured to divide the first picture into a plurality of blocks of a predetermined size;
a first ring determining unit 114 configured to determine, for each block, a first ring of a predetermined radius among the blocks;
a flag code writing unit 115 configured to determine a pixel point corresponding to a predetermined position on the first ring as an initial pixel point, and write a predetermined flag code in a predetermined lowest bit LSB of a bit group corresponding to a first number of pixel points along the first ring from the initial pixel point;
and the picture code writing unit 116 is configured to continue to write the picture identification codes in the LSBs corresponding to the pixel points covered by the first ring in sequence along the first ring after the first number of pixel points.
In one embodiment, the picture code acquiring unit 112 is configured to:
generating a copyright number for the first picture;
and encrypting the copyright number to obtain the picture identification code.
According to a possible design, the first circle of the predetermined radius is set to be the largest inscribed circle of the block of the predetermined size.
In one embodiment, the first ring determining unit 114 is configured to determine a reference position in the block, and determine a position of the first ring according to the reference position and the predetermined radius, wherein the reference position includes one of: the circle center position, the leftmost position of the ring, the rightmost position of the ring, the uppermost position of the ring and the lowermost position of the ring.
In one embodiment, the first number is determined according to the number of bits of the predetermined lowest bit LSB and the number of bits of the predetermined flag code.
According to a possible embodiment, the picture code writing unit 116 is configured to write the picture identification code multiple times in a loop.
According to one possible design, the device 11 further comprises:
a second ring determining unit 117 configured to determine a second ring in the block, wherein the second ring is a concentric ring of the first ring, and a second radius of the second ring is smaller than the predetermined radius of the first ring;
the second writing unit 118 is configured to sequentially write the picture identification codes into the LSBs of the pixels covered by the second ring along the second ring.
Further, in an embodiment, the second circle determining unit 117 is configured to: first determining the second radius; and then determining the position of the second circular ring according to the circle center position of the first circular ring and the second radius.
According to an embodiment of a further aspect, a reading device of the digital watermark is also provided. Fig. 12 shows a schematic block diagram of a digital watermark reading apparatus according to an embodiment. As shown in fig. 12, the reading device 12 includes:
the picture reading unit 121 is configured to read the second picture to obtain bit groups corresponding to each pixel point in the second picture, where the bit groups are used to record pixel values of corresponding pixel points;
an alternative circle determining unit 122 configured to determine an alternative circle with a predetermined radius in the second picture;
the alternative reading unit 123 is configured to sequentially take each pixel point covered by the alternative ring as an alternative starting point, and read, from the alternative starting point along the alternative ring, a predetermined lowest bit LSB of a bit group of a predetermined first number of pixel points to obtain an alternative flag code;
a first ring determining unit 124, configured to determine the candidate ring as a first ring and determine a corresponding candidate starting point as a starting pixel point when the candidate mark code matches with a predetermined mark code;
a first code reading unit 125, configured to, among the pixels covered by the first ring, continue to read LSB bits corresponding to the pixels in sequence along the first ring after the first number of pixels from the initial pixel, so as to obtain at least one group of digital codes;
an encoding set forming unit 126 configured to form an alternative digital encoding set at least according to the at least one group of digital encoding;
a picture code determination unit 127 configured to determine a picture identification code of the second picture from the set of alternative digital codes.
According to an embodiment, the alternative torus determining unit 122 is configured to:
forming a square with the side length 2 times of the preset radius in the second picture, and determining that an inscribed circle of the square is a first alternative circular ring;
the square is moved to determine a second alternative ring.
In one embodiment, the encoding set forming unit 126 is configured to: adding the at least one set of digital codes to the set of candidate digital codes.
In another embodiment, the encoding set forming unit 126 is configured to: and determining the digital code with the highest repetition degree in the at least one group of digital codes, and adding the digital code with the highest repetition degree into the alternative digital code set.
According to one possible design, the picture code determination unit 127 is configured to:
and in the multiple groups of digital codes included in the alternative digital code set, using the digital code with the highest repetition degree as the picture identification code.
According to one possible design, the apparatus 12 further comprises (not shown) a decryption unit configured to decrypt the picture identification code, thereby obtaining the original copyright number.
In a possible embodiment, the device 12 further comprises (not shown):
a second ring determining unit configured to determine a second ring according to a predetermined second radius in the first ring, wherein the second ring is a concentric ring of the first ring, and the second radius is smaller than the predetermined radius of the first ring;
and the second code reading unit is configured to sequentially read the LSB bits of the pixel points covered by the second ring along the second ring to obtain at least one group of second digital codes.
Further, according to an embodiment, the encoding set forming unit 126 is configured to: adding at least one second digital code read based on the second ring to the set of candidate numbers.
The above devices 11 and 12 can write and read spatial domain digital watermarks, respectively. The digital watermark obtained by the method can resist the damage of common picture operation to the watermark, and the robustness and the safety of the spatial domain digital watermark are improved.
According to an embodiment of another aspect, there is also provided a computer-readable storage medium having stored thereon a computer program which, when executed in a computer, causes the computer to perform the method described in connection with fig. 2 and 7.
According to an embodiment of yet another aspect, there is also provided a computing device comprising a memory and a processor, the memory having stored therein executable code, the processor, when executing the executable code, implementing the method described in connection with fig. 2 and 7.
Those skilled in the art will recognize that, in one or more of the examples described above, the functions described in this invention may be implemented in hardware, software, firmware, or any combination thereof. When implemented in software, the functions may be stored on or transmitted over as one or more instructions or code on a computer-readable medium.
The above-mentioned embodiments, objects, technical solutions and advantages of the present invention are further described in detail, it should be understood that the above-mentioned embodiments are only exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made on the basis of the technical solutions of the present invention should be included in the scope of the present invention.