% qim = quantData(im, codeword);
% 
% quantizes data using given codeword
%
% J. Sabataitis
% Oct. 20, 2000
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function qim = quantData(im, codeword);

err = zeros(size(im,1),size(im,2),length(codeword));

for n = 1:length(codeword),
  err(:,:,n) = (im-codeword(n)).^2;
end


for y = 1:size(im,1),
  for x = 1:size(im,2),
    ind = find(err(y,x,:) == min(err(y,x,:))); 
    qim(y,x) = codeword(ind(1));
  end
end
