DCT transformation, DCT inverse transformation, and Block DCT Transformation
You are welcome to reprint it, but please indicate the source!
I. Introduction
The full name of DCT transformation is the discrete cosine transform (discrete cosine transform), which is mainly used to compress data or images and convert the signals in the airspace to the frequency domain, it has good de-relevance performance. DCT transform itself is lossless, but it creates good conditions for subsequent quantization and Haffman encoding in image encoding and other fields. At the same time, due to the symmetry of DCT transformation, we can use DCT inverse transformation After Quantization to restore original image information at the receiving end. DCT transform is widely used in current image analysis and compression fields. We use DCT transform in common JPEG static image encoding and MJPEG, MPEG dynamic encoding, and other standards.
Ii. One-dimensional DCT Transformation
The basis of Two-Dimensional DCT transformation during one-dimensional DCT transformation, so we will first discuss the next one-dimensional DCT transformation. There are eight types of one-dimensional DCT transformations, the most common of which is the second, because of its simple operation and wide applicability. We will only discuss this form here. Its Expression is as follows:
F (I) is the original signal, f (u) is the coefficient after DCT transformation, n is the number of points of the original signal, C (u) can be considered as a compensation coefficient, the DCT transformation matrix can be used as an orthogonal matrix.
3. Two-Dimensional DCT Transformation
In fact, two-dimensional DCT transformation is based on one-dimensional DCT transformation. The formula is as follows:
From the formula, we can see that the preceding section only discusses the situation where two-dimensional image data is a square matrix. in actual application, if the data is not a square matrix, it is usually completed before transformation, after reconstruction, the completed part can be removed to obtain the original image information. This attempt should be easier to understand.
In addition, due to the symmetry of the DCT height, we can use a simpler matrix processing method when using MATLAB for related operations:
Next, we use MATLAB to simulate the process:
1 clear; 2 clc; 3 x = round (RAND (4) * 100) % generates a random matrix 4 A = zeros (4 ); 5 for I = 6 for J = 7 if I = 0 8 A = SQRT (1/4); 9 else10 A = SQRT (2/4 ); 11 end 12 A (I + 1, J + 1) = A * Cos (pI * (J + 0.5) * I/4 ); 13 end14 end15 y = a * x * a' % DCT transform 16 YY = dct2 (x) % built-in DCT Transform of MATLAB
The running result is:
1 X = 2 3 42 66 68 66 4 92 4 76 17 5 79 85 74 71 6 96 93 39 3 7 8 9 Y =10 11 242.7500 48.4317 -9.7500 23.505212 -12.6428 -54.0659 7.4278 22.795013 -6.2500 10.7158 -19.7500 -38.804614 40.6852 -38.7050 -11.4653 -45.934115 16 17 YY =18 19 242.7500 48.4317 -9.7500 23.505220 -12.6428 -54.0659 7.4278 22.795021 -6.2500 10.7158 -19.7500 -38.804622 40.6852 -38.7050 -11.4653 -45.9341
From the above results, we can see that the method we use is the same as the result of the built-in DCT change method in MATLAB, so the correctness of our method is verified.
If the original signal is an image or other highly correlated data, we can find that after the conversion, the larger coefficient is concentrated in the upper left corner, and the lower right corner is almost 0, in the top left corner, the low frequency component is the low frequency component, and the low frequency coefficient is the contour and gray distribution characteristics of the target in the image. The high frequency coefficient reflects the details of the target shape. After DCT transformation, the energy is mainly concentrated in the low-frequency component, which is also a manifestation of the de-relevance of DCT transformation.
In the quantization and encoding phase, we can adopt the "Z" font encoding, so that we can get a large number of consecutive 0, which greatly simplifies the coding process.
Iv. Two-Dimensional DCT Inverse Transformation
At the receiver side of the image, based on the Reversible Changes of DCT, we can use DCT inverse transformation to restore the original image information. The formula is as follows:
In the same way, we can use the previous matrix computing companies to export the corresponding matrix form of DCT Inverse Transformation:
Next we use MATLAB to simulate this process:
1 clear; 2 clc; 3 x = [4 61 19 50 5 82 26 61 45 6 89 90 82 43 7 93 59 53 97] % raw data 8 A = zeros (4 ); 9 for I = for J = If I = 012 A = SQRT (1/4); 13 else14 A = SQRT (2/4); 15 end 16 A (I + 1, J + 1) = A * Cos (pI * (J + 0.5) * I/4 ); % generate transformation matrix 17 end18 end19 y = a * x * a' % DCT transformed matrix 20x1 = A' * y * A % dct reverse transformation restored Matrix
The running result is:
1 X = 2 3 61 19 50 20 4 82 26 61 45 5 89 90 82 43 6 93 59 53 97 7 8 9 Y =10 11 242.5000 32.1613 22.5000 33.221212 -61.8263 7.9246 -10.7344 30.688113 -16.5000 -14.7549 22.5000 -6.877014 8.8322 16.6881 -35.0610 -6.924615 16 17 X1 =18 19 61.0000 19.0000 50.0000 20.000020 82.0000 26.0000 61.0000 45.000021 89.0000 90.0000 82.0000 43.000022 93.0000 59.0000 53.0000 97.0000
We can see that the original information is restored lossless after the inverse transformation, so the correctness of the method is proved. However, in the actual process, it is necessary to quantify the code or directly discard the high-frequency components, so there will be a certain degree of error, which is inevitable.
V. Block DCT Transformation
In actual image processing, the complexity of DCT transformation is actually relatively high. Therefore, the common practice is to divide the image, and then perform DCT and reverse transformation on the image in each segment, merge parts to improve the transformation efficiency. As the sub-block grows, the complexity of the algorithm increases rapidly. However, when a large part is used, the image block effect is significantly reduced. Therefore, we need to make a compromise, generally, 8*8 blocks are used.
The blkproc function of MATLAB can help us easily process chunks. The following shows our processing process:
1 clear; 2 clc; 3 4 xforwarimread('pepper.bmp '); 5 x = double (x); 6 [a, B] = size (x); 7 y = blkproc (X, [8 8], 'dct2'); 8x1 = blkproc (Y, [8], 'idct2'); 9 10 figure11 subplot (1, 3, 1 ); 12 imshow (uint8 (x); 13 title ('original fig'); 14 15 subplot (1, 3, 2); 16 imshow (uint8 (y )); 17 title ('block DCT transform tues'); 18 19 subplot (, 3); 20 imshow (uint8 (X1); 21 title ('block DCT restoration tues '); 22 23 Y1 = dct2 (x); 24x10 = idct2 (Y1); 25 26 figure27 subplot (1, 3, 1); 28 imshow (uint8 (x )); 29 Title ('original'); 30 31 subplot (, 2); 32 imshow (uint8 (Y1); 33 title ('dct transform fig '); 34 35 subplot (, 3); 36 imshow (uint8 (x10); 37 title ('dct inverse transformation recovery ');
The running result is:
, We can see the difference between DCT transformation and Block DCT transformation in use.
Vi. Summary
DCT and DWT are the basic knowledge of image processing. They have been useful for the past, but they have not been well organized. Today, they are useful in Sparse Coding, I hope I can give some tips to later users.
My Sina Weibo: http://weibo.com/3109428257/profile? Rightmod = 1 & WVR = 5 & mod = personinfo
Reference: http://wuyuans.com/2012/11/dct2/
[DCT Notes] DCT transformation, DCT inverse transformation, and Block DCT Transformation