For a given image Img, I calculated its entropy and got the same result as MATLAB's entropy function.
hist_img = hist(Img(:),256);
pdf_img = hist_img./sum(hist_img);
H_pdf = sum(pdf_img.*log2(1./pdf_img))
H_test = entropy(input_img)
However, when I try to do the same for difference image I don't get the same result
dif = input_img(2:end,:) - input_img(1:end-1,:);
hist_dif = hist(dif(:),256);
pdf_dif = hist_dif./sum(hist_dif);
H_pdf = pdf_dif.*log2(1./pdf_dif);
H_pdf (isnan(H_pdf )) = 0;
H = sum(H_pdf )
H_test = entropy(dif)
Is there any suggestions how to fix this?