function [I, dI] = miFromCounts_TrevesPanzeri(czx)

    cx = sum(czx,1)';
    cz = sum(czx,2);
    N = sum(czx(:));
    if any(size(czx) == 1)
        I = 0;
    else
        I = entropy(cz) + entropy(cx) - entropy(czx);
    end
    
    % Apply finite size correction from Treves and Panzeri
    nz = size(czx,1);
    nx = size(czx,2);
    I = I - (nx-1)*(nz-1)/(2*N);
    
    % Determine variance using Bill's ghetto method
    if nargout==2
        I_half = zeros(100,1);
        for n=1:500
            czx_half = floor(.5*czx + sqrt(.5*czx).*randn(nz,nx));
            cx_half = sum(czx_half,1)';
            cz_half = sum(czx_half,2);
            if any(size(czx_half) == 1)
                I_half(n) = 0;
            else
                I_half(n) = entropy(cz_half) + entropy(cx_half) - entropy(czx_half);
            end
        end
        dI = std(I_half)/sqrt(2);
    end
end