r_addinfo.m 3.66 KB
function r_addinfo(expNumber,zone,iFirst,nSkip,iEnd)
% R_ADDINFO - Add contextual and environment information on the picture.
% 
% Syntax:  r_addinfo(expNumber,zone,iFirst,nSkip,iEnd)
% 
% Inputs:
%    expNumber - The date number (yyyymmdd). Points to a directory
%    zone      - The part of the scene to analyse. See the code for details
%    iFirst    - The first image to be treated
%    nSkip     - The number of images skipped
%    iEnd      - The last image to be treated
%                (if iEnd is set to zero, the loop is done from iFirst to
%                 nFiles)
% 
% Example:
%    r_addinfo(20140203,3,1,1,0)
% 
% Other m-files required: none
% Subfunctions: none
% MAT-files required: meteo and tidal data
% 
% See also: G_RECT, R_UNDISTORT, R_ROTATE

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

estr = num2str(expNumber);
zstr = num2str(zone);

rootdir = '/Volumes/DyDisk/opc';
expdir  = [rootdir,'/images/',estr];
origdir = [expdir,'/original'];
intdir  = [expdir,'/interp'];
zonedir = [intdir,'/zone',zstr];
calfile = [rootdir,'/calib/opc_rect.mat'];

metfile = [rootdir,'/meteo/ile_bicquette/meteo_ile_bicquette.txt'];

S = load(metfile);

cd(zonedir)

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

if iEnd == 0
    iEnd = nFiles;
end

for n = iFirst:nSkip:iEnd
    
    imfilename = imfiles(n).name;
    imNumber   = imfilename(1:13);

    imyr  = str2double(imNumber( 1:4 ));
    immo  = str2double(imNumber( 5:6 ));
    imda  = str2double(imNumber( 7:8 ));
    imhr  = str2double(imNumber(10:11));
    
    ind = find(S(:,1)==imyr & S(:,2)==immo & S(:,3)==imda & S(:,4)==imhr);
    
    temp = S(ind,5);
    wspd = S(ind,7);
    wdir = S(ind,6).*10;
    
    if wdir > 348.75 && wdir <= 11.25
        dirstr = 'N';
    elseif wdir > 11.25 && wdir <= 33.75
        dirstr = 'NNE';
    elseif wdir > 33.75 && wdir <= 56.25
        dirstr = 'NE';
    elseif wdir > 56.25 && wdir <= 78.75
        dirstr = 'ENE';
    elseif wdir > 78.75 && wdir <= 101.25
        dirstr = 'E';
    elseif wdir > 101.25 && wdir <= 123.75
        dirstr = 'ESE';
    elseif wdir > 123.75 && wdir <= 146.25
        dirstr = 'SE';
    elseif wdir > 146.25 && wdir <= 168.75
        dirstr = 'SSE';
    elseif wdir > 168.75 && wdir <= 191.25
        dirstr = 'S';
    elseif wdir > 191.25 && wdir <= 213.75
        dirstr = 'SSO';
    elseif wdir > 213.75 && wdir <= 236.25
        dirstr = 'SO';
    elseif wdir > 236.25 && wdir <= 258.75
        dirstr = 'OSO';
    elseif wdir > 258.75 && wdir <= 281.25
        dirstr = 'O';
    elseif wdir > 281.25 && wdir <= 303.75
        dirstr = 'ONO';
    elseif wdir > 303.75 && wdir <= 326.25
        dirstr = 'NO';
    elseif wdir > 326.25 && wdir <= 348.75
        dirstr = 'NNO';
    end
    
    I0 = imread(imfilename);
    imshow(I0,'Border','tight')
    %I0 = double(I0);
    
    text(400,1520,[num2str(temp),'^oC'], ...
        'Color','w','FontSize',24, ...
        'HorizontalAlignment','right', ...
        'FontName','Arial Narrow');
    text(1980,1400,[dirstr], ...
        'Color','w','FontSize',24, ...
        'HorizontalAlignment','right', ...
        'FontName','Arial Narrow');
    text(1980,1520,[num2str(wspd),' km/h'], ...
        'Color','w','FontSize',24, ...
        'HorizontalAlignment','right', ...
        'FontName','Arial Narrow');
    
    F = getframe(gcf);
    [X,Map] = frame2im(F);

    imwrite(X,[zonedir,'/',imNumber,'_test.jpg'],'jp2');
    
    disp([' ',imNumber]);
    
end