function y = proj1b(l,m,b,d)
%This function takes a 256x256 image l and performs a DCT on it.  It
%then divdes the images into blocks of size bxc and allocates quantization
%bits according to the mask m.  If the image l cannot be split into blocks
%of size bxc then the function returns a null matrix.
%last updated 4-7-99

[r,c]=size(l);
sizer=r/b;
sizec=c/d;

if or(rem(r,b)~=0,rem(c,d)~=0)
  y=[];
else

% Shift image to be zero-centered
  l=l-(mean(mean(l)));

% Perform DCT and scaling (to range of -128 to 128 ) then round to int
  y = round( scale( dct2(l) ) );

%map=zeros(sizer,sizec);

% Output to file (doing quantiztion as we go)
fid = fopen('temp.bin','wb');
for i=1:sizer,
  for j=1:sizec,
    bwrite(fid, m(i,j), y(i*b-(b-1):i*b,j*d-(d-1):j*d));
  end
end
fclose(fid);
