r_show_collisions.m 2.34 KB
function r_show_collisions(expNumber,camNumber,rowNumber)
% R_SHOW_COLLISIONS - Produces a series of images with white circles drawn
% at the position retrieved by R_RECON. It is applied specifically to the
% collision experiment (201307311605, camera 1). 
%
% Syntax:  r_show_collisions
%
% Example:
%    r_show_collisions
%
% Other m-files required: Image Processing Toolbox
% Subfunctions: none
% MAT-files required: data_$expNumber_$camNumber.mat obtained from R_RECON
%
% See also: R_RECON, R_ISOLATE, R_SHOW

% Author: Yannick Levesque, Dany Dumont
% UQAR/ISMER
% email: dany_dumont@uqar.ca
% Website: http://www.ismer.ca/dumont-dany
% 5-Nov-2013
% ______________________________________________________________________

cstr = num2str(camNumber);
estr = num2str(expNumber);
rstr = num2str(rowNumber);

rootdir = '/Users/marie-pier/Desktop/MP/images/multicam';
expdir  = [rootdir,'/',estr,'_multicam'];
camdir  = [expdir,'/cam',cstr];
intdir  = [camdir,'/interp'];

datafile = [expdir,'/data_',estr,'_',cstr,'_',rstr];

load(datafile)
cd(intdir)

imfiles  = dir('im*.jpg');
nFiles   = size(imfiles,1);
nObjects = size(xpos,2);

firstFrame = [ 607 2857 4683 5907 8157  9882 11757 13757 15582 18082];
lastFrame  = [1182 3182 5107 6732 8957 10682 12332 14232 16307 18507];

for n = 1:nFiles
    
    imfilename = imfiles(n).name;
    imNumber   = imfilename(3:7);
    im         = str2double(imNumber);
    
    %I0 = double(imread(imfilename));
    I0 = imread(imfilename);
    imshow(I0)
    
    col = find(im >= firstFrame & im <= lastFrame);
    colstr = num2str(col);
    
    text(20,20,['Collision ',colstr],'Color','w','FontSize',18,'FontName','Arial', ...
                'FontWeight','bold');
    
    
    if ~isnan(xpos(n,1))
        
        viscircles([xpos(n,:)' ypos(n,:)'], 49.5.*ones(1,nObjects),'EdgeColor','w');
        hold on
        % Put a number on each object
        for k=1:nObjects
            text(xpos(n,k)+5,ypos(n,k)+5,num2str(k), ...
                'Color','w','FontSize',18,'FontName','Arial', ...
                'FontWeight','bold');
            plot(xpos(n,k),ypos(n,k),'xw', ...
                'MarkerSize',10);
        end
        hold off
    end
    
    F = getframe(gcf);
    [X,Map] = frame2im(F);
    
    imwrite(X,[camdir,'/im',imNumber,'_show.jpg'],'jpg');
    
end