# A Fast DCT Algorithm for Watermarking in Digital Signal Processor

Authors: S. E. Tsai; S. M. Yang
Journal: Mathematical Problems in Engineering
 (2017)

---

## Abstract

Discrete cosine transform (DCT) has been an international standard in Joint Photographic Experts Group (JPEG) format to reduce the blocking effect in digital image compression. This paper proposes a fast discrete cosine transform (FDCT) algorithm that utilizes the energy compactness and matrix sparseness properties in frequency domain to achieve higher computation performance. For a JPEG image of8×8 block size in spatial domain, the algorithm decomposes the two-dimensional (2D) DCT into one pair of one-dimensional (1D) DCTs with transform computation in only 24 multiplications. The 2D spatial data is a linear combination of the base image obtained by the outer product of the column and row vectors of cosine functions so that inverse DCT is as efficient. Implementation of the FDCT algorithm shows that embedding a watermark image of 32 × 32 block pixel size in a 256 × 256 digital image can be completed in only 0.24 seconds and the extraction of watermark by inverse transform is within 0.21 seconds. The proposed FDCT algorithm is shown more efficient than many previous works in computation.


---

## Body

## 1. Introduction

Discrete cosine transform (DCT) has been widely used to convert a dynamic signal into frequency components so as to reduce digital image storage size, expedite data transmission, and remove redundant information. DCT is closely related to discrete Fourier transform with the advantage of concentrating the energy of transformed signal in low frequency range where human eyes are less sensitive in image processing [1]. The joint ISO committee therefore adopts DCT to Joint Photographic Experts Group (JPEG) international standard of 8 × 8 block size to reduce the blocking effect in image compression. A basic JPEG image encoding is composed of three procedures: image transform, quantization, and encoding.DCT can map an original data into frequency domain by cosine waveform, and conversely inverse discrete cosine transform (IDCT) transfers frequency domain data into spatial domain. Numerous coding methods based on DCT have been presented for digital image processing; however, the associated memory size, bandwidth, and safety issues are of significant concern to real-time applications. Sun and Yang [2] proposed an image compression method based on a Laplace transparent composite model to achieve high coding efficiency. Jridi et al. [3] presented image compression hardware to reduce computational complexity. Others have proposed to optimize image computation by digital signal processor (DSP). Kumbhare and Gokhale [4] developed a low complexity architecture for computing an algebraic integer based 8-point DCT in digital image processing. Jridi et al. [5] designed a low complexity DCT engine in digital video and image processing. Subband decomposition algorithms based on DCT have also been used in transmitting image data of low resolution to rebuilt image of better quality [6–8], but they required high complexity and thus time-consuming computation. Stassen’s matrix multiplication algorithm was proposed to reduce complex matrix multiplication in DCT [9]. Khan et al. [10] increased the coordination between the pixel size and subword size to maximize resource utilization for multimedia application, but the work required heavy computation. This paper proposes a fast DCT (FDCT) algorithm with significantly reduced number of multiplications to achieve higher computation efficiency in digital image processing. It is also shown suitable for hardware implementation in DSP on digital watermarking applications.


## 2. DCT in JPEG

The basic JPEG image encoding method is composed of three procedures: image transform, quantization, and encoding. Figure1 shows the encoder and decoder model, where an original image is first divided into block pixel size 8 × 8 in RGB model with each block in 0 to 63 frequency coefficients as shown in Figure 2. The low frequency coefficients are in the light color region. During image processing, DCT maps the spatial domain data into frequency domain by cosine waveform and conversely in inverse discrete cosine transform [11]. The spatial domain indicates the “magnitude” of a color image while the frequency domain shows the magnitude change from one pixel to the next. In DCT, the original host signal is first divided into nonoverlapping 2D blocks of size 8 × 8. Each block is then processed independently and transformed into AC and DC coefficients in frequency domain, representing the average color of the block and the color change across the block, respectively.Figure 1
The encoder and decoder model of JPEG compression standard by using discrete cosine transform (DCT) and inverse discrete cosine transform (IDCT).Figure 2
The distribution of coefficients in DCT, (a) low frequency position (heavy color), (b) low-middle-frequency position (light color), (c) high-middle frequency position (light color with dots), and (d) high frequency position (white).After DCT, a quantizer with quantization table is used to provide higher compassion ratio in transmission by approximating a continuous set of values in image data to a finite (preferably small) set of values. It is done by dividing each component in frequency domain by a constant and then rounding to the nearest integer. The input to a quantizer is the original data and the output is by a function of a set of discrete, finite output values. A good quantizer is to represent the original signal with minimum loss or distortion. A highly useful feature of JPEG process is that varying levels of image compression and quality are obtained by the selection of specific quantization matrix, similar to weighting function to mean psychological visual capability. Quantization involves dividing each coefficient by an integer value between 1 and 255.After quantization, the DC coefficient, which contains a significant fraction of the total image energy, becomes a measure of the average value of the original 64 pixels, and the 63 AC components are treated in an entropy coding process in the order of increasing frequency. Because the 8 × 8 blocks are usually with strong correlation, the quantized DC coefficient is encoded as the difference from the DC term of the previous block. The higher frequency coefficients are more likely to be 0 or negligible after quantization, thereby improving the compression of run-length encoding.


## 3. Fast Discrete Cosine Transform (FDCT)

### 3.1. 1D FDCT

In proposed fast discrete cosine transform (FDCT) algorithm, an original signal is first divided into nonoverlapping 2D blocks of size 8 × 8 in three color components as shown in Figure1 in JPEG format. Each block is then processed independently by the transform. Consider a spatial domain image data of 8-point, s=[s(0)s(1)⋯s(7)]T being transformed into frequency domain f, f=[f0f1⋯f(7)]T, where(1)fk=12Ck∑i=07sicos⁡2i+1kπ16with C(k)=1/2, if k=0, and C(k)=1 for others. f(0) and f(4) can be evaluated without multiplication, only by addition and subtraction. There are only six elements left in f to be evaluated. Further minimization of the number of multiplications can be achieved by regrouping the coefficients by using the symmetric property to yield (2)f2f6f7f5f1f3=bd0000d-b000000ef-ac00face00-ac-e-f00ce-f-as0-s3-s4+s6s1-s2-s5+s6s0-s7s6-s1s3-s4s2-s5,where a=0.488, b=0.463, c=0.416, d=0.192, e=0.098, and f=0278. The number of multiplications is now reduced to 20. To eliminate one more multiplication, f(2) and f(6) can be evaluated by(3)f2f6=Ab-ds0-s3-s4+s7ds0+s1-s2-s3-s4-s5+s6+s7-b-ds1-2-s5+s6,where A=110011, so that f(1), f(3), f(5), and f(7) become(4)f7f5-f1f3=A∗Ae+a-f+cs0-s7f-cs0-s7+s6-s1a-e-f+cs6-s1A-a-cs0-s7+s3-s4cs0-s7+s3-s4+s6-s1+s2-s5e-cs6-s1+s2-s5Ae-a-f-cs3-s4f+cs3-s4+s2-s5a+e-f-cs2-s5,where A∗=II00I-I with I being the 2 × 2 identity matrix. By now, DCT only needs 12 multiplications. Similarly, the inverse transform is (5)s′i=12∑k=07Ckfkcos⁡2i+1kπ16,where C(k)=1/2, if k=0, and C(k)=1 for others. Careful observation reveals that it is straightforward to derive inverse transform IDCT from DCT by(6)s′0s′1s′2s′3s′4s′5s′6s′7=11bdef-ac1-1d-b-f-a-c-e1-1-dbce-f-a11-b-d-ac-e-f11-b-da-cef1-1-db-c-efa1-1d-bface11bd-e-fa-cf0f4f2f6f7f5-f1f3.By shifting and swapping the corresponding rows, (6) can be decomposed as (7)s′0s′6s′3s′2s′7s′1s′4s′5=B+CB-C+DB+CB-C-D.The matrix is made up in three building blocks with symmetric coefficient matrices,(8)
B
=
1
1
1
-
1
f
0
f
4
,
C
=
b
d
d
-
b
f
2
f
6
,
D
=
e
f
-
a
c
a
c
e
-
e
-
f
s
y
m
m
.
-
a
f
7
f
5
-
f
1
f
3
.Both FDCT and fast IDCT have the same coefficients and matrix blocks. It is thus efficient in hardware implementation.


### 3.2. 2D FDCT

