% load the images from the AT&T-faces dataset
dataset_loc = 'C:\Users\Akshay\Desktop\Compressed Sensing\datasets';
all_image_files = dir(fullfile(dataset_loc, 'att_faces', '**', '*.pgm'));
att_faces = cell(length(all_image_files), 1);
for i = 1:length(att_faces)
att_faces{i,1} = imread(fullfile(all_image_files(i).folder, all_image_files(i).name));
imshow(img, 'InitialMagnification', 250)
h_w_range = [19 19 59 79];
crop_img = imcrop(img, h_w_range); % size of cropped image [80 60]
imshow(crop_img, 'InitialMagnification', 250)
resize_img = imresize(crop_img, [64, 64]);
imshow(resize_img, 'InitialMagnification', 250);
%% Sparsity comparison between the two domains
% Find the DCT and equate low-magnitude
% coefficients to zero and check the reconstruction quality
h1 = histogram(x, 60, 'Normalization', 'probability', ...
'FaceAlpha', 0.6, 'FaceColor', [0.2 0.6 0.9]);
legend({'Standard basis'},'Location','best');
h2 = histogram(s, 60, 'Normalization', 'probability', ...
'FaceAlpha', 0.6, 'FaceColor', [0.9 0.4 0.2]);
legend({'DCT basis'},'Location','best');
% We need a basis for representing our images of size (64 x 64),
% already sparse in the DCT domain, needs a representation of the
% form x = \Phi s where s is a sparse vector and x is the image
% stretched to make a single column (note the major order of transforming
% the image matrix into a vector.
row_dctmtx = dctmtx(rows);
col_dctmtx = dctmtx(cols);
Phi = kron(col_dctmtx, row_dctmtx);
NUM_SAMPLES = [500, 1000, 1500, 2000, 2500, 3000];
for i = 1:length(NUM_SAMPLES)
SAMPLES = randi(IMG_SIZE, [NUM_SAMPLES(i), 1]);
sprintf("============%d============", i)
minimize( norm(s_l1, 1) );
K_l1_recon = uint8(reshape(x_l1_recon, [rows, cols]));
P_SNRS_DCT = [P_SNRS_DCT psnr(K_l1_recon, K)];
SSIMS_DCT = [SSIMS_DCT multissim(K_l1_recon, K)];
end
ans = "============1============"
ans = "============2============"
ans = "============3============"
ans = "============4============"
ans = "============5============"
ans = "============6============"
NUM_SAMPLES = [500, 1000, 1500, 2000, 2500, 3000];
for i = 1:length(NUM_SAMPLES)
SAMPLES = randi(IMG_SIZE, [NUM_SAMPLES(i), 1]);
sprintf("============%d============", i)
minimize( norm(s_l1, 1) );
K_l1_recon = uint8(reshape(x_l1_recon, [rows, cols]));
P_SNRS_SVD = [P_SNRS_SVD psnr(K_l1_recon, K)];
SSIMS_SVD = [SSIMS_SVD multissim(K_l1_recon, K)];
end
ans = "============1============"
ans = "============2============"
ans = "============3============"
ans = "============4============"
ans = "============5============"
ans = "============6============"
% Plot of the SSIM for DCT based vs SVD vased reconstructions
plot(NUM_SAMPLES, SSIMS_DCT, 'r-o', 'LineWidth', 1.5); % Red line with circles
plot(NUM_SAMPLES, SSIMS_SVD, 'b-s', 'LineWidth', 1.5); % Blue line with squares
xlabel('Number of samples in observation');
title('Variation of SSIM with observation size');
legend('DCT', 'SVD', 'Location', 'best');
% Plot of the PSNRs for DCT based vs SVD vased reconstructions
plot(NUM_SAMPLES, P_SNRS_DCT, 'r-o', 'LineWidth', 1.5); % Red line with circles
plot(NUM_SAMPLES, P_SNRS_SVD, 'b-s', 'LineWidth', 1.5); % Blue line with squares
xlabel('Number of samples in observation');
title('Variation of Peak-SNR with observation size');
legend('DCT', 'SVD', 'Location', 'best');
% A side-by-side comparison of the image reconstructed from 3000
% samples and the original cropped image from the AT&T dataset
% by using the SVD bases made from a different dataset, the Yale-Faces dataset.
montage({K_l1_recon, K});