r_create_floe.m 5.09 KB
function [floe] = r_create_floe(nFrames,nObjects,xpos,ypos,c,a,s,camNumber)
% R_CREATE_FLOE - Creates the variable ''floe'' that contains the x-position of
% the floe, its y-position, its shape, its aera and its color.
%
% Syntax: 
%    [floe] = r_create_floe(nFrames,nObjects,xpos,ypos,c,a,s,camNumber)
%
% Inputs:
%    nFrame    - The number of frame
%    nObjects  - The number of object
%    xpos      - The x-position 
%    ypos      - The y-position
%    c         - The color of the object
%    a         - The area of the object
%    s         - The shape of the object
%    camNumber - The camera number
%
% Example:
%    [floe] = r_create_floe(250,5,2,450,c,a,s,4)
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also: r_data_pos 
%
% Author: Marie-Pier Marquis, Dany Dumont
% UQAR/ISMER
% email: dany_dumont@uqar.ca
% Website: http://www.ismer.ca/dumont-dany
% July 2014 Last revision : October 2014
% ________________________________________________________________________
%%
% Sort data by position along the y-axis
floe = nan.*ones(nObjects,nFrames,5);
for n = 1:nFrames
    [sy,u] = sort(ypos(n,:),'ascend'); % r_recon returns y-position 
    if nObjects == 5
        for k = 1:nObjects
            if k == 1
                u1 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u1);
                    floe(k,n,2) = ypos(n,u1);
                    floe(k,n,3) = c(n,u1);
                    floe(k,n,4) = s(n,u1);
                    floe(k,n,5) = a(n,u1);
                end
            elseif k == 2
                u2 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u2);
                    floe(k,n,2) = ypos(n,u2);
                    floe(k,n,3) = c(n,u2);
                    floe(k,n,4) = s(n,u2);
                    floe(k,n,5) = a(n,u2);
                end
            elseif k == 3
                u3 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u3);
                    floe(k,n,2) = ypos(n,u3);
                    floe(k,n,3) = c(n,u3);
                    floe(k,n,4) = s(n,u3);
                    floe(k,n,5) = a(n,u3);
                end
            elseif k == 4
                u4 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u4);
                    floe(k,n,2) = ypos(n,u4);
                    floe(k,n,3) = c(n,u4);
                    floe(k,n,4) = s(n,u4);
                    floe(k,n,5) = a(n,u4);
                end
            elseif k == 5
                u5 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u5);
                    floe(k,n,2) = ypos(n,u5);
                    floe(k,n,3) = c(n,u5);
                    floe(k,n,4) = s(n,u5);
                    floe(k,n,5) = a(n,u5);
                end
            end
        end
        
    elseif nObjects == 3
        for k = 1:nObjects
            if k == 1
                u1 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u1);
                    floe(k,n,2) = ypos(n,u1);
                    floe(k,n,3) = c(n,u1);
                    floe(k,n,4) = s(n,u1);
                    floe(k,n,5) = a(n,u1);
                end
            elseif k == 2
                u2 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u2);
                    floe(k,n,2) = ypos(n,u2);
                    floe(k,n,3) = c(n,u2);
                    floe(k,n,4) = s(n,u2);
                    floe(k,n,5) = a(n,u2);
                end
            elseif k == 3
                u3 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u3);
                    floe(k,n,2) = ypos(n,u3);
                    floe(k,n,3) = c(n,u3);
                    floe(k,n,4) = s(n,u3);
                    floe(k,n,5) = a(n,u3);
                end
            end
        end
    elseif nObjects == 2
        for k = 1:nObjects
            if k == 1
                u1 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u1);
                    floe(k,n,2) = ypos(n,u1);
                    floe(k,n,3) = c(n,u1);
                    floe(k,n,4) = s(n,u1);
                    floe(k,n,5) = a(n,u1);
                end
            elseif k == 2
                u2 = u(k);
                if ~isnan(sy(k))
                    floe(k,n,1) = xpos(n,u2);
                    floe(k,n,2) = ypos(n,u2);
                    floe(k,n,3) = c(n,u2);
                    floe(k,n,4) = s(n,u2);
                    floe(k,n,5) = a(n,u2);
                end
            end
        end
    else
        disp(' Error');
        return
    end
end

% Some unit conversion
% From pixel length to meters
if camNumber == 1
    floe(:,:,1) =  0.01.*floe(:,:,1) - 0.1;
elseif camNumber == 2
    floe(:,:,1) =  0.01.*floe(:,:,1) + 3.9;
elseif camNumber == 3
    floe(:,:,1) =  0.01.*floe(:,:,1) + 7.9;
elseif camNumber == 4
    floe(:,:,1) =  0.01.*floe(:,:,1) + 11.9;
end
floe(:,:,2) = -0.01.*floe(:,:,2) + 1.0;

% From number of pixel area to meter square
floe(:,:,5) =  0.0001.*floe(:,:,5);




end