r_recon.m 4.4 KB
function r_recon(expNumber,camNumber,rowNumber,nb,filter)
% R_RECON - Run R_ISOLATE in batch mode
%
% Syntax:  data = r_recon(expNumber,camNumber,rowNumber,nb,filter)
%
% Inputs:
%    expNumber - The experiment identifier
%    camNumber - The camera number
%    rowNumber - The row number (from 1 to 4 starting from the left)
%    nb        - Number of objects to be identified
%    filter    - String specifying which color filters to use
%                'r': red
%                'g': green
%                'b': blue
%                'y': yellow
%
% Example:
%    r_recon(201307231525,1,4,5,'rgby');
%
% Other m-files required: Image Processing Toolbox
% Subfunctions: none
% MAT-files required: none
%
% See also: R_ISOLATE, R_SHOW, R_MOVIE

% Author: Yannick Levesque, Dany Dumont
% UQAR/ISMER
% email: dany_dumont@uqar.ca
% Website: http://www.ismer.ca/dumont-dany
% July 2013; Last revision: 14-Oct-2013
% ______________________________________________________________________

cstr = num2str(camNumber);
estr = num2str(expNumber);
rstr = num2str(rowNumber);
nbF = 40;
nbFStr = num2str(nbF);
rootdir = ['/MP_oceanographie/MP/images/multicam_',nbFStr,'f'];
listfile = [rootdir, '/list1.mat'];
expdir  = [rootdir,'/',estr,'_multicam'];
camdir  = [expdir,'/cam',cstr];
rectdir = [camdir,'/interp']; % 5 fps
%rectdir = [camdir,'/interp_25']; % 25 fps
cd(rootdir)
load(listfile)
cd(rectdir)

imfiles = dir('*.jpg');
nFiles  = size(imfiles,1);

%% Cropping parameters
% Images are 421x601 pixels
% The domain defined by I(iCrop:jCrop) will be set to zero (black).
if camNumber == 1
    
    if rowNumber == 1
        iBlack = 1:601;
        jBlack = 121:421;
    elseif rowNumber == 2
        iBlack = 1:601;
        jBlack = [1:105,220:421];
    elseif rowNumber == 3
        iBlack = 1:601;
        jBlack = [1:205,320:421];
    elseif rowNumber == 4
        iBlack = 1:601;
        jBlack = 1:305;
        
    elseif rowNumber == 99 % The collision experiment (201307311605)
        iBlack = 1:300;
        jBlack = 1:180;
    end
    
elseif camNumber == 2
    
    if rowNumber == 1
        iBlack = 1:601;
        jBlack = 121:421;
    elseif rowNumber == 2
        iBlack = 1:601;
        jBlack = [1:105,220:421];
    elseif rowNumber == 3
        iBlack = 1:601;
        jBlack = [1:205,320:421];
    elseif rowNumber == 4
        iBlack = 1:601;
        jBlack = 1:305;
    end
    
elseif camNumber == 3
    
    if rowNumber == 1
        iBlack = 1:601;
        jBlack = 121:421;
    elseif rowNumber == 2
        iBlack = 1:601;
        jBlack = [1:105,220:421];
    elseif rowNumber == 3
        iBlack = 1:601;
        jBlack = [1:205,320:421];
    elseif rowNumber == 4
        iBlack = 1:601;
        jBlack = 1:305;
    end
    
elseif camNumber == 4
    
    if rowNumber == 1
        iBlack = 1:601;
        jBlack = 121:421;
    elseif rowNumber == 2
        iBlack = 1:601;
        jBlack = [1:105,220:421];
    elseif rowNumber == 3
        iBlack = 1:601;
        jBlack = [1:205,320:421];
    elseif rowNumber == 4
        iBlack = 1:601;
        jBlack = 1:305;
    end
    
end

% Initialization

t    = nan.*ones(nFiles,1);
m    = nan.*ones(nFiles,1);
xpos = nan.*ones(nFiles,nb);
ypos = nan.*ones(nFiles,nb);
a    = nan.*ones(nFiles,nb);
%i    = nan.*ones(nFiles,601,421);
s    = nan.*ones(nFiles,nb);
c    = nan.*ones(nFiles,nb);

for n = 1:nFiles
    
    imfilename = imfiles(n).name;
    imNumber   = imfilename(3:7);
    
    [err,nf,imout,imtime,x,y,a,s,c] = ...
        r_isolate(imfilename,nb,filter,iBlack,jBlack,camNumber);
    
    if err == 0;
        t(n,1)    = imtime;
        m(n,1)    = nf;
        xpos(n,:) = x;
        ypos(n,:) = y;
        aa(n,:)   = a;
        %i(n,:,:)  = imout;
        ss(n,:)   = s;
        cc(n,:)   = c;
    else
        t(n,1)    = imtime;
        m(n,1)    = nf;
    end
    
    disp(imNumber);
    
end

%% Saving data

disp(' Saving data ...');

time   = t; %#ok<*NASGU>
nfloes = m;
a      = aa;
s      = ss;
c      = cc;
%images = i;
nbstr  = num2str(nb);

save([expdir,'/data_',estr,'_',cstr,'_',rstr],'time', ...
   'nfloes','xpos','ypos','a','s','c', nbstr,...
   '-v7.3'); % 5fps
%  save([expdir,'/data_','25_',estr,'_',cstr,'_',rstr,],'time', ...
%     'nfloes','xpos','ypos','a','s','c', ...
%     '-v7.3');  % 25 fps
% disp(' Done!');