How to calculate the entropy of a portion of image as in the following formula?

2 views (last 30 days)
Hello everyone, I am new here on matlab. I should calculate the subset entropy of portion of image, defined as in the formula (4). Could someone please tell me how to write a routine that calculates the subset entropy using matlab please.
Thank you very much in advance.

Accepted Answer

Bruno Luong
Bruno Luong on 20 Jan 2023
Please try this
A=imread('ngc6543a.jpg');;
A=double(A(1:500,:,:));
A=sum(A,3);
M = 11; N = 11;
% Build 8-neighbor
[di,dj] = ndgrid(-1:1);
di = di(:);
dj = dj(:);
di(5,:) = []; dj(5,:) = []; % remove (0,0) shift
A8 = zeros([size(A),8]);
for i=1:8
A8(:,:,i) = A(min(max(di(i)+(1:end),1),end), ...
min(max(dj(i)+(1:end),1),end));
end
dA = sum(abs(A8-A),3);
depth = 24+zeros(size(A));
K = ones(M,N);
delta = conv2(dA,K,'same')./(2.^depth.*conv2(ones(size(dA)),K,'same'));
subplot(2,1,1);
imagesc(A)
colormap gray
subplot(2,1,2);
imagesc(delta);
  7 Comments
Bruno Luong
Bruno Luong on 20 Jan 2023
Edited: Bruno Luong on 20 Jan 2023
Ask people who claim it, here my value is smal becaise the depth (beta) is 24 as in your example of code.
1/2^24
ans = 5.9605e-08
You have all the values in my code, why can't you check it.
I simply implement what you wrote above as formula, I don't know this specific formula, the paper and people who wrote it.
What I know is entropy never have strict unit definition, as long as it's defined consistently across the usage for comparison.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 20 Jan 2023
What about entropy
e = entropy(grayImage(row1:row2, col1:col2))
  1 Comment
Simone
Simone on 20 Jan 2023
Hi @Image Analyst, the the way the entropy function is calculated is different from formula (4). I wrote this routine, do you think it will work?
A1=imread('IMG_111.png');
A=double(A1);
g=rgb2gray(A);
x=2000 %coordinate of subset center
y=2000 %coordinate of subset center
j=60 %subset radius
A1=A([(x-(j-1)):(x+j)],[(y-(j-1)):(y+j)]);
xx=((j*2)-9)
for k=8:1:xx
for l=8:1:xx
A2=A1([(k-7):(k+9)],[(l-7):(l+9)]);
for i=1:1:17
for j=1:1:17
Ii=A2([i],[j]);
row=size(A2,1);
column=size(A2,2);
Ip=A2([(row-1)/2],[(column-1)/2]);
c=abs(Ip-Ii);
C(i,j)=c;
S = sum(C(:));
end
end
D(k,l)=S;
end
end
S1 = sum(D(:));
subsetentropy=S1/((2^24)*(j*2*j*2))

Sign in to comment.

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!