You are on page 1of 15

# The basics of Discrete Cosine Transform has been discussed.

The articles have been collected from various sources.

The Discrete Cosine Transform (DCT)
The discrete cosine transform (DCT) helps separate the image into parts (or spectral sub-bands) of differing importance (with respect to the image's visual quality). The DCT is similar to the discrete Fourier transform: it transforms a signal or image from the spatial domain to the frequency domain (Fig 7.8).

DCT Encoding The general equation for a 1D (N data items) DCT is defined by the following equation:

and the corresponding inverse 1D DCT transform is simple F-1(u), i.e.: where

The general equation for a 2D (N by M image) DCT is defined by the following equation:

f(i. F(u.: where The basic operation of the DCT is as follows:         The input image is N by M. much of the signal energy lies at low frequencies. these can range from -1024 to 1023. .   The output array of DCT coefficients contains integers. It is computationally easier to implement and more efficient to regard the DCT as a set of basis functions which given a known input array size (8 x 8) can be precomputed and stored. and are often small .v) is the DCT coefficient in row k1 and column k2 of the DCT matrix. these appear in the upper left corner of the DCT. This array contains each pixel's gray scale level. i.0]? answer: They define DC and AC components.and the corresponding inverse 2D DCT transform is simple F-1(u.small enough to be neglected with little visible distortion. 8 bit pixels have levels from 0 to 255. The values as simply calculated from the DCT formula. This involves simply computing values for a convolution mask (8 x8 window) that get applied (summ values x pixelthe window overlap with image apply window accros all rows/columns of image).j) is the intensity of the pixel in row i and column j.9.e. The 64 (8 x 8) DCT basis functions are illustrated in Fig 7. Therefore an 8 point DCT would be: where Question: What is F[0. For most images. Compression is achieved since the lower right values represent higher frequencies. The DCT input is an 8 by 8 array of integers.v).

10) DCT/FFT Comparison  o  Computing the 2D DCT Factoring reduces problem to a series of 1D DCTs (Fig 7.DCT basis functions  Why DCT not FFT? DCT is similar to the Fast Fourier Transform (FFT).11): apply 1D DCT (Vertically) to Columns . but can approximate lines well with fewer coefficients (Fig 7.

and Signal Processing 1989 (ICASSP `89). The equations are given by: o o Most software implementations use fixed point arithmetic. World record is 11 multiplies and 29 adds. Loeffler. Images do however tend to compact their energy in the frequency domain making compression in the frequency domain much more effective. Speech. 988-991) DISCRETE COSINE TRANSFORM Out of the image compression techniques available. The Discrete Cosine Transform (DCT) is an example of transform coding. Conf. The current JPEG standard uses the DCT as its basis. (C. Int'l. The DCT coefficients are all real numbers unlike the Fourier Transform. DCT: . The DC relocates the highest energies to the upper left corner of the image. Transform coding is simply the compression of the images in the frequency domain. The DCT is fast. "Practical Fast 1-D DCT Algorithms with 11 Multiplications". the coefficients must not allow for the loss of any information. or alternatively Horizontal to Vertical. The lesser energy or information is relocated into other areas. transform coding is the preferred method. Some fast implementations approximate coefficients so all multiplies are shifts and adds. Transform coefficients are used to maximize compression. Proc. It can be quickly calculated and is best for images with smooth edges like photos with human subjects. pp. compression in the spatial domain is not an easy task. The Inverse Discrete Cosine Transform (IDCT) can be used to retrieve the image from its transform representation. A.  apply 1D DCT (Horizontally) to resultant Vertical DCT above. Ligtenberg and G. on Acoustics. For lossless compression. Moschytz. Since energy distribution varies with each image.

was then formed in 1986 in order to avoid competing standards among the three standards organizations. JPEG has been in existence for nearly a decade. The DCT is the transform used in JPEG compression. It is said that the core of JPEG 2000 is Wavelet technology. the International Telegraph and Telephone Consultative Committee (CCITT). Revisions updating JPEG to make use of our current text-based technologies are in progress. The Joint Photographic Experts Group. The project began under ISO as Working Group 8 but later merged with CCITT. It was drafted as the ISO Committee Draft 10918 or Digital Compression and Coding of Continuous-Tone Still Images. The release date has been set for January 2000. DCT ● A technique for converting signal into elementary frequency components ●Why we need compression? . The standard was intended for natural. The project team isdeveloping a JPEG format that provides more compression options and better images which take up the same amount of space. the Adaptive Discrete Cosine Transform (DCT) was chosen to be the core of the JPEG format.IDCT: HISTORY OF JPEG "Joint Photographic Experts Group" is the original name of the committee that created the JPEG format. The JPEG project began back in 1982. actually a subcommittee of ISO. It was designed to compress natural pictures that are smooth and curved and have no jagged edges. the format would be able to send loss-less images. and the International Electrotechnical Commission (IEC). real world scenes. After testing of numerous schemes. The goal was to create a data compression standard that would display an image within one second down a 64 Kbits/sec ISDN line. but implementation will probably take some time. Eventually. This project has been in progress since August 1998. It was officially standardized as the International Standard ISO 10918-1. the merged ISO/IEC committee gave their approval to make the JPEG the standard. The standard was a joint effort by three of the world's largest standards organizations: The International Organization for Standardization (ISO). Three years later.

The need for sufficient storage space. and long transmission time for image. For analysis of two-dimensional (2D) signals such as images. we need a 2D version of the DCT . and video data Principles behind compression ● Redundancy reduction Aims at removing duplication from the signal source ● Irrelevancy reduction It omits parts of the signal that will not be noticed by the signal receiver. The general equation for a 1D (N data items) DCT is defined by the following equation: The one-dimensional DCT is useful in processing one-dimensional signals such as speech waveforms. large transmission bandwidth. audio. One-Dimensional Discrete Cosine Transform The DCT can be written as the product of a vector (the input list) and the n x n orthogonal matrix whose rows are the basis Vectors. We can find that the matrix is orthogonal And each basis vector corresponds to a sinusoid of a certain frequency.

Entropy Coding (EC) achieves additional compression losslessly by encoding the quantized DCT coefficients more compactly based on their statistical characteristics. which contains a significant fraction of the total image energy. is differentially encoded. DCT introduces no loss to the source image samples. or are compressed by alternately interleaving 8x8 sample blocks from each in turn. image quality degrades because of the artifacts resulting from the block-based DCT scheme. While the DCT-based image coders perform very well at moderate bit rates. The DC coefficient. ● Assuming a periodic input. the magnitude of . For a typical 8x8 sample block from a typical source image. Advantages and Disadvantages ● The DCT does a better job of concentrating energy into lower order coefficients than does the DFT for image data ● The DCT is purely real. the DFT is complex. DCT merely transforms them to a domain in which they can be more efficiently encoded. at higher compression ratios. most of the spatial frequencies have zero or near-zero amplitude and need not be encoded.DCT-based are either compressed entirely one at a time.

jsp?tp=&arnumber=4449470&isnumber=4479597 screte Cosine Transform The DCT transforms a signal from a spatial representation into a frequency representation. and Jingjing Fu http://ieeexplore.JPEG does this by dividing the coefficients by a quantization matrix in order to get long runs of zeros) Compress the quantized coefficients using a lossless method (RLE.seecs. etc) The formulae for a 2D DCT: . IEEE. throw away unimportant information to reduce the filesize .ieee.http://www.edu.e.pdf 4. Directional Discrete Cosine Transforms—A New Framework for Image Coding by Bing Zeng.http://www. Arithmetic coding.the DFT coefficients is spatially invariant . An oversimplified JPEG compressor:     Cut an image up into chunks of 8x8 pixels Run each chunk through an 8x8 2D DCT Quantize the resulting coefficients (i. Lower frequencies are more obvious in an image than higher frequencies so if we transform an image into its frequency components and throw away a lot of higher frequency coefficients. we can reduce the amount of data needed to describe the image without sacrificing too much image quality.html 2.com/watch?v=hgr5O0du-sg 3.pk/publications/tech_reports/DCT_TR802.http://wisnet. Huffman.uk/Dave/Multimedia/node231.org/stamp/stamp. Member. This is not true for the DCT REFERNECES: 1.cf.youtube.ac.cs.

we use the IDCT formulae: .Four example blocks in spatial and frequency domains: >>> Spatial Frequency Inverse Discrete Cosine Transform To rebuild an image in the spatial domain from the frequencies obtained above.

the DCT is perfectly reversable and we do not lose any image definition until we start quantizing coefficients.Mathematically. A better quantizer would decrease precision gradually instead of simply zeroing out components. In my simulation. Original image 4x4 (25%) 3x3 (14%) 2x2 (6%) Do those artifacts look familiar? . I simply threw most of them out. Below is the original image and reconstructions of it using only the most significant n x n coefficients.

Even a naïve implementation of the separated DCT.Discrete Cosine Transform and Quantisation The Advanced Image Coding codec uses the Discrete Cosine Transform (DCT) to transform a 8x8 residual block into a set of coefficients to cosine functions with increasing frequencies. will run faster than a single-pass 2D DCT. The formula: This means that instead of performing a 2D DCT. see the Resources and links section. we can perform a 1D DCT on each row and then on each column of the block we're processing. Below you will find a short introduction to the DCT. The AAN (Arai/Agui/Nakajima) algorithm is one of the fastest known 1D DCTs. such as the one in listing2. 1-Dimensional DCT The 1-dimensional Forward DCT transforms a row of 8 residual values (V) into a row of 8 coefficients(C): . AIC . listing3. For more detailed information there are plenty of resources available on the internet.c.c shows a still faster 2D DCT built from 1D AAN DCTs.Optimization A 2D DCT can be evaluated more quickly using a series of 1D DCTs.

The following figure shows the result of the FDCT. The later coefficients are much smaller than the first ones. The following graphs clarify this: . which might indicate that these do not contribute much to the image quality. only positive values are used here) Sample row Residual values DCT coefficients 121 61 58 -175 61 43 113 49 171 37 200 10 226 5 246 5 The resulting DCT coefficients don't look better compressible at all. applied to a sample row. The residual values are represented using shades of gray (for clarity. however. can be seen in the decreasing magnitude of the coefficients. The clue to compression.

an additional coefficient (AC coefficient) is added to the reconstruction. By using only 4 of the 8 coefficients. In the first graph. which means that the DC coefficient represents the average of an entire row of values. the subsequent improvements become smaller and less noticeable. The first graph shows a straight line through the average residual values. the reconstructed line is already close to the original. only the first DCT coefficient (the DC coefficients) is used to reconstruct the values. By adding AC coefficients. detail is added to the image and the blue line moves closer to the original red dots. In each following graph. This is the key to compression. The blue line represent the reconstructed residual values after performing an Inverse DCT on several DCT coefficients. Since the higher-order (high-frequency) DCT coefficients . also shown at the bottom of each graph.The red dots represent the original residual values. From the fifth graph onward.

and AIC. they can be discarded while still producing a close approximation of the original.contribute less information to the image. use quantisation. This will make the coefficients better compressible. When you choose a quality level in JPEG or AIC. Quantisation But completely discarding coefficients is not always desirable. which is just a fancy word for dividing in this context. Several tests have shown that uniform quantisation is more appropriate in this case. 2-Dimensional DCT The 1-dimensional DCT discussed above only takes advantage of correlation between residual values in a row. This is why JPEG. but also reduces image quality because the coefficients cannot be reconstructed faithfully. It also uses a nonuniform quantisation method by which high frequency coefficients (the later coefficients) are quantised with higher values than low frequency ones. JPEG uses the DCT to transform pixel values instead of residual values. The higher this value. In certain types of images with high contrast. This is done by performing a 2dimensional DCT on a block of 8x8 residual values: However. . the smaller the results will be. the high frequency coefficients are important to the image detail and cannot be discarded. like textual images or cartoons. AIC performs the DCT on residual values. you actually set the amount of quantisation used. In AIC. Each coefficient gets divided by a certain value. all coefficients are quantised by the same value. followed by a 1D DCT on all columns from the result of the first step. This is much faster than implementing a 2D DCT directly. Better compression can be achieved when we take both the horizontal and vertical correlation between residual values into account. a 2D DCT can also be implemented by first applying a 1D DCT on all rows.

Agui and Nakajima) algorithm is used to calculate the DCT. so there is no need to reorder the DCT coefficients. AIC only uses the floating point algorithm since it produces the highest quality images. The CABAC codec does not use run length encoding. . This reference software supports different algorithms. So in AIC. To speed up the calculations. in the last step. but on modern computers. In JPEG the DCT coefficients are transmitted in zigzag order to form runs of zeros which can be encoded using run length encoding. floating point calculations are performed much faster than in the old days. the AAN (Arai.The DCT code used in the AIC codec is based on the code in the JPEG reference software from the Independent JPEG Group. the coefficients are transmitted in scan line order. the DCT coefficients and prediction modes are encoded to the stream using Context Adaptive Binary Arithmetic Coding(CABAC). Finally. It's a bit slower than the other algorithms.

:920/.

34/0 92  995.

.

 4:9:-0 .42.

7 /: 8  995...9.

.

8309 800.8 0/: 5.

.9438.5:-.

90.*7054798.

8.3814728 07.943.0 4/3-303 02-07  .70904830%7.20471472.%*%#  5/1  70.3/33: 995.

.

0005470 000 47.

89.25.

090.9.25 8595 .425430398.32..705708039.943394.9  34.3/974.1706:03.0782510/!.2.094:98.4:83.0 6:.0394981706:03.4941071706:03.73:2-07 83:2-07  _U^W`W[_ZW^SZ_X[^ %0%97.9.300/0/94/08.39442:.4011.83.3 2.3071706:03..24:3941/.08.3814728.425708847 .381472.943  4071706:03.0398 0 .89.1742.08841097.7024704-...71.705708039.09.85.7-0902..370/:..

f°¯f ½°n°¾½ ¾ ° fnn°f°.

@ .f°   ¾°n n °¾% ff°¯½f°°¯f° n    ¾  9  ¾¾   ° n n °¾ ff°f°¯f°  ° °¾ ¾% O .

0147.% .¯½ ¾¾ f° n n °¾¾°f¾¾ ¾¾¯  % ¯f° ¯ nn °  n% O O O %01472:.

0 0:8090% 1472:.084-9..0    .   4:70.250-4.9.039085.3/1706:03.9.30/.31742901706:03.32.-4.38      ½ff    °n ZbW^_W_U^W`W[_ZW^SZ_X[^ %470-:/.8385./42./42.

393.70.425430398  04890473..43897:. 90%850710.39074://0..796:.2.-0.0398   °f¯f  % %   % % % %  49480.98441.8437.9438419:8343902489831.4011.0398 3282:..7  ./:.791.9.3933 .32.3/70.943 8259702489419024:9 -09907 6:.902.2.4011..0/013943:39 089.0.80570./4182507434:9.3/0/4349480.078.3890.970.

.

3-00.7.\` S`[Z %.9434190805./4150714723.90/24706:.  %820.0883 ..93890.:83..89079.90/ % 8:.....389..3.35071472.%430.03.8070841%8 %01472:.0 70574..:.% 0.3/ 903430.88%  %0 7.8904303893 .830 5.02502039.3.M.74. 7:31.4:234190-4.

:.

381472 % 9497.7/%97.4792843041901.9439490% 472470/09.3814728..7441708/:..70904830%7.4011.9439070.% %0 /203843. 848.70 5039417084:7.0/31472. 708/:.70..:808908.0398   . ..394.08.4011.4/0.89089343%8 893 .48301:3.08  044:13/.04/3..0/2.943893.-4.8907%-:91742%8      _U^W`W[_ZW^SZ_X[^SZVaSZ`_S`[Z %0/.:08 ' 394.943   203843..3.039894.-04390390730980090#084:7.2.831706:03.08.7441 .3/3880..891.84793974/:..381472.47.80941.

 147.25074 %0708/:..707057080390/:838.:08 .550/94...70:80/070  f¯½    ¾ ff ¾              .0.8./08417.:08.79 435489. %014431:7084890708:94190% ..

4011.9 %014437.70.39:/04190.293/.7198 .907.9.4011.82.58.0398 %0.425708843  40.4011.3-08003390/0.99080/4349.06:.079.0398/43 944-09907...4397-:902:.832.909.70 2:.07 .0398..@n n °¾    %0708:93%.9490 2.4257088-0. %0.39017894308 .:094.

..07.5 .943 %017897.0398 9070.84843. %070//49870570803990473..70..990.039 .:08 30.897.. 742901197.4011.:08 .0398 39017897.039 8 .190750714723.07.09007 47/07  1706:03.0.08.5 43901789%.0708/:.7./..43897:..4011.43897:. %. 70//498 :83434190.3/088 349.425708843 \$3.930974:90.07.43897:.039705708039890.//0/94902..039 90.42082.0398 8:80/ 9470.//3.7/ 908:-806:0392574.//943.0398 .5848.4011.3/90-:03024.4011.90/308.:08.990.041.543.4809490 473.0398 /09.07.0.0780%4380.4011.14437.990-49942410.-0  %8890094.4011.389.48079490473.:08  .4011.3039707441..90/708/:.4011.:08 .020398-0.43897:..4011.. %. .5 %0 -:0307057080399070.3..20.708/:.33.8.//0/949070.

:880/..480 ..:089..3-0/8.398. .398.9438 2470.%.07 .4397-:9008831472..3.398..%43.399490 2..24:3941 6:..943-09003708/:.:08  40.079.89079.3980/-908.1.%/8..3/.079.748 1440/ -.08.84-025020390/-1789.1706:03.94394902.% %0 /203843.3349-0/8.20..0847..47/147/.-4.090.06:.3/ :806:.7/0/089574/:.0/09.0398..89 0909:.9-0.03!47 4:.9:.  ":.039098/./41708/:.425708843.4011.082.4257088-0 -:9.39.4308  5071472890%43708/:.8/087.84:808.4011.91: 034:..4011..43909 .90.80990.9434190473..398.8:89 .553.-0 3.90898...3..%43.4397.4480....4011.4011.3349-070.3 25020393.07.:083..7/3..943:80/  !:80890%9497..1.90398.7/0/ %88! .74 09907.4011..55742.3.0398.343 :314726:.0 90./0/-./3398..3-0..:08 9.7025479.%/70.943 :9.706:...0/0309.079.4770.4011.0398.0-499047439....38147250.:0   203843.:08394.:083890. /203843.2.341706:03...3980/907.425090/8.03988349.943-09003708/:.0439.398.9432094/-.%43.4:39 %88/430-50714723..9  .3.0790708:98-0 %82./.0398-09907 .70 6:.557457..0.041.0398 .9:314726:...:08 \$0..089 ..907.8470/:..0398 90.4770.08439.:0 9082..-4.:0 %0 0798.80 3 .90/ 1.3/ ..39508412..41708/:..43897:.943 .6:.794438 901706:03.4:238174290708:9419017898905 %882:.4011.:8090..

70 97.4/3  3!90%.7097.3904907.701742 903/0503/039!74:5 %87010703..2 :8343909/.4/3 849070834300/947047/07 90%.03.%0%.4/3 %0.8 %48500/:590.4011..4/0.4011.:.0398.4/0/:837:3039 03.92.08419.898905 90%..479283.8-.0398.47/079414727:38410748.3/ .47928:80/94..80/4390.935439.4011.47928 -:94324/073./408349:807:303903.94324/08.47928 43 :8089014.08419.2..9438. 390.4/0:80/390.382990/3.33904//.779209.:.4/0390!7010703.1.4011.708:554798/1107039..59.4/0/94908970.08 9 8.89079.4/0.09574/:..7003.:.3/570/.9438 90 7.935439.3-003.33047/07   . :.08900896:. .382990/38..0398..-98407 9.9090%  3.0398 \$43 90.7050714720/ 2:.425:9078 14..