1 Introduction

The security systems could be described in two types, the first one is ‘cryptography’ that consist of text encryption, image encryption [11, 13, 17, 24, 28, 29], and etc. The second one is ‘information hiding’, which consists of ‘Steganography’ and ‘Watermarking’. The watermarking’s purpose is authentication of digital content and recovering the original content in tempered regions by the help of embedding additional information in the host image. In order to achieve this goal, we produce an information array for each block of image and embed it in the host image. Two basic steps in watermarking are, dividing an image to the same size blocks and producing an information array for each block by processing these blocks. Some previous methods using Compression Code (CC), i.e. the quantized DCT coefficients [7, 10], VQ indexing [26], and average intensity [15, 20, 21, 26, 27]. In these methods, the number of bits, which are produced is fixed for all blocks. If we use a fixed size for all blocks we would face a problem, which may constraints result, because the provided information is over fit for the smooth block and inadequate for rough blocks. We are facing two challenges in the watermarking algorithms, the large information array length that increases the watermark payload and the insufficient data makes problem in recovery phase and decrease the image quality. To overcome these problems some schemes have been proposed. For instance, in [20, 21], the authors proposed a multi-level encoding for various types of blocks with variable of information array (CC). However, in these methods, the capacity of watermark embedding that is fixed, lead to the size fixation of CC for different images. “Qin et al.” [22], proposed a novel reversible data hiding in the index tables of vector quantization compressed image based on index mapping mechanism. VQ indices with zero occurrence besides high occurrence indices are used to make a mapping list. These schemes still lead to overmuch or inadequate information array length for the smooth or the rough image blocks. In 2014, “Chen et al.”. [8] proposed a method for digital image watermarking with flexible watermark payload. They used a chaotic pseudorandom number generator for encrypting the watermarked data and block mapping. They used a metric for defining block types that classified into smooth and rough. Their metric is dysfunctional, because it wrongly recognized some smooth blocks as rough. This shortcoming results consumption of bandwidth in improper way, because they send 12 bits instead of 6 bits for smooth blocks. Other disadvantages of this method, for recovering a tampered block, they employed an average mapping block in the valid case, otherwise average of 8 neighbor blocks are utilized for replacing the whole pixels in tampered block. This method for recovery may have a convincing results, but it could be better by using features of valid neighbor block pixels for determining each pixel in this tampered block. In 2015, “Liao and Shu” [16], proposed a novel method for reversible data hiding in encrypted image based on absolute mean difference of multiple neighboring pixels. They suggest a new metric to calculate complexity of image blocks that leads to high data embedding ratio. “Chen et al.” [6], proposed color image analysis based on Quaternion-Type-Moments. Indeed, a novel QTMs and QTM invariants (QTMIs) are suggested which had better performance in several application frameworks such as: color image reconstruction, face recognition, and etc. In this paper, we proposed a fragile digital image watermarking method by using chaotic map, which has a better definition for classification of smooth and rough blocks and better quality in self-recovery phase. The original image is divided into equal 2 × 2 sub-blocks, and then we categorize the blocks into rough or smooth blocks. After that, based on the block’s type, we create information array with size of 6 for smooth or 12 for rough blocks. In order to enhance security, we use a chaotic map for block mapping and after encrypting the watermarked data with a secret key, we embed the data in position, which defined by block mapping procedure. Moreover, we suggest a novel strategy for self-recovery of each pixel in tampered block based on position of tampered blocks in image and features of valid neighbor block pixels. Experimental results proved that our scheme is secure and has a good quality in self-recovery phase.

The paper structure is as follows: in section 2, the proposed method is described. Then we provided experimental results in section 3 and in section 4, we come into the conclusion.

2 The proposed method

The proposed method consists of 4 phases (block encoding, watermark embedding, watermark extraction and verification and image recovery), which separately define in following sections. The overall views of each phase in proposed scheme are shown in Figs. 1, 2, 3, and 4, respectively.

Fig. 1
figure 1

The overview of block encoding process

Fig. 2
figure 2

The overview of watermark embedding process

Fig. 3
figure 3

