Why the entropy variable stores the same values of all pictures?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi all,
I have a code of matlab works on multiple pictures to calculate grey level co-occurrence matrix for each picture , but when i calculated the entropy vlaues , the vlaues are the same for all pictures .I want to know why this problem .
my code is bleow :
folder='C:\Users\Administrator.1-50-185\Desktop\photos';
I=dir(fullfile(folder,'*.jpg'));
for k=1:numel(I)
filename=fullfile(folder,I(k).name);
I2{k}=rgb2gray(imread(filename));
end
for r=1:numel(I)
[px,py]=size(I2{r});
cr=27;
x_start=(px-cr)/2;
x_stop=x_start+cr;
y_start=(py-cr)/2;
y_stop=y_start+cr;
I3{r}= I2{r}(x_start:x_stop,y_start:y_stop,:);
end
for g=1:numel(I)
for m=1:4
switch(m)
case 1
glcm_matrix{g,m}=graycomatrix(I3{g},'Offset',[0 1]);
stats{g,m}=graycoprops(glcm_matrix{g,m},{'contrast','homogeneity','energy','correlation'});
t{g,m}=struct2table(stats{g,m});
sum1=sum(sum(glcm_matrix{g,m}));
entropy1=0;
dissimilarity1=0;
for i=1:8
for j=1:8
if(glcm_matrix{g,m}([i],[j])~=0)
entropy1=entropy1+(-(glcm_matrix{g,m}([i],[j]).*(log(glcm_matrix{g,m}([i],[j])))));
dissimilarity1=dissimilarity1+(abs(i-j).*glcm_matrix{g,m}([i],[j])/sum1);
end
end
end
case 2
glcm_matrix{g,m}=graycomatrix(I3{g},'Offset',[-1 1]);
stats{g,m}=graycoprops(glcm_matrix{g,m},{'contrast','homogeneity','energy','correlation'});
t{g,m}=struct2table(stats{g,m});
sum2=sum(sum(glcm_matrix{g,m}));
entropy2=0;
dissimilarity2=0;
for a=1:8
for b=1:8
if(glcm_matrix{g,m}([a],[b])~=0)
entropy2=entropy2-(glcm_matrix{g,m}([a],[b]).*(log(glcm_matrix{g,m}([a],[b]))));
dissimilarity2=dissimilarity2+(abs(a-b).*glcm_matrix{g,m}([a],[b])/sum2);
end
end
end
case 3
glcm_matrix{g,m}=graycomatrix(I3{g},'Offset',[-1 0]);
stats{g,m}=graycoprops(glcm_matrix{g,m},{'contrast','homogeneity','energy','correlation'});
t{g,m}=struct2table(stats{g,m});
sum3=sum(sum(glcm_matrix{g,m}));
entropy3=0;
dissimilarity3=0;
for c=1:8
for d=1:8
if(glcm_matrix{g,m}([c],[d])~=0)
entropy3=entropy3-(glcm_matrix{g,m}([c],[d]).*(log(glcm_matrix{g,m}([c],[d]))));
dissimilarity3=dissimilarity3+(abs(c-d).*glcm_matrix{g,m}([c],[d])/sum3);
end
end
end
case 4
glcm_matrix{g,m}=graycomatrix(I3{g},'Offset',[-1 -1]);
stats{g,m}=graycoprops(glcm_matrix{g,m},{'contrast','homogeneity','energy','correlation'});
t{g,m}=struct2table(stats{g,m});
sum4=sum(sum(glcm_matrix{g,m}));
entropy4=0;
dissimilarity4=0;
for e=1:8
for f=1:8
if(glcm_matrix{g,m}([e],[f])~=0)
entropy4=entropy4-(glcm_matrix{g,m}([e],[f]).*(log(glcm_matrix{g,m}([e],[f]))));
dissimilarity4=dissimilarity4+(abs(e-f).*glcm_matrix{g,m}([e],[f])/sum4);
end
end
end
end
end
end
excelfilename='chall.xlsx';
for sheet=1:7366
for s=1:4
switch(s)
case 1
xlswrite(excelfilename,glcm_matrix{sheet,s},sheet+2649,'A1:H8');
writetable(t{sheet,s},'chall.xlsx','sheet',sheet+2649,'Range','J1:M2');
col_header={'entropy'};
xlswrite(excelfilename,col_header,sheet+2649,'N1');
xlswrite(excelfilename,entropy1,sheet+2649,'N2');
col_header={'dissimilarity'};
xlswrite(excelfilename,col_header,sheet+2649,'O1');
xlswrite(excelfilename,dissimilarity1,sheet+2649,'O2');
case 2
xlswrite(excelfilename,glcm_matrix{sheet,s},sheet+2649,'A10:H17');
writetable(t{sheet,s},'chall.xlsx','sheet',sheet+2649,'Range','J10:M11');
col_header={'entropy'};
xlswrite(excelfilename,col_header,sheet+2649,'N10');
xlswrite(excelfilename,entropy2,sheet+2649,'N11');
col_header={'dissimilarity'};
xlswrite(excelfilename,col_header,sheet+2649,'O10');
xlswrite(excelfilename,dissimilarity2,sheet+2649,'O11');
case 3
xlswrite(excelfilename,glcm_matrix{sheet,s},sheet+2649,'A19:H26');
writetable(t{sheet,s},'chall.xlsx','sheet',sheet+2649,'Range','J19:M20');
col_header={'entropy'};
xlswrite(excelfilename,col_header,sheet+2649,'N19');
xlswrite(excelfilename,entropy3,sheet+2649,'N20');
col_header={'dissimilarity'};
xlswrite(excelfilename,col_header,sheet+2649,'O19');
xlswrite(excelfilename,dissimilarity3,sheet+2649,'O20');
case 4
xlswrite(excelfilename,glcm_matrix{sheet,s},sheet+2649,'A28:H35');
writetable(t{sheet,s},'chall.xlsx','sheet',sheet+2649,'Range','J28:M29');
col_header={'entropy'};
xlswrite(excelfilename,col_header,sheet+2649,'N28');
xlswrite(excelfilename,entropy4,sheet+2649,'N29');
col_header={'dissimilarity'};
xlswrite(excelfilename,col_header,sheet+2649,'O28');
xlswrite(excelfilename,dissimilarity4,sheet+2649,'O29');
end
end
end
0 comentarios
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!