%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Function: my_MV_entropy(MV,num_pixels,number_of_symbols) % % This function estimates the entropy of the motion vectors after coding % them using DPCM. The entropy is estimated using the histogram of each % vector component independently (i.e. x-coor, y-coor). % The resulting entropy is computed as the sumation of the entropies of % the x and y coordinates and is expressed in units of bits per pixel. % % Input % MV : The motion vectors % num_pixels : Number of pixels in the macroblock (64 in the 8x8 case) % number_of_symbols : Number of possible values as vector coefficients % % Ouput % entropy_value: Entropy of the MV after coding them using DPCM % % Programmed by Daniel Garcia-Romero 4-24-2006 function [entropy_value]=my_MV_entropy(MV,num_pixels,number_of_symbols) % Use a differential encoding of MV before entropy computation [num_vec,dummy]=size(MV); DPCM_x_coor=conv(MV(:,1),[1 -1]); DPCM_x_coor(num_vec+1)=[]; DPCM_y_coor=conv(MV(:,2),[1 -1]); DPCM_y_coor(num_vec+1)=[]; %Estimate entropy based on relative frequencies rel_freq_x_coor=hist(DPCM_x_coor,number_of_symbols); rel_freq_x_coor=rel_freq_x_coor/num_vec; zero_rel_freq=find(rel_freq_x_coor == 0); if (length(zero_rel_freq) > 0) rel_freq_x_coor(zero_rel_freq)=[]; end entropy_value_x=rel_freq_x_coor*log2(1./rel_freq_x_coor)'; rel_freq_y_coor=hist(DPCM_y_coor,number_of_symbols); rel_freq_y_coor=rel_freq_y_coor/num_vec; zero_rel_freq=find(rel_freq_y_coor == 0); if (length(zero_rel_freq) > 0) rel_freq_y_coor(zero_rel_freq)=[]; end entropy_value_y=rel_freq_y_coor*log2(1./rel_freq_y_coor)'; %The total entropy is computed as the sum of the x, y coordinate entropies %and is normalized by the number of pixels entropy_value=(entropy_value_x+entropy_value_y)/num_pixels;% Units of bits/pixel