本文主要是介绍DCT 变换(几个简单的MATLAB的例子),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原文地址:http://hi.baidu.com/huguosheng/item/06393d5744ee9f3795eb05f2
example 1(use real image):
A=imread('class_f.png');imshow(A) %A is unit8(0,255)
C=dct2(A); %进行余弦变换
figure;
B=log(abs(C));
imshow(B)
colormap(jet(64)); %显示为64级灰度
colorbar; %显示颜色条,显示变换后的系数分布
C(abs(C)<10)=0; %将DCT变换后的系数值小于10的元素设为0
%E=idct2(C);
D=idct2(C)./255; %对DCT变换值归一化,进行余弦反变换???
figure;
imshow(D) ;
% imshow(uint8(E)); is the same as D=idct2(C)./255
% imshow(E,[]); is the same as D=idct2(C)./255
FF=abs(C)<10; %Compute the number of elements which are smaller than 10
sum(sum(FF)) %result:56632
GG=abs(C)>10; %Compute the number of elements which are larger than 10
sum(sum(GG)) %result:16025
example 2(use artifical image):
constant Image(low frequency image)
A=ones(5);
B=dct2(A)
A =
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
after DCT transformation
5 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
C=idct2(B) %reconstruction according to B
random image(high frequency image)
A=randn(5)
B=dct2(A)
A =
-0.4326 1.1909 -0.1867 0.1139 0.2944
-1.6656 1.1892 0.7258 1.0668 -1.3362
0.1253 -0.0376 -0.5883 0.0593 0.7143
0.2877 0.3273 2.1832 -0.0956 1.6236
-1.1465 0.1746 -0.1364 -0.8323 -0.6918
ans =
0.5853 -0.5033 -1.3505 -1.2524 -0.3519
0.2492 0.1007 -0.4273 0.1201 -1.5079
-0.8317 0.4357 -0.4183 -0.5794 -0.4022
1.7697 -0.3482 1.3882 -0.3871 1.4934
-1.0525 0.1744 1.7976 0.0521 -0.4997
B(abs(B)<0.1)=0;//0.1 is threshold
C=idct2(B);//reconstruction
这篇关于DCT 变换(几个简单的MATLAB的例子)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!