% This codes illustrates how dataset in [Boracchi & Foi 2012] is organized
%
%Here is the structure description:
%
% img{f}(s).z: s-th observation (blurred and noisy image) from f-th movie
% img{f}(1).gt: the ground truth acquired when the movie was paused. Only the first element of the array contains a non-empty gt field;
% img{f}(s).psf.estimate: PSF estimated from the s-th observation exploiting the continuous trajectory generating the motion in the f-th movie
% img{f}(s).psf.sigmaL: psf descriptor of the s-th observation
% img{f}(s).psf.sigmaS: other psf descriptor of the s-th observation
% img{f}(1).psf.TrajStatistics: trajectory information. The trajectory is described by the complex array
% img{f}(1).psf.TrajStatistics.x. These trajectories have been generated from the PFS Generation Framework available
%                                                   online at home.dei.polimi.it/boracchi/software
% img{f}(1).psf.TrajStatistics.trajID character identifying the PSF in Fig 7 in  [Boracchi & Foi 2012] (a corresponds to rectilinear blur)
% img{f}(s).EXIF.T: exposure time used when the s-th observation has been acquired
% img{f}(s).EXIF.ISO: ISO parameter used when the s-th observation has been acquired.
% img{f}(s).EXIF.ColorChannel: color channel of the Bayer Pattern
% img{f}(s).EXIF.filename: additional information in here
% img{f}(s).noiseParams.a: estimate of the noise parameter a as in [Foi et al., 2008]
% img{f}(s).noiseParams.b: estimate of the noise parameter b as in [Foi et al., 2008]
%
% Please cite this dataset as [Boracchi & Foi 2012]  
%
%
% REFERENCES
%
% [Boracchi & Foi 2012]  Modeling the Performance of Image Restoration from Motion Blur
% Giacomo Boracchi and Alessandro Foi, Image Processing, IEEE Transactions on. vol.21, no.8, pp. 3502 - 3517, Aug. 2012, doi:10.1109/TIP.2012.2192126
% Preprint available at http://home.dei.polimi.it/boracchi/publications.html
% 
%[Foi et al., 2008]  [Foi et al., 2008] Practical Poissonian-Gaussian noise modeling and fitting for single image raw-data 
% A. Foi, M. Trimeche, V. Katkovnik, and K. Egiazarian, Image Processing, IEEE Transactions on. vol. 17, no. 10, pp. 1737-1754, October 2008. doi:10.1109/TIP.2008.2001399 
%
%
% Giacomo Boracchi
% December 2012
% Politecnico di Milano
%
% giacomo.boracchi@polimi.it

close all
clear
clc

fileName = 'rawData/balloons.mat';

load(fileName);

%%
nMovies = numel(img);
disp(['this dataset contains images acquired from ' , num2str(nMovies) , ' scenarios (i.e. movies played on the screen)']);

for ff = 1 : nMovies
    nShots = numel(img{ff});
    disp(['We acquired ' , num2str(nShots) , ' images from psf: ' , img{ff}(1).psf.TrajStatistics.trajID]);
    
    for ss = 1 : nShots
        
        titleStr = ['T = ' , num2str(img{ff}(ss).EXIF.T) , ' ISO: ', num2str(img{ff}(ss).EXIF.ISO) , ' color = ' , num2str( img{ff}(ss).EXIF.ColorChannel) ];
        disp([titleStr , ' img : ' , num2str(ss) , ' / ' , num2str(nShots)])
        
        % the first shot contains also the GT in the corresponding field
        if ss == 1
            figure(1), imshow(img{ff}(ss).gt , []), title(['ground truth'])
        end
        
        % gt
        figure(2), imshow(img{ff}(ss).z , []), title(['observation: ' , titleStr])
        
        % psf estimate
        figure(3), imshow(img{ff}(ss).psf.estimate , []), title(['PSF estimate \varsigma_L = ', num2str(img{ff}(ss).psf.sigmaL) , '  \varsigma_S = ', num2str(img{ff}(ss).psf.sigmaS)])
      
        disp('hit a key...')
        pause();
    end
end