📄 yxdct.m
字号:
%*********************************************************
% 1, 输入Lena的黑白图像,进行DCT变换,并显示变换后的Lena图像
%**********************************************************
function YXDCT()
f=imread('Lena.bmp');
%figure,imshow(f);
%title '原始的Lena图像';
[wideth,height]=size(f);
y=zeros(wideth,height);
uu=zeros(wideth,height);
for i=1:wideth
for j=1:height
y(i,j)=f(i,j);
end;
end;
%****************************************
%******** 进行行的DCT变换 ****************
%%***********************************
temp=zeros(1,height);
for i=1:wideth
for j=1:height
temp(j)=y(i,j);
end;
temp=Y1DCT(temp,height);
for j=1:height
y(i,j)=temp(j);
end;
end;
%**********************************************
%************* 进行列的DCT变换 %****************
%************************************
temp=zeros(1,height);
for j=1:height
for i=1:wideth
temp(i)=y(i,j);
end;
temp=Y1DCT(temp,wideth);
for i=1:wideth
y(i,j)=temp(i);
end;
end;
%**************************************************************
%*****************进行反DCT变换
uu=zeros(wideth,height);
uu=fandct(y);
%******************调整后的反DCT变换
tt=zeros(wideth,height);
for i=1:wideth
for j=1:height
if i<=100&j<=100
tt(i,j)=y(i,j);
else
tt(i,j)=0;
end
end
end
tt=fandct(tt);
% %**************************************************************
% %****************************************
% %******** 进行行的反DCT变换 ****************
% %%***********************************
% temp1=zeros(1,height);
% for i=1:wideth
% for j=1:height
% temp1(j)=y(i,j);
% end;
% temp1=iyDCT(temp1,height);
% for j=1:height
% uu(i,j)=temp1(j);
% end;
% end;
% %**********************************************
% %************* 进行列的反DCT变换 %****************
% %************************************
% temp2=zeros(1,height);
% for j=1:height
% for i=1:wideth
% temp2(i)=uu(i,j);
% end;
% temp2=iyDCT(temp2,wideth);
% for i=1:wideth
% uu(i,j)=temp2(i);
% end;
% end;
%*************************将进行完DCT变换后的数值求其模,进行实数的转换
%**************************************************************************
y1=zeros(wideth,height);
for i=1:1:wideth
for j=1:1:height
y1(i,j)=uint8(sqrt(y(i,j)^2));
if y1(i,j)>255
y1(i,j)=255;
end;
end;
end;
%****************************************************
%******** 调整图像的显示的中心 *******************
%***************************************************
% for i=1:1:wideth
% for j=1:1:height
% if(i>wideth/2)
% i1=i-wideth/2;
% else
% i1=i+wideth/2;
% end
% if(j>height/2)
% j1=j-height/2;
% else
% j1=j+height/2;
% end
% y1(i1,j1)=uint8(y(i,j));
% end
% end
%***********************************************
%调整DCT系数
% tt=zeros(wideth,height);
% for i=1:wideth
% for j=1:height
% if i<=100&j<=100
% y(i,j)=y(i,j);
% else
% y(i,j)=0;
% end
% end
% end
% tt=fandct(y);
%*************************************************
%********** 显示变换后的DCT和反DCT的图像
%**********************************************
figure,imshow(uint8(y1));
title 'DCT变换后的Lena图像';
figure,imshow(uint8(uu));
title 'DCT反变换后的Lena图像';
figure,imshow(uint8(tt));
title '调整后的的Lena图像';
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -