
%[rs, gs, bs] = jpgread('hingis2.jpg');
filename = 'medical.tif';
qfactor = 80;
levels = 3;

%[rs, gs, bs] = jpgread(filename);
theimage = imread(filename);
rsd = double(theimage(:, :, 1))/255;
%gsd = double(theimage(:, :, 2))/255;
%bsd = double(theimage(:, :, 3))/255;
clear theimage;
%[xs, smap] = rgb2ind(rsd, gsd, bsd, 256);
%figure(1); imshow(xs, smap);

%[rsd, gsd, bsd] = tiffread(filename);

[rpyr, rindices] = buildGpyr(rsd, levels);
%[gpyr, gindices] = buildGpyr(gsd, levels);
%[bpyr, bindices] = buildGpyr(bsd, levels);

for i=1:levels

  scale = 2^(i-1);
  
  rp = pyrBand(rpyr, rindices, i) / scale;
%  gp = pyrBand(gpyr, gindices, i) / scale;
%  bp = pyrBand(bpyr, bindices, i) / scale;

  save(sprintf('rp_%d', d), rp);

  %[xsp, smap] = rgb2ind(rp, gp, bp, 256);
  %figure(i);
  %imshow(xsp, smap);
  % title(sprintf('Level %d', i));
  
  %tif(:, :, 1) = rp;
  %tif(:, :, 2) = gp;
  %tif(:, :, 3) = bp;
  
  %jpgwrite(sprintf('%s_%d', filename, i), rp, gp, bp, qfactor);
  %imwrite(sprintf('%s_%d', filename, i), rp, gp, bp, 
  %tiffwrite(rp, gp, bp, sprintf('%s_%d', filename, i));
end

