% Calculating Gray level difference statistics for two pixels at angle

% 0 degree.

% Equation : [f(x) - f(x+h)]/h

row=size(img,1); %number of rows in input image

col=size(img,2); %number of columns in input image

%Calculate p_delta in 0 direction,

%h = 1 ; eq : |f(x) - f(x+h)|/h.

f_delta0=img;

for i=1:row

for j=1:col-1

f_delta0(i,j)= abs(img(i,j)- img(i,j+1));

end

end

f_delta0=f_delta0(1:row,1:col-1);

f_delta0=round(f_delta0); %f_delta0 contains the final difference calculated between two pixels i.e. f(x) and f(x+h)

[p_delta0, x] = imhist(f_delta0); % returns the histogram counts in p_delta0

pp = sum(p_delta0); % total number of occurences

p_delta0 = p_delta0/pp; % probability distribution function or probability of each 'grey level difference' in image

%for computing contrast

[size_p_delta0_1,size_p_delta0_2] = size(p_delta0); %size of p_delta is rows = 256, col = 1

i_matrix = repmat([1:size_p_delta0_1]',1,size_p_delta0_2);

j_index = i_matrix(:); %j_index contains one column and 256 rows. j_index = [ 1 2 3 4 5 .......253 254 255 256]

sqr_ji = j_index.^2; %square of j_index as required for Contrast formula

%j_matrix = repmat([1:size_p_delta0_2],size_p_delta0_1,1);

%i_index = j_matrix(:); % i_index = [ 1 1 1 1 1 .... 2 2 2 2 2 ... ]

%%%% Calculating Contrast, Entropy,Energy, Mean.

contrast0 = sum(sqr_ji.*p_delta0)

ASM0 = sum(p_delta0 .^2)

Entropy0 = - sum(p_delta0.*log(p_delta0+ eps))

mean0 = (1/256)* sum(j_index .* p_delta0) % m = 256

More Puja Bharti's questions See All
Similar questions and discussions