% Image Compression code

% getting the original image
C8 = dct(eye(8));
Qy = [16 11 10 16 24  40  51  61; ...
      12 12 14 19 26  58  60  55; ...
      14 13 16 24 40  57  69  56; ...
      14 17 22 29 51  87  80  62; ...
      18 22 37 56 68  109 103 77; ...
      24 35 55 64 81  104 113 92; ...
      49 64 78 87 103 121 120 101;...
      72 92 95 98 112 100 103 99];
Xbig = imread('flower_pic.jpg');
Xbig = double(Xbig);


%cropping image
X_crop = Xbig(2:257,100:355,:);
image = X_crop;

%define rgb components separately
new_quantized_image = zeros(256,256,3);

p = 4;
Qy = p*Qy;
Q = p*8./hilb(8);
Qy = p*Qy;
%quantization steps

for i = 1:8:249
    for j = 1:8:249
      for k = 1:3
            new_image = image(i:i+7,j:j+7,k);

            % quantized 8x8 image
            quantized_image = Quantization(new_image,C8,Qy);
            
            % creates the 3 color layers individually
            if k == 1
                new_quantized_image(i:i+7,j:j+7,1) = quantized_image;
            
            elseif k == 2
                new_quantized_image(i:i+7,j:j+7,2) = quantized_image;
                
            else k == 3
                new_quantized_image(i:i+7,j:j+7,3) = quantized_image;
                
            end
      end
    end
end

%original image
figure(1)
image = uint8(image);
imagesc(image); 

%quantized image
figure(2)
new_quantized_image = uint8(new_quantized_image);
imagesc(new_quantized_image); 



    
