Technobabble. You probably want to ignore this.
Matlab doesn't know how to subtract uint8 integers. It probably doesn't know how to do anything with uint8 numbers.
imread() returns a 2d array of uint8s.
dct2() and idct2() both return double 2d arrays, instead of uint8s. They work on uint8s though. Confusing.
I=imread(filename);
imshow(I)
J=dct2(I); -- compute the discrete cosine transform of I
imshow(log(abs(J))); -- display it with logarithm scale
K=J(abs(J) < THRESHOLD) = 0; -- threshold, essentially a compression amount
L=idct2(K)/255; -- inverse dct
imshow(L); -- show the result
M=double(I) - L*255; -- calculate the difference between the images
imshow(M); -- and then show it.