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

1 visualizzazione (ultimi 30 giorni)
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.

Risposta accettata

Bruno Luong
Bruno Luong il 20 Gen 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 Commenti
Bruno Luong
Bruno Luong il 20 Gen 2023
Modificato: Bruno Luong il 20 Gen 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.

Accedi per commentare.

Più risposte (1)

Image Analyst
Image Analyst il 20 Gen 2023
What about entropy
e = entropy(grayImage(row1:row2, col1:col2))
  1 Commento
Simone
Simone il 20 Gen 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))

Accedi per commentare.

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by