image_name = mGetLeftImageFileList; bin_total = 2^8; zero_bin = zeros( 1, bin_total ); Hu0_total = 0; for image_count = 1:size(image_name,1); image_file = deblank( image_name( image_count,: ) ) image = pgmRead( sprintf( '../images/%s',image_file ) ); % ignore coding for first column -- valid results only image_filter = [ -1 1 ]; image = filter2( image_filter, image, 'valid' ); [ row_total, col_total ] = size( image ); % errors below zero are shifted up by 256, ie wrapped around so that % the reconstruction will be correct, eg: % e = s0 - s1 = 255 - 0 = 255 % then % s0 = s1 + e = 0 + ( 255 ) = 255 % or: % e = s0 - s1 = 0 - 255 = -255 = 1 % then % s0 = s1 + e = 255 + ( 1 ) = 256 = 0 bin = zero_bin; for row = 1:row_total for col = 1:col_total bin_index = image( row, col ); if bin_index < 0 bin_index = bin_index + 257; % +256 to wrap, +1 for valid index else bin_index = bin_index + 1; % 0 not a valid index end 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 ) Hu0_total = Hu0_total+Hu0; end % Overall statistics: sprintf( 'Combined images:' ) Hu0 = Hu0_total/size(image_name,1)