0
我想使用DCT矩陣U將2D離散餘弦變換應用於生成的8x8像素白色圖像,然後恢復並繪製圖像。使用imagesc()的範圍錯誤
計算矩陣U的:
N = 8;
k = 0:N-1;
u = 0:N-1;
U = cos(u'*pi*(k+0.5)/N)*sqrt(2/N);
U (1,1:N) = U(1,1:N)/sqrt(2);
圖像X:
X = ones(8, 8, 3, 'double');
DCT 2D變換圖像X的:
Y(:,:,1) = U*X(:,:,1)*U';
Y(:,:,2) = U*X(:,:,2)*U';
Y(:,:,3) = U*X(:,:,3)*U';
恢復的圖像:
Xr(:,:,1) = U'*Y(:,:,1)*U;
Xr(:,:,2) = U'*Y(:,:,2)*U;
Xr(:,:,3) = U'*Y(:,:,3)*U;
現在,當我嘗試做:
figure;
subplot(2, 1, 1);
imagesc(X);
axis off;
title('Original image');
subplot(2, 1, 2);
imagesc(Xr);
axis off;
title('Recovered image');
我收到以下錯誤:
Error using image
TrueColor CData contains element out of range 0.0 <= value <= 1.0
Error in imagesc (line 18)
hh = image(varargin{1},'CDataMapping','scaled');
Error in Ejercicio1_3 (line 32)
imagesc(Xr);
和矩陣的值XR是:爲什麼我
Xr(:,:,1) =
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
Xr(:,:,2) =
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
Xr(:,:,3) =
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
當所有的值都在正確的範圍內時得到這個錯誤? (0.0,1.0)
您的代碼在'Y = U * X * U'上失敗;''爲'X'是一個3D矩陣 –
謝謝@ nirvana-msu,我已經修復了這篇文章。 – Kroka
你能告訴我們'fprintf(「%。17g \ n」,max(Xr(:)))'的結果是什麼嗎? – beaker