Implementation of a 2D DCT is by separating into a pair 1D DCT as illustrated in Figure3. Consider a 2D spatial data sequences(i,j), 0≤i,j≤7, in matrix S of 8 × 8, and the corresponding 2D DCT sequence f(u,v), 0≤u,v≤7, in frequency domain of matrix F is defined as (9)fu,v=14CuCv∑i=07∑j=07si,jcos⁡2i+1uπ16cos⁡2j+1vπ16.The inverse transformation represented by S′, S′=s′i,j,(10)s′i,j=14∑u=07∑v=07CuCvfu,vcos⁡2i+1uπ16cos⁡2j+1vπ16,where C(u),C(v)=1/2 if u,v=0 andC(u), C(v)=1 for others. By defining a matrix M={m(u,v)}, where m(u,v) represents the matrix element in theuth row andvth column, (11)mu,v=122,u=0∪0≤v≤712cos⁡2v+1uπ16,1≤u≤7∪0≤v≤7.A 2D DCT data matrix F and its inverse matrix S′ can be written as(12a)F=MSMT,(12b)S′=MTFM.Because the base vectors of DCT are orthogonal, the inverse transform IDCT can therefore be easily obtained as shown in (12b). DCT transforms high correlated image into a few transform coefficients. Conventional image coding techniques use the quantization process to achieve higher compression ratio. Therefore, F includes only a few nonzero elements in the low frequency range, which makes it possible to design efficient IDCT algorithm by fully utilizing the computation efficiency in (3) and (4) and the energy compactness property of F.Figure 3
The FDCT algorithm of 2D DCT calculated by one pair of 1D DCTs.The 2D spatial data matrixS′ in (12b) can be considered as linear combination of the base images or the outer product of the column and row vectors in M. This interpretation makes it easier for (12a) and (12b) to manipulate the sparseness of the 2D DCT matrix F and to calculate the spatial data matrix S′. The proposed FDCT algorithm achieves high computation performance over many other previous algorithms. The row (or column) data can be processed by using 1D DCT (or IDCT) first with the results stored in transposition memory. By exploiting the redundancy in the coefficients of DCT, the algorithm reduces the complexity of 2D DCT of an 8 × 8 block to only 24 multiplications.


## 3.1. 1D FDCT

In proposed fast discrete cosine transform (FDCT) algorithm, an original signal is first divided into nonoverlapping 2D blocks of size 8 × 8 in three color components as shown in Figure1 in JPEG format. Each block is then processed independently by the transform. Consider a spatial domain image data of 8-point, s=[s(0)s(1)⋯s(7)]T being transformed into frequency domain f, f=[f0f1⋯f(7)]T, where(1)fk=12Ck∑i=07sicos⁡2i+1kπ16with C(k)=1/2, if k=0, and C(k)=1 for others. f(0) and f(4) can be evaluated without multiplication, only by addition and subtraction. There are only six elements left in f to be evaluated. Further minimization of the number of multiplications can be achieved by regrouping the coefficients by using the symmetric property to yield (2)f2f6f7f5f1f3=bd0000d-b000000ef-ac00face00-ac-e-f00ce-f-as0-s3-s4+s6s1-s2-s5+s6s0-s7s6-s1s3-s4s2-s5,where a=0.488, b=0.463, c=0.416, d=0.192, e=0.098, and f=0278. The number of multiplications is now reduced to 20. To eliminate one more multiplication, f(2) and f(6) can be evaluated by(3)f2f6=Ab-ds0-s3-s4+s7ds0+s1-s2-s3-s4-s5+s6+s7-b-ds1-2-s5+s6,where A=110011, so that f(1), f(3), f(5), and f(7) become(4)f7f5-f1f3=A∗Ae+a-f+cs0-s7f-cs0-s7+s6-s1a-e-f+cs6-s1A-a-cs0-s7+s3-s4cs0-s7+s3-s4+s6-s1+s2-s5e-cs6-s1+s2-s5Ae-a-f-cs3-s4f+cs3-s4+s2-s5a+e-f-cs2-s5,where A∗=II00I-I with I being the 2 × 2 identity matrix. By now, DCT only needs 12 multiplications. Similarly, the inverse transform is (5)s′i=12∑k=07Ckfkcos⁡2i+1kπ16,where C(k)=1/2, if k=0, and C(k)=1 for others. Careful observation reveals that it is straightforward to derive inverse transform IDCT from DCT by(6)s′0s′1s′2s′3s′4s′5s′6s′7=11bdef-ac1-1d-b-f-a-c-e1-1-dbce-f-a11-b-d-ac-e-f11-b-da-cef1-1-db-c-efa1-1d-bface11bd-e-fa-cf0f4f2f6f7f5-f1f3.By shifting and swapping the corresponding rows, (6) can be decomposed as (7)s′0s′6s′3s′2s′7s′1s′4s′5=B+CB-C+DB+CB-C-D.The matrix is made up in three building blocks with symmetric coefficient matrices,(8)
B
=
1
1
1
-
1
f
0
f
4
,
C
=
b
d
d
-
b
f
2
f
6
,
D
=
e
f
-
a
c
a
c
e
-
e
-
f
s
y
m
m
.
-
a
f
7
f
5
-
f
1
f
3
.Both FDCT and fast IDCT have the same coefficients and matrix blocks. It is thus efficient in hardware implementation.


