當前位置:成語大全網 - 新華字典 - matlab 圖像dct變換

matlab 圖像dct變換

[A,map]=imread('******');

%顯示原圖

imshow(A,map),

title('原圖');

image=double(A);

N=8;

for x=1,

a(x)=sqrt(1/N);

end,

for x=2:8,

a(x)=sqrt(2/N);

end,

%dct

rimage=zeros(8,8);

for x=1:32,

for y=1:32,

for u=1:N,

for v=1:N,

for i=1:N,

for j=1:N,

rimage(i,j)=image(i+(x-1)*8,j+(y-1)*8);

b(i,j)=rimage(i,j).*cos((2*(i-1)+1)*(u-1)*pi/(2*N)).*cos((2*(j-1)+1)*(v-1)*pi/(2*N));

end,

end,

d(u,v)=sum(sum(b,1),2);

C(u,v)=a(u).*a(v).*d(u,v);

end,

end,

xhimage{x,y}=C;

end,

end,

aa=zeros(8,8);

b1=zeros(256,256);

for x=1:32,

for y=1:32,

aa=xhimage{x,y};

for i=1:8,

for j=1:8,

b1(i+(x-1)*8,j+(y-1)*8)=aa(i,j);

end,

end,

end,

end,

figure,imshow(uint8(b1));title('DCT');