% Freeman (1970). See page 15 of 2019 lecture notes on object description
%
% cc    - struct containing (y0,x0) initial coordination of chain code
% code  - the chain code of the object
function A = area_from_chain_code(cc)
   
  A = 0; % Area
  chain = cc.code;
  y_im1 = cc.y0; % y starting point (y_i-1)
  
  % Vectors for converting 8-directional chain code to directions
  cy  = [0,-1,-1,-1,0,1,1,1];
  cx = [1,1,0,-1,-1,-1,0,1];
  
  for c = 1:length(chain)
      
    c_iy = cy(chain(c)+1);
    c_ix = cx(chain(c)+1);
    A = A + c_ix*(y_im1 + c_iy/2);
    y_im1 = y_im1 + c_iy;
    
  end

end