The overview of watermark extraction and verification process

Fig. 4
figure 4

The overview of image recovery process

2.1 Block encoding

In this phase, first we divide the original Image test (I), into N, non-overlap sub-blocks I 1 I N with size of 2 × 2 then, for each sub-block I i , we extract five most significant bits of each pixel to form a matrix A i . The information array contains of 5-bits average, 1-bit block type and 6-bits that are added when the block is rough. With these 6 bits we can determine exact position of maximum pixel and the positions of pixel(s) that are less than average. This information is very vital in self-recovery phase of tampered region. The information array corresponding to block I i denoted by (α I). The overview of information array block is shown in Fig. 5. The detail steps of block encoding are as follows:

  1. Step 1:

    Average-code: For each 2 × 2 blocks, let A i = \( \left(\begin{array}{cc}\hfill {a}_{i1}\hfill & \hfill {a}_{i2}\hfill \\ {}\hfill {a}_{i3}\hfill & \hfill {a}_{i4}\hfill \end{array}\right), \) is an average matrix corresponding to sub-block I i that has integer entries between (0, 31), where a ik (k = 1, 2, 3, 4) is five most significant bits of corresponding pixels in sub-block I i .

Fig. 5
figure 5

Information Array (α I)

The average value of the block is: \( Av{g}_i = floor\ \left(\frac{1}{4}\ {\displaystyle {\sum}_{j=1}^4}{a}_{ij}\right) \) Where floor, rounds each argument to the nearest integer less than or equal to that argument, and the average belong to [0, 31] interval. We define an array that called high frequency array (H) as follows:

$$ H = \left(\begin{array}{cc}\hfill {a}_{i1}-Av{g}_i\hfill & \hfill {a}_{i2}-Av{g}_i\hfill \\ {}\hfill {a}_{i3}-Av{g}_i\hfill & \hfill {a}_{i4}-Av{g}_i\hfill \end{array}\right) $$

The aforementioned array can contain one, two, or three negative element(s), which their average use in definition of parameter S that will discuss in following.

  1. Step 2:

    Block-type: We use the Eq. (1), as stated bellow, in order to classify the block as smooth or rough.

$$ Block\ typ{e}_i= Ma{x}_i-\left(Av{g}_i+\left|su{m}_{H_i}\right|\right) $$
(1)

Where Max i and \( su{m}_{H_i} \) demonstrate the maximum element of matrix A i and the sum of elements of H i , which are negative, respectively. If the above equation result become negative, the block is rough, otherwise the block is smooth. This new metric provides a strong tool for better quality in self-recovery phase and efficient use of bandwidth. Table 1, shows the typical expression for certain 2 × 2 blocks. The average intensity and CC are also shown. As it is obvious base on Table 1 (the highlighted row), the proposed metric in [8] is inefficient due to the fact its distinguishes an smooth block as rough block, which lead to send 12 bits instead of 6 bits and further bandwidth consumption.

Table 1 Blocks with the three LSB removed and their CC
  1. Step 3:

    We fulfill positions of 7–12 in information array, if only the block is rough. These bits are filled based on Tables 2 and 3 and the rule described in Eq. 2.

    Table 2 Fulfill of positions 7 ~ 9
    Table 3 Fulfill of positions 10 ~ 12
