

%% Floe
Floe = [];
for i = 1 : length(ice_floe)
    a0 = cat(1, ice_floe(i).Area);
    c0 = cat(1, ice_floe(i).Center);
    p0 = cat(1, ice_floe(i).Perimeter);
    pixels = cat(1, ice_floe(i).PixelsPosition);
    
    a1 = cat(1, floe(i).Area);
    c1 = cat(1, floe(i).Center);
    p1 = cat(1, floe(i).Perimeter);
    v1 = cat(1, floe(i).Vertices);
    n = length(v1);
    v1(n, :) = [];
    inter = cat(1, floe(i).Intersect);
    
    
    polygon1 = struct('Vertices', v1, 'Center', c1, 'Area', a1,...
        'Perimeter', p1, 'Intersect', inter);
    
    ff = struct('Center', c0, 'Area', a0, 'Perimeter', p0,...
        'Polygon', polygon1, 'Pixels', pixels);
    Floe = [Floe; ff];
    
end 


%% Brash
Brash = [];
for i = 1 : length(brash_ice)
    a0 = cat(1, brash_ice(i).Area);
    c0 = cat(1, brash_ice(i).Center);
    pixels = cat(1, brash_ice(i).PixelsPosition);
        
    r1 = cat(1, brash(i).Radius);
    p1 = 2 * pi * r1;
    inter = cat(1, brash(i).Intersect);
    
    circle1 = struct('Radius', r1, 'Perimeter', p1, 'Intersect', inter);
    
    bb = struct('Center', c0, 'Area', a0, 'Circle', circle1, 'Pixels', pixels);
    Brash = [Brash; bb];
    
end 


%% Param
NumPix_x = size(index_floe, 2);
NumPix_y = size(index_floe, 1);
MAMSL = [];
FOV = [];
TiltAngle = 90;
PanAngle = 0;
CamRot = [];
LeverArm = [];
VesselRot = [];
VesselPos = [];
FileName = [];
Time = [];
Location = 'Ny-Alesund';
Creator = 'UAV';
Caption = [];
PrjName = [];
PrjNum = [];

Param = struct('NumPix_x', NumPix_x, 'NumPix_y', NumPix_y, 'MAMSL', MAMSL,...
    'FOV', FOV, 'TiltAngle', TiltAngle, 'PanAngle', PanAngle, 'CamRot', CamRot,...
    'LeverArm', LeverArm, 'VesselRot', VesselRot, 'VesselPos', VesselPos,...
    'FileName', FileName, 'Time', Time, 'Location', Location,...
    'Creator', Creator, 'Caption', Caption, 'PrjName', PrjName, 'PrjNum', PrjNum);


%% Field
Georef = [];
Rot = [];
LengthSI_x = 50;
LengthSI_y = 18;
PixScale_x = LengthSI_x / NumPix_x;
PixScale_y = LengthSI_y / NumPix_y;
PixArea = PixScale_x * PixScale_y;
NumFloes = length(floe);
NumBrash = length(brash);
CovFloes = cat(1, coverage.IceFloe);
CovBrash = cat(1, coverage.BrashIce);
CovSlush = cat(1, coverage.Slush);
CovWater = cat(1, coverage.Water);
CovOther = length(find(index_residue ~= 0)) / (NumPix_x * NumPix_y);

% FSD
FSD = [];
floe_area = cat(1, ice_floe.Area);
min_x = min(floe_area);
max_x = max(floe_area);
nbins = 50;
inter = fix((max_x - min_x)/nbins);
[z, n] = hist(floe_area, min_x : inter : max_x);
int_min = n;
int_max = n(2 : length(n)) - 1;
int_max = [int_max, max_x];
num = z;
for i = 1 : length(int_min)
    FSD{i} = [int_min(i), int_max(i), num(i)];
end

Field = struct('Georef', Georef, 'Rot', Rot, 'LengthSI_x', LengthSI_x,...
    'LengthSI_y', LengthSI_y, 'PixScale_x', PixScale_x,...
    'PixScale_y', PixScale_y, 'PixArea', PixArea, 'NumFloes', NumFloes,...
    'NumBrash', NumBrash, 'CovFloes', CovFloes, 'CovBrash', CovBrash,...
    'CovSlush', CovSlush, 'CovWater', CovWater, 'CovOther', CovOther, 'FSD', {FSD});


%%
IceImage = struct('Param', Param, 'Field', Field, 'Floe', Floe, 'Brash', Brash);
