%% Image Resizing
% Load a file that contains depth measurements of a mold used to mint a United States penny. The data, taken at the National Institute of Standards and Technology, are sampled on a 128-by-128 grid. Display the data.

load penny

surf(P)
view(2)
colormap copper
shading interp
axis ij square off

%
% Compute the discrete cosine transform of the image data using the DCT-1 variant. Operate first along the rows and then along the columns.

Q = dct(P,[],1,'Type',1);
R = dct(Q,[],2,'Type',1);

%
% Invert the transform. Truncate the inverse so that each dimension of the reconstructed image is one-half the length of the original.

S = idct(R,size(P,2)/2,2,'Type',1);
T = idct(S,size(P,1)/2,1,'Type',1);

%
% Invert the transform again. Zero-pad the inverse so that each dimension of the reconstructed image is twice the length of the original.

U = idct(R,size(P,2)*2,2,'Type',1);
V = idct(U,size(P,1)*2,1,'Type',1);

%
% Display the original and reconstructed images.

surf(V)
view(2)
shading interp
hold on

surf(P)
view(2)
shading interp

surf(T)
view(2)
shading interp
hold off
axis ij equal off

% Copyright 2012 The MathWorks, Inc.