1、中文 4500 字 Image Compression Using the DiscreteCosine Transform Abstract The discrete cosine transform (DCT) is a technique for converting a signal into elementary frequency components. It is widely used in image compression. Here we develop some simple functions to compute the DCT and to compress im
2、ages. These functions illustrate the power of Mathematica in the prototyping of image processing algorithms. The rapid growth of digital imaging applications, including desktop publishing, multimedia, teleconferencing, and high-definition television (HDTV) has increased the need for effective and st
3、andardized image compression techniques. Among the emerging standards are JPEG, for compression of still images Wallace 1991; MPEG, for compression of motion video Puri 1992; and CCITT H.261 (also known as Px64), for compression of video telephony and teleconferencing. All three of these standards e
4、mploy a basic technique known as the discrete cosine transform (DCT). Developed by Ahmed, Natarajan, and Rao 1974, the DCT is a close relative of the discrete Fourier transform (DFT). Its application to image compression was pioneered by Chen and Pratt 1984. In this article, I will develop some simp
5、le functions to compute the DCT and show how it is used for image compression. We have used these functions in our laboratory to explore methods of optimizing image compression for the human viewer, using information about the human visual system Watson 1993. The goal of this paper is to illustrate
6、the use of Mathematica in image processing and to provide the reader with the basic tools for further exploration of this subject. The One-Dimensional Discrete Cosine Transform The discrete cosine transform of a list of n real numbers s(x), x = 0, ., n-1, is the list of length n given by: s(u)= 2/n
7、C(u) 10( 2 1 )( ) c o s 2nxxusx n u=0, n where 1/2( ) 2Cu for u=0 =1 otherwise Each element of the transformed list S(u) is the inner (dot) product of the input list s(x) andbasis vector. The constant factors are chosen so that the basis vectors are orthogonal and normalized. The eight basis vectors
8、 for n = 8 are shown in Figure 1. The DCT can be writthe product of a vector (the input list) and the n x n orthogonal matrix whose rows are the vectors. This matrix, for n = 8, can be computed as follows: DCTMatrix = Table If k=0, Sqrt1/8, Sqrt2/8 CosPi (2j+1) k/16 , k,0,7,j,0,7 / N; We can check t
9、hat the matrix is orthogonal: DCTMatrix . TransposeDCTMatrix / Chop / MatrixForm 1. 0 0 0 0 0 0 0 0 1. 0 0 0 0 0 0 0 0 1. 0 0 0 0 0 0 0 0 1. 0 0 0 0 0 0 0 0 1. 0 0 0 0 0 0 0 0 1. 0 0 0 0 0 0 0 0 1. 0 0 0 0 0 0 0 0 1. Each basis vector corresponds to a sinusoid of a certain frequency: ShowGraphicsArr
10、ayPartition ListPlot#, PlotRange - -.5, .5, PlotJoined - True, DisplayFunction - Identity& / DCTMatrix, 2 ; Figure 1. The eight basis vectors for the discrete cosine transform of length eight. The list s(x) can be recovered from its transform S(u) by applying the inverse cosine transform (IDCT): ()s
11、x = 2/n 10( 2 1 )( ) ( ) c o s 2nuxuC u s U n x=0, ,n where 1/2( ) 2Cu for u=0 =1 otherwise This equation expresses s as a linear combination of the basis vectors. The coefficients are the elements of the transform S, which may be regarded as reflecting the amount of each frequency present in the in
12、puts. We generate a list of random numbers to serve as a test input: input1 = TableRandomReal, -1, 1, 8 0.203056, 0.980407, 0.35312, -0.106651, 0.0399382, 0.871475, -0.648355, 0.501067 The DCT is computed by matrix multiplication: output1 = DCTMatrix . input1 0.775716, 0.3727, 0.185299, 0.0121461, -
13、0.325, -0.993021, 0.559794, -0.625127 As noted above, the DCT is closely related to the discrete Fourier transform (DFT). In fact, it is possible to compute the DCT via the DFT (see Jain 1989, p. 152): First create a new list by extracting the even elements, followed by the reversed odd elements. Then multiply the DFT of this re-ordered list by so-called twiddle factors