function output = dft_block(input,blocksize);

% function output = dft_block3(input,blocksize);
%
% DFT_BLOCK  --  Applies the DFT to blocks of an input image and returns 
%                a set of band images in a 3-dimensional matrix.
%
% Input Parameters:
%  input     -- The image to encode
%  blocksize -- Blocks are 1 row x "blocksize" columns. (Optional: Default is 8)
%
% Output Parameters:
%  output    -- A 3-D matrix of band images.  See Lab #5 handout for more details.
%

% Written by Mark Bartsch and David Neuhoff, Fall 2002
% Modification History:
%    8/16/02  --  Added modification history (MB)


if ~exist('blocksize','var') | isempty(blocksize)
    blocksize = 8;
end

sz = size(input);

% Reshape the input into a three dimensional matrix
output = input;
output = reshape(output,[sz(1),blocksize,sz(2)/blocksize]);
output = permute(output,[1 3 2]);

% Compute the fft along the 3rd dimension
output = fft(output,[],3)/blocksize;

% Extract and collect the desired components 
output(:,:,(blocksize/2+2:blocksize)) = sqrt(2) * imag(output(:,:,2:(blocksize/2)));
output(:,:,2:blocksize/2) = sqrt(2) * real(output(:,:,2:blocksize/2));
