【发布时间】:2015-04-09 08:57:18
【问题描述】:
我使用 Matlab 中的一个函数来计算图像的 DCT(离散余弦变换)。我不知道我的代码中有什么不起作用,它用于图像压缩。请帮助我。 请有任何想法。
clc;close all;clear all;
image=('cameraman.tif');
[h w] = size(image);
image = double(image) - 128;
b=8;
block = zeros(b,b);
image_t=zeros(size(image));
for k=1:b:h
for l=1:b:w
image_t(k:k+b-1,l:l+b-1)= image(k:k+b-1,l:l+b-1);
for u=1:b
for v=1:b
if u == 0
Cu = 1/sqrt(2);
else
Cu = 1;
end
if v == 0
Cv = 1/sqrt(2);
else
Cv = 1;
end
Res_sum=0;
for x=1:b;
for y=1:b
Res_sum = Res_sum + ((image_t(x,y))*cos(((2*x)+1)*u*pi/(2*b))*cos(((2*y)+1)*v*pi/(2*b)));
end
end
dct= (1/4)*Cu*Cv*Res_sum;
block(u,v) = dct;
end
end
image_comp(k:k+b-1,l:l+b-1)=block(u,v);
end
end
end
【问题讨论】:
-
为什么它不起作用?
-
诚实评论...如果您希望其他人查看您的代码,请避免使用变量名称,例如 h、w、b、v、u、Cu、Cv。当你编写它时,它们可能看起来很简单,但老实说,当我面对一个新代码并看到这个时,我什至懒得去阅读它。
-
@gdasamu 我已经使用 DCT 公式实现了。
-
为什么不用matlab的
dct()函数呢? -
@articuno 我不能在我的程序中使用内置函数。
标签: matlab image-processing dct