## 3.2. 2D FDCT

Implementation of a 2D DCT is by separating into a pair 1D DCT as illustrated in Figure3. Consider a 2D spatial data sequences(i,j), 0≤i,j≤7, in matrix S of 8 × 8, and the corresponding 2D DCT sequence f(u,v), 0≤u,v≤7, in frequency domain of matrix F is defined as (9)fu,v=14CuCv∑i=07∑j=07si,jcos⁡2i+1uπ16cos⁡2j+1vπ16.The inverse transformation represented by S′, S′=s′i,j,(10)s′i,j=14∑u=07∑v=07CuCvfu,vcos⁡2i+1uπ16cos⁡2j+1vπ16,where C(u),C(v)=1/2 if u,v=0 andC(u), C(v)=1 for others. By defining a matrix M={m(u,v)}, where m(u,v) represents the matrix element in theuth row andvth column, (11)mu,v=122,u=0∪0≤v≤712cos⁡2v+1uπ16,1≤u≤7∪0≤v≤7.A 2D DCT data matrix F and its inverse matrix S′ can be written as(12a)F=MSMT,(12b)S′=MTFM.Because the base vectors of DCT are orthogonal, the inverse transform IDCT can therefore be easily obtained as shown in (12b). DCT transforms high correlated image into a few transform coefficients. Conventional image coding techniques use the quantization process to achieve higher compression ratio. Therefore, F includes only a few nonzero elements in the low frequency range, which makes it possible to design efficient IDCT algorithm by fully utilizing the computation efficiency in (3) and (4) and the energy compactness property of F.Figure 3
The FDCT algorithm of 2D DCT calculated by one pair of 1D DCTs.The 2D spatial data matrixS′ in (12b) can be considered as linear combination of the base images or the outer product of the column and row vectors in M. This interpretation makes it easier for (12a) and (12b) to manipulate the sparseness of the 2D DCT matrix F and to calculate the spatial data matrix S′. The proposed FDCT algorithm achieves high computation performance over many other previous algorithms. The row (or column) data can be processed by using 1D DCT (or IDCT) first with the results stored in transposition memory. By exploiting the redundancy in the coefficients of DCT, the algorithm reduces the complexity of 2D DCT of an 8 × 8 block to only 24 multiplications.


## 4. Performance Evaluation in Digital Image Watermarking

