% This code is only available for academic non-commercial use. 
% If you are using this code, please give a reference to:
% Zhang, Q. and R. Skjetne, “Image processing for identification of 
% sea-ice floes and the floe size distributions.” IEEE Transactions
% on Geoscience and Remote Sensing, Vol. 53, No. 5, pp. 2913-2924, 2015.

%% parameter setting
% parameters for image
I = imread('sea_ice_test.jpg');   % input image
kms0 = 3;    % kmeans

Ra_min = 10;  % minimum ice piece area
Ra = 2500;   % maximum ice piece area
Rc = 0.9;   % convexity threshlod
Rl = 2;    % threshold ratio between length and width

se = strel('disk', 3);  % morphology structure element


% parameters for GVF Snake
Num = 500;      % number of GVF iterations
iter = 100;   % number of Snake iterations 
% N = 50;    % iter of deformation


% parameters for shape enhancement
se_th = 50;    % threshold for adaptive morphology structure element
min_floe = 40;   % minimum floe area
min_brash = 1;   % minimum brash area


%% other parameters for GVF Snake, DON'T TUNE!
sigma = 0;   % gaussianBlur
GradientOn = 1;  % 1 : Gradient on  0 : Gradient off

GVFOn = 1;   % 1 : GVF  0 : SVF
mu = 0.1;    % parameter for GVF (more noise, increase mu)

alpha = 0.05;   % internal weight that control snake's tension
beta = 0;     % internal weight that control snake's rigidity
gamma = 1;    % step size in one iteration
kappa = 0.5;   % external force weight
Dmin = 0;   % min raster of the snake
Dmax = 1;   % max raster of the snake

timer = 1;

%%
[seg, bk] = seaice_kmean_GVF_forenhancement( I, kms0, sigma, GradientOn, GVFOn, Num, mu,...
    iter, alpha, beta, gamma, kappa, Dmin, Dmax,  Ra_min, Ra, Rc, Rl, se, timer);


[out, index_floe, ice_floe, index_brash, brash_ice, index_slush, index_water, index_residue, coverage] = ...
    ice_shape_enhancement(bk, seg, min_floe, min_brash, se_th);


[floe, brash] = sea_ice_model( ice_floe, brash_ice, index_floe );