$$ S=\left\{{}_{1\kern24em otherwise}^{0\kern1em if\kern0.5em 2 MSBs\kern0.5em Max\kern0.5em pixel="11"\kern0.5em and\kern0.5em 2 Msbs\kern0.5em of\kern0.5em average\kern0.5em of\kern0.5em negative\kern0.5em elements\kern0.5em in\kern0.5em H\kern0.5em array="00"}\right. $$
(2)

For example, status 3 in Table 1 demonstrate that maximum element placed in second position in A i array (a i2 ). The 2MSBs of maximum pixel and 2MSBs of average of negative element(s) in H array equals to “11”, “00”, respectively. For this condition, S is selected as zero, which mean that there exist a big difference between maximum pixel and other pixel(s) that have negative value(s) in H array. Indeed, such condition will occur in edge of the image.

By excluding the position of maximum element of matrix A i , three positions remain that denoted by numbers 1, 2, and 3 in above table relative to maximum. For example, status 4 in above table means that position of negative elements relative to maximum are first and second place. The tampered region in edges could be recovered with better quality in our scheme based on better definition of information array in our scheme.

Indeed, by applying above procedure, corresponding to each block I i (1 ≤ i ≤ N), the information array α I with length six or twelve is built. Here, the aforementioned array called as watermarked data.

2.2 Key agreement

In order to enhance safety of the proposed scheme, the watermarked data (α i i = 1, 2…, N) encrypted with a key that agreed between users. Indeed, a key agreement between users is an essential step in the proposed scheme. Users (i.e. user A and B, who are participating in watermarking process), apply an efficient and secure key agreement protocol by using their private key besides the partner public key. In this field, too many articles exist such as [14, 14, 18].

2.3 Watermark embedding

Assume that user A wants to embed watermark data (α i i = 1, 2…, N), into image (I) and send it to user B. First, he/she build key agreed (K), then use it for encryption of watermarked data based on the following equation:

$$ \overset{\sim }{\alpha_i}={\alpha}_i\oplus K,\kern0.5em i = 1,\ 2\dots,\ N $$
(3)

Then, we use a two dimensional chaotic map, to determine exact position (X(i), Y(i)) that encrypted information array \( \overset{\sim }{\alpha_i} \) will be embedded to it. The mathematical formula of this map is as below:

$$ \left\{\begin{array}{c}\hfill {X}_i= mod\left(1-2\left({Y}_{i-1}^2\right)\times {10}^5,1\right)\kern4.75em \hfill \\ {}\hfill {Y}_i= mod\Big( cos\left(6\times arccos\left({X}_{i-1}\right)\times {10}^5,1\right)\hfill \end{array}\right. $$
(4)

where mod is modulo operation that finds the reminder of one number by another. In order to determine initial value \( \left(\begin{array}{c}\hfill {X}_0\hfill \\ {}\hfill {Y}_0\hfill \end{array}\right) \), by using agreed key K, a number between zero and one will be generated, assume this number as X 0 (for this purpose, based on domain value of K, simple mathematical operator can be used). Then, obtain Y 0 by using below formula:

$$ {Y}_0= mod\Big( \cos \left(6\times \arccos \left({X}_0\right)\times {10}^5,1\right) $$

We iterate Eq. (4) for N times, where N demonstrates the number of sub-blocks in the image and sequence \( \left(\begin{array}{c}\hfill {X}_i\hfill \\ {}\hfill {Y}_i\hfill \end{array}\right) \), 1 ≤ i ≤ N will be produced. Then, two sequence X i and Y i , 1 ≤ i ≤ N will be extracted. After that sort function used to arrange X i and Y i elements as an index of row and column that the information array of ith block is embedded in it, respectively. Next, the watermarked data is embedded into three least significant bits of each pixel in the mapping block. Note that, if the length of the information array is equal to 6, we use three LSB’s of two pixels and otherwise we use three LSB’s of four pixels.

2.4 Watermark extraction and verification

Watermark extraction is the reverse procedure of watermark embedding process. The receiver with the help of chaotic map (Eq. 4) and appropriate initial values can define exact position of blocks that watermarked data embedding is in it. The notation e im , demonstrates the extracted watermarked data of the ith block, with size m. The same procedure in section 2.1 is done for received image and builds the watermarked data (information array) based on received image. Note that all of the watermarked data, which extracted from the received images, may not be valid. Indeed, invalid watermarked data situations consist of modified pixels and pixels, which mapping blocks (that consist of their corresponding information) changed after transmission process. Hence, it cannot be used as appreciate tool for checking consistency of blocks. To get rid of this problem a match mark is defined (D = {d i | i = 1, 2, …, N}). For each block, d i determined by comparing extracted watermark and the watermark which produced by the method in section 2.1.

$$ {d}_i = \left\{\begin{array}{c}\hfill 0\kern3.75em if\ {e}_{jm}={w}_{im}\ \forall m\le\ {\vartheta}_i\hfill \\ {}\hfill 1\kern8.75em otherwise\kern0.5em \hfill \end{array}\right. $$
(5)

where ϑ i is the length of information array of the ith block and j, is the index of mapping block corresponding to the ith block. We use the following equation (Eq. 6) to better represent the location of tempering regions. If t i  = 1, the corresponding block is invalid, otherwise is valid.

$$ {t}_i^0 = \left\{\begin{array}{c}\hfill 1\kern2.75em if\ \left({d}_i=1\kern0.5em ,\ {\Gamma}_i^D\ge\ {\Gamma}_j^D\ \right)\kern3em \hfill \\ {}\hfill 0\kern3em otherwise\hfill \end{array}\right. $$
(6)

Where j, is the index of mapping block corresponding to the ith block, the notations Γ D i and Γ D j denote the number of valid blocks that are adjacent to ith and jth blocks in D respectively. The temper detection mark (TDM), T = {t i | i = 1, 2,…, N} is,

$$ {t}_i = \left\{\begin{array}{c}\hfill 0\kern3.25em if\ {t}_i^0=1\ and\ {\Gamma}_i^{t_0}\le 2\hfill \\ {}\hfill 1\kern2.75em if\ {t}_i^0=0\ and\ {\Gamma}_i^{t_0}\ \ge 5\hfill \\ {}\hfill {t}_i^0\kern7.25em otherwise\kern0.75em \hfill \end{array}\right. $$
(7)

where \( {\Gamma}_i^{t_0} \), denotes the number of valid blocks adjacent to ith block in the initial TDM t0. After temper detection, all blocks mark as valid or invalid. In the following, we discuss image recovery procedure.

2.5 Image recovery

In this section, our efficient method for restoration of tampered image introduced. The proposed method contains two main stages. First, the recovery procedure of blocks with valid mapping blocks is done, which helps to have a better recovery of tampered blocks with invalid mapping blocks. Second, for the block recovery, which have invalid mapping blocks, the information of adjacent pixels are used (Fig. 6). The detailed procedure of image recovery is as follows:

In the first stage of image recovery, our goal is restoration of tampered locations, which their mapping blocks are valid. After localization of these regions, following steps will be done.

  1. Step 1:

    Based on the 6th element of extracted information array from corresponding mapping block, the tampered block can be marked as smooth or rough.

  2. Step 2:

    If the block is smooth, five most significant bits (MSBs) of the extracted information array used to obtain the average of tampered block. Because, the value range of images is between 0 and 256, we fulfill positions 6 to 8 with zero to meet this requirement.

  3. Step 3:

    The whole pixels value in the tampered blocks will be replaced by the average obtained in previous step.

  4. Step 4:

    If the block is rough, besides extraction of five MSBs, the remaining bits (7–12) will be used. The extracted bits from positions 7–9 are used to determine maximum pixel value position and value of parameter S, which shown the distance between maximum pixel value and average of pixel(s) with negative value(s) of H.

  5. Step 5:

    The bits at positions 10–12 are used to specify position(s) of pixel(s) with negative value(s) of H relative to maximum pixel value position. The position(s) could be determined with decoding the bits stored in these positions (see Fig. 7 and Table 3).

Fig. 6
figure 6

Position(s) of negative element(s) relative to maximum

Remark: One of the innovations in this article is the use of special image block features in definition of information array. The information about position of maximum pixel value, the distance between maximum pixel value and average of pixel(s) with negative value(s) of H besides the exact position(s) of aforementioned pixel(s) relative to maximum pixel value position are stored in information array. Then, this information embeds in the mapping positions of the corresponding block. The advantage of storing this information is that we can achieve good image recovery with help of these features, because instead of replacing all pixel values in the block with average value, we put nearest possible value based on the aforementioned feature’s state.

  1. Step 6:

    Based on the bit values in position 7–12, we can obtain S, maximum position, and position(s) of pixel(s) with negative amount of H. If the value of S equal to zero, the maximum value and pixel(s) with negative value(s) of H will be replaced by the modified average as follows, otherwise the pixel values in the tempered block will be replaced by the extracted average that expanded to 8 bits by adding zero to the bit positions 6–8. The two most significant bit of average will be replaced by “11” for maximum value pixel and “00” for pixel(s) with negative value(s) of H, respectively. Similar to procedure done in step 2, bit positions 6–8 are fulfilled with zero. The remaining pixel(s) in the block will be replaced by the extracted average from information array that its 6–8 bit positions filled with zero.

After completing over mentioned steps, the first round of recovery phase will be completed, and in the second round we deal with the conditions that the mapping block of specific block is not valid. In this case we use pixels of valid blocks that are adjacent to the tempered blocks (Fig. 6).

Fig. 7
figure 7

Conditions of block recovery. a for blocks that placed in a corner, the average of five adjacent pixels are used, b for blocks placed in first or last row, the average of four adjacent pixels (2 east, 2 west) are used, c for blocks in first or last column, the average of four pixels (2 south 2 north) are calculated, d: for inner blocks, the average of all twelve adjacent pixels are measured

  1. Step 7:

    Based on positions of tampered blocks, the number of adjacent pixel will be changed as shown in Fig. 6. After specifying the number of adjacent pixels, validation of their corresponding blocks will be checked to specify the target pixels set.

  2. Step 8:

    We use result of previous step to determine which pixels participate in calculating the average and the calculated value replaced by previous amount of pixels. Finally, the reconstructed image can be obtained with acceptable quality (Table 6).

3 Experimental results

In order to prove the effectiveness of proposed method, some experiments and comparisons are done with latest researches in [8, 12, 27]. The proposed method is checked by two standard image formats BMP and Tiff. Although, the experimental results are based on Tiff format. Several measurements such as, code-length (bpp: bit per pixel) and code-quality [29] (PSNR between recovered image and original one) are used to prove coding efficiency. Moreover, similar metrics [30] (PSNR between watermarked image and original one) and watermark payload (bpp), are applied to show invisibility property of watermarked image. After that, in section 3.2, some visual results are presented, which refer to temper detection and recovery performance. Then, for proving efficiency of proposed scheme, the chi-square test is used. Finally, the quality of index is calculated to prove the similarity between reconstructed image and original one.

3.1 Code efficiency and invisibility

As mentioned before, we do this test to prove invisibility and efficiency of proposed method. We use bit per pixel (bpp) and PSNR in order to prove over mentioned goals. As described in section 2, there is relation between code-length and image type, the smoother the image get, the smaller value shown by code-length. By defining accurate metric for distinguishing rough and smooth blocks, the watermark payload of our scheme becomes minimum. This fact is shown in Table 4 and implies optimal bandwidth consumption. Although, applying different code-length proposed in [8, 15], but incorrect distinguishing of smooth blocks as rough blocks that is result of inefficient metrics, causes much bandwidth consumption (Table 1). Our code quality is almost the best alongside others latest proposed schemes. Indeed, we portioned image into 2 × 2 blocks, which increases precision of temper detection and leads to better recovery of tempered image. The results of invisibility test with comparison of experimental results provided in Table 5. Furthermore, Comparison of image recovery phase between proposed and Chen et al. method provided in Table 6.

Table 4 Comparison of coding efficiency for different images
Table 5 Performance comparison of invisibility for different images
Table 6 Comparison of image recovery phase between proposed and Chen et al. method

3.2 Tamper detection and recovery

In order to show the robustness of tamper detection and recover quality of proposed scheme, we use Lena, Barbara, Baboon with size of 512 × 512 for this test. The watermarked Lena, Barbara and Baboon generated by the proposed scheme are shown in Fig. 8(a)–(c). Three tampered images shown in Fig. 8(d)–(f). As the results in Fig. 9 demonstrate, our proposed scheme has a good performance in tamper localization and recovery.

Fig. 8
figure 8

Watermarked and tempered images. a Watermarked Lena, b Watermarked Barbara, c Watermarked Baboon, d Tempered Lena, e Tempered Barbara, f Tempered Baboon

Fig. 9
figure 9

Tampered detection and recovery images. a Tampered Lena, b Tampered Barbara, c Tampered Baboon, d Recovered Lena, e Recovered Barbara, f Recovered Baboon

In Fig. 9, we have provided the tampered localization and image reconstruction results. As it’s clear in this picture, the proposed scheme has a convincing result. Finally, In Fig. 10 we provide a comparison between our proposed method and some recent schemes.

Fig. 10
figure 10

Comparison of proposed method with schemes in [8, 12, 27]. (a ~ d): Lena original image, Lena tampered image, Lena tamper detection, Lena recovery image. (e ~ h): Lena original image, Lena tampered image, Lena tamper detection based [8], Lena recovery image based [8]. (i ~ l): Lena original image, Lena tampered image, Lena tamper detection based [27], Lena recovery image based [27]. (m ~ p): Lena original image, Lena tampered image, Lena tamper detection based [12], Lena recovery image based [12]

3.3 Chi-square test

In the proposed method, we use LSBs of each block (6 ~ 12 bits) to embed watermark data array, therefore, the LSB plan of image would be changed after embedding process. Chi-square test, [19] as a statistical analysis, helps us to understand whether a difference between expected signal and observed signal exist or not. The result of this test is shown in Fig. 11. If the red line come close to 1, it means that, there is a data, which is embedded in host image, in contrast, if it’s close to zero, it means existence of hidden secret data in the host image can’t observe [9].

Fig. 11
figure 11

Chi-square test a original Lena image, b Watermarked Lena image

3.4 Quality index

In order to measure, quality of recovered watermark image, we use quality index [19] that is calculated based on below formula:

$$ Q = \frac{4{\sigma}_{HT}\ H\hbox{'}T\hbox{'}}{\left({\sigma}_H^2 + {\sigma}_T^2\right)\ \left[H{\hbox{'}}^2 + T{\hbox{'}}^2\right]} $$
(8)

Where,

$$ {H}^{\prime } = \frac{1}{N}{\displaystyle \sum_{i=1}^N}{H}_i,\ {T}^{\prime } = \frac{1}{N}{\displaystyle \sum_{i=1}^N}{T}_i $$
(9)
$$ {\sigma}_H^2 = \frac{1}{N-1}{\displaystyle {\sum}_{i=1}^N}{\left({H}_i-H\hbox{'}\right)}^2 $$
(10)
$$ {\upsigma}_{\mathrm{T}}^2=\frac{1}{\mathrm{N}-1}{\displaystyle {\sum}_{\mathrm{i}=1}^{\mathrm{N}}{\left({\mathrm{T}}_{\mathrm{i}}-\mathrm{T}\prime \right)}^2} $$
(11)

In the above equation, n is the number of pixels in the image, H is the host image and T is the recovered watermark image. The value of Q is between 1 and −1. If the calculated value be −1, it means that, the host image and the recovered watermark image are not similar, but if it equals to 1, it means that two images are identical. The calculated values of this metric are shown in Table 7.

Table 7 Quality of index results for standard images

4 Conclusion

We have presented a novel fragile watermarking scheme based on chaotic maps that generates the embedded data with as few bits as possible while maintains the standards of good watermarking scheme such as accurate localization of tampered regions, satisfying recovery quality (both of them shown in Fig. 9), and optimal watermark payload (Table 1). The host image is portioned into sub-blocks with fix size of 2 × 2 pixels to improve the accuracy of proposed method in detection of tampered region. The chaotic maps are used in block mapping phase to enhance security of the proposed scheme. A novel efficient metric for determining rough or smooth blocks are proposed, which has led to at least three advantageous. First, “decreasing of bandwidth consumption” due to minimum watermark payload length. Indeed, the length of embedded data varies based on characteristic of block (6 bits for smooth blocks and 12 bits for rough blocks will be embedded in a host image). Some more advantageous are, “better tamper detection” and “self-recovery with high quality”, because of special image features which used in definition of information array. Our method, provides basic of watermarking scheme such as, invisibility, recover quality and security. Experimental results have proved that our method is powerful in tamper detection, self-recovery and robust against the known watermarking attacks.