0 Replies - 426 Views - Last Post: 01 July 2019 - 02:33 AM Rate Topic: -----

#1 ahmadres   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 01-July 19

Different results about glcm and features on same images

Posted 01 July 2019 - 02:33 AM

The problem is when I calculate glcm and its features for same pictures and same code , i get different results about glcm and features , so what is the wrong in with this .
The code is in attached file .



folder='C:\Users\user\Desktop\ISIC2018_Task3_Training_Input';
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(g)=sum(sum(glcm_matrix{g,m}));
             count1(g)=0;
             entropy1(g)=0;
             dissimilarity1(g)=0;
             for i=1:8
                 for j=1:8
                     if(glcm_matrix{g,m}([i],[j])~=0)
                        entropy1(g)=entropy1(g)+(-glcm_matrix{g,m}([i],[j])).*(log(glcm_matrix{g,m}([i],[j])));
                        count1(g)=count1(g)+(abs(i-j).*(glcm_matrix{g,m}([i],[j])));
                       
                     end
                 end
             end
             dissimilarity1(g)=(count1(g)/sum1(g));
          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(g)=sum(sum(glcm_matrix{g,m}));
             count2(g)=0;
             entropy2(g)=0;
             dissimilarity2(g)=0;
             for a=1:8
                 for b=1:8
                     if(glcm_matrix{g,m}([a],[b])~=0)
                       entropy2(g)=entropy2(g)+(-glcm_matrix{g,m}([a],[b])).*(log(glcm_matrix{g,m}([a],[b])));                     
                       count2(g)=count2(g)+(abs(a-B)/>.*glcm_matrix{g,m}([a],[b]));

                     end
                 end
             end
              dissimilarity2(g)=(count2(g)/sum2(g));
          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(g)=sum(sum(glcm_matrix{g,m}));
             count3(g)=0;
             entropy3(g)=0;
             dissimilarity3(g)=0;
             for c=1:8
                 for d=1:8
                     if(glcm_matrix{g,m}([c],[d])~=0)
                       entropy3(g)=entropy3(g)+(-glcm_matrix{g,m}([c],[d])).*(log(glcm_matrix{g,m}([c],[d])));       
                       count3(g)=count3(g)+(abs(c-d).*glcm_matrix{g,m}([c],[d]));

                     end
                 end
             end
             dissimilarity3(g)=(count3(g)/sum3(g));
          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(g)=sum(sum(glcm_matrix{g,m}));
             count4(g)=0;
             entropy4(g)=0;
             dissimilarity4(g)=0;
             for e=1:8
                 for f=1:8
                     if(glcm_matrix{g,m}([e],[f])~=0)
                       entropy4(g)=entropy4(g)+(-glcm_matrix{g,m}([e],[f])).*(log(glcm_matrix{g,m}([e],[f])));                
                       count4(g)=count4(g)+(abs(e-f).*glcm_matrix{g,m}([e],[f]));
                     end
                 end
             end
             dissimilarity4(g)=(count4(g)/sum4(g));             
      end
      
   end
   
end

excelfilename2='chall2.xlsx';


for sheet=1:10015
    
   for s=1:4
       
      switch(s)
        
          case 1
             str11 = strcat('B',num2str(2+4.*(sheet- 1)));
             str12 = strcat('E',num2str(2+4.*(sheet- 1)));
             str21 = strcat(str11,':',str12);
             writetable(t{sheet,s},'chall2.xlsx','sheet',1,'Range',str21,'WriteVariableNames', false);
             str1 = strcat('F',num2str(2+4.*(sheet- 1)));
             col_header={'entropy'};           
             xlswrite(excelfilename2,entropy1(sheet),1,str1);
             str2 = strcat('G',num2str(2+4.*(sheet- 1)));
             col_header={'dissimilarity'};           
             xlswrite(excelfilename2,dissimilarity1(sheet),1,str2);

          case 2
             str13 = strcat('B',num2str(3+4.*(sheet- 1)));  
             str14 = strcat('E',num2str(3+4.*(sheet- 1)));
             str41 = strcat(str13,':',str14);
             writetable(t{sheet,s},'chall2.xlsx','sheet',1,'Range',str41,'WriteVariableNames', false);
             str3 = strcat('F',num2str(3+4.*(sheet- 1)));
             col_header={'entropy'};          
             xlswrite(excelfilename2,entropy2(sheet),1,str3);
             str4 = strcat('G',num2str(3+4.*(sheet- 1)));
             col_header={'dissimilarity'};           
             xlswrite(excelfilename2,dissimilarity2(sheet),1,str4);

          case 3
             str15 = strcat('B',num2str(4+4.*(sheet- 1)));
             str16 = strcat('E',num2str(4+4.*(sheet- 1)));
             str61 = strcat(str15,':',str16);
             writetable(t{sheet,s},'chall2.xlsx','sheet',1,'Range',str61,'WriteVariableNames', false);
             str5 = strcat('F',num2str(4+4.*(sheet- 1)));
             col_header={'entropy'};           
             xlswrite(excelfilename2,entropy3(sheet),1,str5);
             str6 = strcat('G',num2str(4+4.*(sheet- 1)));
             col_header={'dissimilarity'};             
             xlswrite(excelfilename2,dissimilarity3(sheet),1,str6);

          case 4    
             str17 = strcat('B',num2str(5+4.*(sheet- 1)));
             str18 = strcat('E',num2str(5+4.*(sheet- 1)));
             str81 = strcat(str17,':',str18);
             writetable(t{sheet,s},'chall2.xlsx','sheet',1,'Range',str81,'WriteVariableNames', false);
             str7 = strcat('F',num2str(5+4.*(sheet- 1)));
             col_header={'entropy'};          
             xlswrite(excelfilename2,entropy4(sheet),1,str7);
             str8 = strcat('G',num2str(5+4.*(sheet- 1)));
             col_header={'dissimilarity'};             
             xlswrite(excelfilename2,dissimilarity4(sheet),1,str8);



      end
      
   end
   
end



  
  


                 
             

Attached File(s)


This post has been edited by modi123_1: 01 July 2019 - 05:31 AM
Reason for edit:: Added code.


Is This A Good Question/Topic? 0
  • +

Page 1 of 1