Discrete cosine transform (DCT) can map an original digital data into frequency domain by cosine waveform, and, conversely, inverse discrete cosine transform (IDCT) transfers the frequency domain data into spatial domain. The associated memory size, bandwidth, and safety issues in the transformation algorithms are of significant concern. Direct computation of 2D DCT (N ×N pixel size of a block) requires N4 multiplications, while direct realization (with the row-column separation) of 8 × 8 DCT 2×83=1024 multiplications. Although many algorithms have been proposed to optimize multiplications, they either required huge amount of computation [6–8, 10] or suffered from low efficiency [4, 5, 9]. Table 1 lists the number of multiplications required in preview works compared with the proposed FDCT algorithm. The latter is much more efficient in computation as described in (2) to (12a) and (12b) where only 12 × 2 = 24 multiplications are needed. By comparison, Jridi et al. [5] needed 256 multiplications as they simply calculated 8 × 8 standard DCT. Similarly, Ko et al. [7] required 31 multiplications, while Sung et al. [8] based on subband decomposition needed 25 multiplications. Manoria and Dixit [9] used Stassen’s matrix multiplication but their 2D DCT (8 × 8) needed 28 multiplications. Khan et al. [10] took 40 multiplications for 2D DCT operation on an image of 8 × 8 block. In summary, both the FDCT algorithm and its inverse transform are more efficient than many previous works in reducing the complexity of computation. Implementation in digital signal processor (DSP) for real-time digital watermarking becomes feasible.Table 1
The number of multiplications for 2D DCT by the algorithms of previous works and by the proposed FDCT algorithm.
Algorithm Number of multiplications for2D DCT (8 × 8 block) Direct computation 84 = 4,096 Direct computation(with line-column separation) 2 × 83 = 1024 Jridi et al. [5] 256 Ko et al. [7] 31 Sung et al. [8] 25 Manoria and Dixit [9] 28 Khan et al. [10] 40 FDCT algorithm (this work) 24The process of embedding watermark in digital image for copyright protection and marketing applications have been proposed over the past decade. Conventional technique is to embed a secret bit string in spatial, frequency, or wavelet domain into an image. The FDCT algorithm is implemented in a digital signal processor (TMS320C6701) to validate its efficiency in digital watermarking applications. The signal processor in both fixed-point and floating-point is supported by a set of software development tools with C/C++ compiler, assembly optimizer, a linker, and assorted utilities as shown in Figure4. The proposed FDCT algorithm is written in C language, and the C/C++ compiler is able to perform optimization (n=0,1,2,3) in different level of clock cycles and code size. The lowest level (n=0) optimization provides the operations of performing loop rotation, allocating variables to registers, and simplifying expressions and statements, the first level (n=1) on constant propagation and unused assignments, the second level (n=2) on software pipelining, unused global assignments, loop unrolling, and incremented pointer, and the highest level (n=3) on optimization by simplifying functions with return values never used, removing all functions never called, inline calls to small functions, and reorder function declarations so that the attributes of called functions are known when the caller is optimized. n=0 and 1 levels can efficiently reduce the code size, while n=2 and 3 enhance the execution speed with larger code size. The computation time and code size in different levels of optimization are listed in Table 2. With increasing code size, the clock cycles and processing time decrease, so the best optimization is by n=3.Table 2
Processing time of the FDCT algorithm in DSP.
Optimization level (n) Clocks (cycle) Time (ms) Code size (KB) None 22,141,816 133 21 0 15,304,558 92 19 1 11,207,925 67 22 2 5,715,198 35 36 3 5,653,914 34 35 Matlab NA 610 NAFigure 4
Software environment in implementing the FDCT algorithm on DSP (TMS320C6701).For a digital watermark (32 × 32 block size) embedded in an original image (256 × 256), calculation by the FDCT algorithm in frequency domain and then inverse transform of the encrypted data back to spatial domain image uses 5,653,914 clocks (n=3), corresponding to 34 ms in 35 KB code size. Implementation shows that it takes only 0.24 seconds to have the watermark embedded in the original image. Extraction of watermark by inverse transform IDCT is within 0.21 seconds. Real-time implementation of the FDCT algorithm in DSP for image processing is shown very efficient.


## 5. Conclusions

(1)
A fast discrete cosine transform (FDCT) algorithm that utilizes the energy compactness and matrix sparseness properties in frequency domain for higher computation performance is developed. For a JPEG image of8×8 block size in spatial domain, the algorithm first decomposes the 2D DCT into one pair of 1D DCTs, and the calculation can be completed in only 24 multiplications. The 2D spatial data is a linear combination of base image obtained by the outer product of the column and row vectors of cosine functions such that the inverse DCT is as efficient. The algorithm is shown to achieve high performance compared to many other previous works. (2)
The algorithm optimizes a 2D DCT by exploiting the redundancy of the frequency coefficients so as to facilitate the implementation in digital signal processor (DSP). For a spatial domain data matrixS, the 2D DCT data matrix F includes only a few nonzero elements in the low frequency range, which makes it possible to design efficient IDCT algorithm. The energy compactness property of F and its inverse matrix S′ can be written as linear combinations of the cosine functions such that both FDCT and its inverse transform are shown to have the same coefficients and matrix blocks for efficient hardware implementation. (3)
An example of digital image watermarking is applied to demonstrate the efficiency of the FDCT algorithm. Hardware implementation of watermarking in DSP shows that it takes only 0.24 seconds to embed a 32 × 32 block size digital watermark into a digital image of block size 256 × 256. Implementation also shows that extraction of watermark can be completed within 0.21 seconds. The FDCT algorithm in DSP is shown efficient and effective in real-time implementation of digital image watermarking.



---

*Source: 7401845-2017-02-09.xml*