clear;




%% Test image instantiations - First row
imCand = [1:21]%[1, 5, 6, 7, 8, 9, 10, 27, 33, 39, 42, 45, 51, 52, 53, 61, 64, 65,  68, 69, 70];

blurNo = 6;
noiseNo = 10;

if(blurNo == 2)
%     imCand = [12, 20];%[45,69] %[12, 20]
%     imOut= [ 12, 20]
    fileName = 'CVPR10-AdaptivePrior_deblur.html';
else
    if(noiseNo == 5)
%         imCand = [16]%[61,64] %[16, 17]
%         imOut = [16, 17]
        fileName = 'CVPR10-AdaptivePrior_denoise_small.html';
    else
%         imCand = [11, 14]%[42, 52] %[11, 14]
%         imOut = [ 11, 14];
        fileName = 'CVPR10-AdaptivePrior_denoise_large.html';
    end
end

fid = fopen(fileName, 'w');

%% Header definition
fprintf(fid, '%s\n', '<html><head><title>Adaptive Prior - Examples</title></head><body>');


resultPath = 'Results_AdaptivePrior/';

for imNo = 1:length(imCand)

    'Loading data'
    fidText = fopen(sprintf('%s%s%s%s%s', '../', resultPath, num2str(imNo), '/measDataAll_', num2str(imCand(imNo)), '_', ...
        num2str(blurNo), '_', num2str(noiseNo), '.txt'), 'r');
    tline = fgetl(fidText);
    PSNRSparse = tline;
    tline = fgetl(fidText);
    PSNRSteer = tline;
    tline = fgetl(fidText);
    PSNRAdapt = tline;
    tline = fgetl(fidText);
    tline = fgetl(fidText);
    tline = fgetl(fidText);
    SSIMSparse = tline;
    tline = fgetl(fidText);
    SSIMSteer = tline;
    tline = fgetl(fidText);
    SSIMAdapt = tline;
    fclose(fidText); 
    
    
    fprintf(fid, '%s%s%s\n%s\n%s\n%s\n%s\n', '<h2>Test image', num2str(imNo), '</h2>', '<table border=0>', ...
        '<tr align=center valign=middle>', '<td>');
    
     
     %% Mouse over

    fprintf(fid, '%s\n', 'Mouse over the following links to flip between images<br>');
    fprintf(fid, '%s\n', 'By default, our result is shown<br>');
    % Steerable random fields image
    fprintf(fid, '%s\n%s%s%s%s%s%s%s%s%s%s%s%s\n', '<a href="#"', 'onmouseover="document.i', num2str(imNo), '.src= ''', resultPath, ...
        num2str(imCand(imNo)), '/sparseDeconv_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"');

    fprintf(fid, '%s%s%s%s%s%s%s%s%s%s%s%s\n', 'onmouseout="document.i', num2str(imNo), '.src= ''', resultPath, num2str(imCand(imNo)), '/adaptDeconv_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"> Deconvolved with the steerable random fields, PSNR : ', num2str(PSNRSteer), ', SSIM : ', num2str(SSIMSteer), '</a><br>');
    
    
    % sparse deconvolution image
    fprintf(fid, '%s\n%s%s%s%s%s%s%s%s%s%s%s%s\n', '<a href="#"', 'onmouseover="document.i', num2str(imNo), '.src= ''', resultPath, ...
        num2str(imCand(imNo)), '/sparseDeconvAnat_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"');

    fprintf(fid, '%s%s%s%s%s%s%s%s%s%s%s%s\n', 'onmouseout="document.i', num2str(imNo), '.src= ''', resultPath, num2str(imCand(imNo)), '/adaptDeconv_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"> Deconvolved with the unsteered gradient prior, PSNR : ', num2str(PSNRSparse), ', SSIM : ', num2str(SSIMSparse), '</a><br>');
    
    % degraded image
    fprintf(fid, '%s\n%s%s%s%s%s%s%s%s%s%s%s%s\n', '<a href="#"', 'onmouseover="document.i', num2str(imNo), '.src= ''', resultPath, ...
        num2str(imCand(imNo)), '/imBlur_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"');

    fprintf(fid, '%s%s%s%s%s%s%s%s%s%s%s%s\n', 'onmouseout="document.i', num2str(imNo), '.src= ''', resultPath, num2str(imCand(imNo)), '/adaptDeconv_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"> Degraded image</a><br>');
    
    % Original image
    fprintf(fid, '%s\n%s%s%s%s%s%s%s%s%s%s%s%s\n', '<a href="#"', 'onmouseover="document.i', num2str(imNo), '.src= ''', resultPath, ...
        num2str(imCand(imNo)), '/orig_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"');

    fprintf(fid, '%s%s%s%s%s%s%s%s%s%s%s%s\n', 'onmouseout="document.i', num2str(imNo), '.src= ''', resultPath, num2str(imCand(imNo)), '/adaptDeconv_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"> Original image</a><br>');
    

    % adaptive deconvolution image
    fprintf(fid, '%s%s%s%s%s%s%s', '<img src=', resultPath, num2str(imCand(imNo)), '/adaptDeconv_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp width = "750" name=i', num2str(imNo), '>');
    fprintf(fid, '%s\n%s\n', '</td>');
   
