% Issac D. Gerg / Pushkar U. Durve
% CSE 485 - Digital Image Processing I 
% Project 0 
% Group Number # 4
% Effects of Spatial Resolution Changes and Quantization on Gray Level Images 

file = 'lenna.gif';

picture_lenna = imread(file);

% Resizing lenna.gif to 512 x 512.
% Using Nearest Interpolation - Which is function default 
picture_lenna_scale = imresize(picture_lenna, [512 512], 'nearest');
imwrite(picture_lenna_scale, 'gerg_durve.jpg', 'jpg');  


% Experiment with COLORMAP function
image(picture_lenna_scale);
colormap(gray);

% "For Any Gray Level Images in the following database" assume we can pick any image.  
% Image taken from http://www.cse.psu.edu/~cg485/images/ 
% File used is 'lenna.gif'

% Effects of Spatial Resolution Changes

picture_lenna_scale_128 = imresize(picture_lenna, [128 128], 'nearest');
picture_lenna_scale_64 = imresize(picture_lenna, [64 64], 'nearest');
picture_lenna_scale_32 = imresize(picture_lenna, [32 32], 'nearest');

picture_lenna_scale_128_256 = imresize(picture_lenna_scale_128, [256 256], 'nearest');
picture_lenna_scale_64_256 = imresize(picture_lenna_scale_64, [256 256], 'nearest');
picture_lenna_scale_32_256 = imresize(picture_lenna_scale_32, [256 256], 'nearest');

imwrite(picture_lenna_scale_128_256, 'gerg_durve_128.jpg', 'jpg');  
imwrite(picture_lenna_scale_64_256, 'gerg_durve_64.jpg', 'jpg');  
imwrite(picture_lenna_scale_32_256, 'gerg_durve_32.jpg', 'jpg');  

% Effects of Quantization

[picture_lenna_8_index,map] = gray2ind(picture_lenna,256); 
picture_lenna_8 = ind2gray(picture_lenna_8_index,map);
imwrite(picture_lenna_8, 'lenna_8.jpg', 'jpg');

[picture_lenna_6_index,map] = gray2ind(picture_lenna,64); 
picture_lenna_6 = ind2gray(picture_lenna_6_index,map);
imwrite(picture_lenna_6, 'lenna_6.jpg', 'jpg');

[picture_lenna_4_index,map] = gray2ind(picture_lenna,16); 
picture_lenna_4 = ind2gray(picture_lenna_4_index,map);
imwrite(picture_lenna_4, 'lenna_4.jpg', 'jpg');

[picture_lenna_2_index,map] = gray2ind(picture_lenna,4); 
picture_lenna_2 = ind2gray(picture_lenna_2_index,map);
imwrite(picture_lenna_2, 'lenna_2.jpg', 'jpg');

[picture_lenna_1_index,map] = gray2ind(picture_lenna,2); 
picture_lenna_1 = ind2gray(picture_lenna_1_index,map);
imwrite(picture_lenna_1, 'lenna_1.jpg', 'jpg');