【发布时间】:2021-05-29 00:58:34
【问题描述】:
我使用 1D DCT 和 IDCT 实现了我自己的 2D DCT。我的 DCT 结果与 Matlab 的实现相匹配,但 IDCT 给出了不同的结果。从重建图像可以看出,差异并没有完全消失。
【问题讨论】:
标签: matlab image-processing dct
我使用 1D DCT 和 IDCT 实现了我自己的 2D DCT。我的 DCT 结果与 Matlab 的实现相匹配,但 IDCT 给出了不同的结果。从重建图像可以看出,差异并没有完全消失。
【问题讨论】:
标签: matlab image-processing dct
我对此有所了解 - 你的 DCT/IDCT 方程对我来说看起来不太正确。我使用了来自 SciPy 文档 here 的 DCT-2 和 DCT-3 公式。
original_img = imread('nggyu.jpeg');
transformed_img = permute(dct1d(permute( ...
dct1d(double(original_img)), ...
[2,1,3])), [2,1,3]);
recovered_img = uint8(permute(idct1d(permute( ...
idct1d(transformed_img), ...
[2,1,3])), [2,1,3]));
figure('position', [0, 0, 600, 200])
subplot(1,3,1), imshow(original_img), title 'Original'
subplot(1,3,2), imshow(log(abs(transformed_img)),[]), title 'DCT'
subplot(1,3,3), imshow(recovered_img), title 'IDCT'
function y = dct1d(x)
% Compute normalized DCT-2 over the first dimension of the input.
N = size(x, 1);
y = zeros(size(x));
n = (1:N)';
for k = 1:N
if k == 1
scale = sqrt(1/(4*N));
else
scale = sqrt(1/(2*N));
end
y(k,:,:) = scale * 2 * sum(x(n,:,:) .* cos((pi/(2*N)) * (2*n-1) * (k-1)), 1);
end
end
function x = idct1d(y)
% Compute normalized DCT-3 over the first dimension of the input.
N = size(y, 1);
x = zeros(size(y));
k = (2:N)';
for n = 1:N
x(n,:,:) = y(1,:,:)/sqrt(N) + sqrt(2/N) * sum(y(k,:,:) .* cos((pi/(2*N)) * (2*n-1) * (k-1)), 1);
end
end
【讨论】: