Recovering an image using IDCT through DCT coefficients

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

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);

subplot(2,2,1)
imagesc(data);
xlabel('Original (grayscale)');
subplot(2,2,2)