image_name = mGetLeftImageFileList; zero_bin = zeros( 2^8, 2^8 ); grey = 2^7; Hu0_total =0; for image_count = 2:2%1:size(image_name,1); image_file = deblank( image_name( image_count,: ) ) image = pgmRead( sprintf( '../images/%s', image_file )); [ row_total, col_total ] = size( image ); bin = zero_bin; for row = 1:row_total for col = 2:col_total bin_row_index = image( row, col-1 )+1; bin_col_index = image( row, col )+1; % current pixel determines column since 3D mesh puts column along "x" axis. % zero is not a valid index -> add 1 bin( bin_row_index, bin_col_index ) = bin( bin_row_index, bin_col_index ) + 1; end end % Normalize to find pdf PDF = bin / sum( sum( bin ) ); if image_count == 2 for m=1:4; for n=1:4;mesh2=mesh2+PDF(m:4:256,n:4:256); end; end mesh2=mesh2'; % if image_count == 0 % display joint histogram for first image % subplot( 2, 1, 1 ); % mesh( PDF' ); surface( [1.5:4:255], [1.5:4:255], mesh2 ); PDF_max = max( max( mesh2 ) ); PDF_max = ceil( PDF_max*2000 ) / 2000; axis( [ 0 255 0 255 0 PDF_max ] ); view( -10, 30 ); grid on; xlabel( 'First pixel' ); ylabel( 'Second pixel' ); zlabel( 'Joint Probability Density' ); title( image_file ); drawnow; end % x*log(x) = log(x^x) PlogP = log( PDF.^PDF)/log(2); Hu0 = -sum( sum( PlogP ) ) Hu0_total = Hu0_total + Hu0; end Hu0 = Hu0_total / size(image_name, 1 ) sprintf( 'Normalized to word length per pixel:' ) Hu0/2