% 
%     % steerable deconvolution image
%     fprintf(fid, '%s%s%s%s%s%s', '<img src=', resultPath, num2str(imCand(imNo)), '/sparseDeconv_', num2str(imCand(imNo)), ...
%         '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp width = "450">');
%     fprintf(fid, '%s\n%s\n', '</td>', '<td>');
% 
%     % sparse deconvolution image
%     fprintf(fid, '%s%s%s%s%s%s', '<img src=', resultPath, num2str(imCand(imNo)), '/sparseDeconvAnat_', num2str(imCand(imNo)), ...
%         '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp width = "450">');
%     fprintf(fid, '%s\n%s\n', '</td>', '<td>');
% 
% 
%     % Original  image
%     fprintf(fid, '%s%s%s%s%s%s', '<img src=', resultPath, num2str(imCand(imNo)), '/orig_', num2str(imCand(imNo)), ...
%         '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp width = "450">');
     fprintf(fid, '%s\n%s\n%s\n%s\n', '</tr>', '<tr align = center>');
    
    
    % labeling
    fprintf(fid, '%s\n%s%s%s%s\n%s\n%s\n', '<td>', '<h3>Ours PSNR : ', num2str(PSNRAdapt), ', SSIM : ', num2str(SSIMAdapt), '</h3> </td>');
%     fprintf(fid, '%s\n%s%s%s%s\n%s\n%s\n', '<td>', '<h3>Steerable random fields </h3> PSNR : ', num2str(PSNRSteer), ', SSIM : ', num2str(SSIMSteer), '</td>');
%     fprintf(fid, '%s\n%s%s%s%s\n%s\n%s\n', '<td>', '<h3>Sparse deconvolution </h3> PSNR : ', num2str(PSNRSparse), ', SSIM : ', num2str(SSIMSparse), '</td>');
%     fprintf(fid, '%s\n%s\n%s\n%s\n%s\n', '<td>', '<h3>Original image</h3>', '</td><br><br><br>');
    
    fprintf(fid, '%s\n%s\n%s\n%s\n', '</td>', '</tr>'); 

    fprintf(fid, '%s\n%s\n%s\n%s\n%s\n', '<tr align=center valign=middle>', '<td>');

    %% Mouse over

    fprintf(fid, '%s\n', 'Mouse over the following links to flip between images<br>');
    fprintf(fid, '%s\n', 'By default, our result is shown<br>');
    % Steerable random fields image
    fprintf(fid, '%s\n%s%s%s%s%s%s%s%s%s%s%s%s\n', '<a href="#"', 'onmouseover="document.i', num2str(imNo), '.src= ''', resultPath, ...
        num2str(imCand(imNo)), '/sparseDeconv_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"');

    fprintf(fid, '%s%s%s%s%s%s%s%s%s%s%s%s\n', 'onmouseout="document.i', num2str(imNo), '.src= ''', resultPath, num2str(imCand(imNo)), '/adaptDeconv_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"> Deconvolved with the steerable random fields, PSNR : ', num2str(PSNRSteer), ', SSIM : ', num2str(SSIMSteer), '</a><br>');
    
    
    % sparse deconvolution image
    fprintf(fid, '%s\n%s%s%s%s%s%s%s%s%s%s%s%s\n', '<a href="#"', 'onmouseover="document.i', num2str(imNo), '.src= ''', resultPath, ...
        num2str(imCand(imNo)), '/sparseDeconvAnat_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"');

    fprintf(fid, '%s%s%s%s%s%s%s%s%s%s%s%s\n', 'onmouseout="document.i', num2str(imNo), '.src= ''', resultPath, num2str(imCand(imNo)), '/adaptDeconv_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"> Deconvolved with the unsteered gradient prior, PSNR : ', num2str(PSNRSparse), ', SSIM : ', num2str(SSIMSparse), '</a><br>');
    
    % degraded image
    fprintf(fid, '%s\n%s%s%s%s%s%s%s%s%s%s%s%s\n', '<a href="#"', 'onmouseover="document.i', num2str(imNo), '.src= ''', resultPath, ...
        num2str(imCand(imNo)), '/imBlur_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"');
    
    fprintf(fid, '%s%s%s%s%s%s%s%s%s%s%s%s\n', 'onmouseout="document.i', num2str(imNo), '.src= ''', resultPath, num2str(imCand(imNo)), '/adaptDeconv_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"> Degraded image</a><br>');
    
    % Original image
    fprintf(fid, '%s\n%s%s%s%s%s%s%s%s%s%s%s%s\n', '<a href="#"', 'onmouseover="document.i', num2str(imNo), '.src= ''', resultPath, ...
        num2str(imCand(imNo)), '/orig_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"');

    fprintf(fid, '%s%s%s%s%s%s%s%s%s%s%s%s\n', 'onmouseout="document.i', num2str(imNo), '.src= ''', resultPath, num2str(imCand(imNo)), '/adaptDeconv_', num2str(imCand(imNo)), ...
        '_', num2str(blurNo), '_', num2str(noiseNo), '.bmp''"> Original image</a><br>');

    fprintf(fid, '%s\n%s\n%s\n', '</tr></table><br>', '<br>', '<br>');
    
end
fclose(fid); 
     