function Carray = randcov_segmented7(f,swindows,s)

f = shiftdim(f,1);
% number of features
feature_no = size(f,3);

Carray = cell(s,1);

for v = 1:s
    
    % compute the covariance matrix of the selected region
    C = zeros(feature_no,feature_no);
    windows = swindows(v,:);
    
    i = 1:feature_no;
    j = 1:feature_no;
    ii = windows(1):windows(1)+windows(3)-1;
    jj = windows(2):windows(2)+windows(3)-1;
    slice_i = f(ii,jj,i);
    slice_j = f(ii,jj,j);
    % compute covariance descriptor using only foreground
    % pixels
    sum2 = sum(sum(slice_i));
    sum3 = sum(sum(slice_j));
    for i = 1:feature_no
        for j = 1:feature_no
            if(i <= j)
                sum1 = sum(sum(slice_i(:,:,i).*slice_j(:,:,j)));
                C(i,j) = (1/((length(ii)*length(jj))-1))*(sum1-sum2(1,1,i)*sum3(1,1,j)/(length(ii)*length(jj)));
            else
                C(i,j) = C(j,i);
            end
        end
    end  
    Carray{v} = C;
end


