function Q=quant(bits);

L=freadbin('lenna.256', 256, 256, 'uchar');

imagesize=256;
imagelevels=256;

Li=zeros(imagesize);

levels=2^bits;
stepsize=imagelevels/levels;

for i = 1:levels
   li=find((L>=(i-1)*stepsize)&(L<i*stepsize));
   Li(li)=i*stepsize-1;
end

figure
imagesc(Li);
colormap(gray);

Q=Li;
