r_rotate.m 1.76 KB
function r_rotate(expNumber,camNumber,k,iFirst,iEnd)
% R_ROTATE - Rotate a batch of images by k times 90 degrees in the
% counsterclockwise direction.
% 
% Syntax:  r_rotate(expNumber,camNumber,k,iFirst,iEnd)
% 
% Inputs:
%    expNumber - The experiment identifier
%    camNumber - The camera number
%    k         - The integer number of 90 counterclockwise rotations
%    iFirst    - The first image to be treated
%    iEnd      - The last image to be treated. If iEnd is set to zero,
%                the loop is done on all files starting with iFirst.
% 
% Example:
%    r_rotate(201307231525,2,-1,1,0)
% 
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
% 
% See also: ROT90, R_UNDISTORT, R_INTERP, R_MOVIE

% Author: Dany Dumont
% UQAR/ISMER
% email: dany_dumont@uqar.ca
% Website: http://www.ismer.ca/dumont-dany
% September 2013
% ______________________________________________________________________

cstr = num2str(camNumber);
estr = num2str(expNumber);
nbF = 40;
nbFStr = num2str(nbF);

rootdir = ['/MP_oceanographie/MP/images/multicam_',nbFStr,'f'];
expdir  = [rootdir,'/',estr,'_multicam'];
camdir  = [expdir,'/cam',cstr];
unddir  = [camdir,'/undistorted'];

cd(unddir)

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

if iEnd == 0
    iEnd = nFiles;
end

for n = iFirst:iEnd
    
    imfilename = imfiles(n).name;
    imNumber   = imfilename(3:7);
    
    I = imread(imfilename);
    I = double(I);
    
    R = squeeze(I(:,:,1));
    G = squeeze(I(:,:,2));
    B = squeeze(I(:,:,3));
    
    R_rot = rot90(R,k);
    G_rot = rot90(G,k);
    B_rot = rot90(B,k);
    
    I_rot(:,:,1) = R_rot;
    I_rot(:,:,2) = G_rot;
    I_rot(:,:,3) = B_rot;
    I_rot = uint8(I_rot);
    
    imwrite(I_rot,imfilename,'jpg');
    
    disp([' ',imNumber]);
    
end