% Main function to generate CS measurements 
% and reconstruct image using TV method and MARX method
% For any questions, please contact
% Xiangjun Zhang at:
% zhangxj@grads.ece.mcmaster.ca

clear all

% Inputs
img = double(imread('./Images/Vessels.tif'));  %input image
[height, width] = size(img);
N = prod(size(img));       %number of total pixels
num = round(N*0.2);     %number of measurements
seed_val = 0;       %seed value of random generators

%----------
% Generate measurements. 
% The name of input filename and variables can NOT change
save GetM_Input img num seed_val   
system('GetCSMeasurements.exe');
%----------

%----------
% Reconstruction
load measurements
% The name of input filename and variables can NOT change
save MARX_Input y width height nor_s mea_s seed_val
system('MARX_CS.exe');

% Output results
load rec_img
psnr = zeros(1,2);
psnr(1) = psnrfun(img, TV_im, 0);
psnr(2) = psnrfun(img, MARX_im, 0);
disp(psnr)
imwrite(uint8(TV_im), './Results/Vessels_TV.tif', 'compression', 'none');
imwrite(uint8(MARX_im), './Results/Vessels_MARX.tif', 'compression', 'none');
Write2TXT( './Results/PSNR_Vessels.txt',  'PSNR_TV    PSNR_MARX', psnr );
