I have computed the discrete cosine transform (DCT) of an image in MATLAB. I got a matrix of discrete cosine transform coefficients in the workspace. How can I recover the original image from its discrete cosine transform coefficients in MATLAB?

  • Apparently you already have the knowledge of the DCT/IDCT function. Do you have a specific issue? Color image, integer calculations – Laurent Duval Feb 3 '17 at 7:12
up vote 0 down vote accepted

If you used dct2 on an image, or on each image channel separately for color images, with the appropriate input format, then idct2 recover the original image (the transformation is invertible and orthogonal), up to rounding errors (similar discussion in Why is $\exp(\ln(x))−x\neq 0$ in floating point arithmetic?).

You can find for instance a demo below:

dataRGB = double(imread('autumn.tif'));
data = rgb2gray(dataRGB/255);
dataDct=  dct2(data);
dataDctIdct = idct2(dataDct);

subplot(2,2,1)
imagesc(data); 
xlabel('Original (grayscale)');
subplot(2,2,2)
imagesc(log(abs(dataDct))); 
xlabel('Original DCT');
subplot(2,2,3)
imagesc(dataDctIdct); 
xlabel('Original recovered');
subplot(2,2,4)
imagesc(data-dataDctIdct); 
xlabel('Difference'); 
colorbar
colormap gray

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.