function Hu0 = mComputeEntropy( image ); zero_bin = zeros( 1, max(max(image))-min(min(image))+1 ); [ row_total, col_total ] = size( image ); image_size = row_total*col_total; bin = zero_bin; image_offset = min(min( image ) )-1; for row = 1:row_total for col = 1:col_total bin_index = image( row, col ) - image_offset; % zero index not allowed bin( bin_index ) = bin( bin_index ) + 1; end end % Normalize to find pdf PDF = bin/sum(bin); % x*log(x) = log(x^x) PlogP = log(PDF.^PDF)./log(2); Hu0 = -sum( PlogP );