% heres the code for NGTDM
clc;
clear all;
close all;
I=imread('')%load image
I=single(handles.crop1);
d=2; % for distance equal to 2
greylevels=255;
[rowsize, colsize]=size(I);
oneskernel=ones(2*d+1,2*d+1);
kernel=oneskernel;
kernel(d+1,d+1)=0;
kerncount=(2*d+1)^2-1;
S=zeros(greylevels,1);
N=zeros(greylevels,1);
Ip1=I+1;
mask=sign(I-greylevels)+1;
convmask=conv2(mask,oneskernel,'same');
convmask=abs(sign(convmask)-1);
convimage=conv2(I,kernel,'same')/kerncount;
convimage=abs(I-convimage);
for row=(1+d):(rowsize-d)
for col=(1+d):(colsize-d)
if convmask(row,col)>0
index=Ip1(row,col);
S(index)=S(index)+convimage(row,col);
N(index)=N(index)+1;
end
end
end
R=sum(N);
[Ni,Nj]=meshgrid(N);
[Si,Sj]=meshgrid(S);
[i,j]=meshgrid([0:greylevels-1]);
ilessjsq=(i-j).^2;
Ni=Ni.*abs(sign(Nj));
Nj=Nj.*abs(sign(Ni));
coars=R*R/sum(N.*S);
Ng=nnz(N);
contr=sum(S)*sum(sum(Ni.*Nj.*ilessjsq))/R^3/Ng/(Ng-1);
busyn=sum(N.*S)/sum(sum(abs(i.*Ni-j.*Nj)))/R;
compl=sum(sum(abs(i-j).*(Ni.*Si+Nj.*Sj)./(Ni+Nj+eps)))/R;
stren=sum(sum((Ni+Nj).*ilessjsq))/(sum(S)+eps);
disp('NGTDM features _Coarseness');display(coars)
disp('NGTDM features _Contrast');display(contr)
disp('NGTDM features _Busyiness');display(busyn)
disp('NGTDM features _Complexity');display(compl)
disp('NGTDM features _Strength');display(stren)
set(handles.edit22,'String',coars);
set(handles.edit23,'String',contr);
set(handles.edit24,'String',busyn);
set(handles.edit25,'String',compl);
set(handles.edit26,'String',stren);
d=1; %for distance equal to 1
greylevels=255;
[rowsize, colsize]=size(I);
oneskernel=ones(2*d+1,2*d+1);
kernel=oneskernel;
kernel(d+1,d+1)=0;
kerncount=(2*d+1)^2-1;
S=zeros(greylevels,1);
N=zeros(greylevels,1);
Ip1=I+1;
mask=sign(I-greylevels)+1;
convmask=conv2(mask,oneskernel,'same');
convmask=abs(sign(convmask)-1);
convimage=conv2(I,kernel,'same')/kerncount;
convimage=abs(I-convimage);
for row=(1+d):(rowsize-d)
for col=(1+d):(colsize-d)
if convmask(row,col)>0
index=Ip1(row,col);
S(index)=S(index)+convimage(row,col);
N(index)=N(index)+1;
end
end
end
R=sum(N);
[Ni,Nj]=meshgrid(N);
[Si,Sj]=meshgrid(S);
[i,j]=meshgrid([0:greylevels-1]);
ilessjsq=(i-j).^2;
Ni=Ni.*abs(sign(Nj));
Nj=Nj.*abs(sign(Ni));
coars=R*R/sum(N.*S);
Ng=nnz(N);
contr=sum(S)*sum(sum(Ni.*Nj.*ilessjsq))/R^3/Ng/(Ng-1);
busyn=sum(N.*S)/sum(sum(abs(i.*Ni-j.*Nj)))/R;
compl=sum(sum(abs(i-j).*(Ni.*Si+Nj.*Sj)./(Ni+Nj+eps)))/R;
stren=sum(sum((Ni+Nj).*ilessjsq))/(sum(S)+eps);
disp('NGTDM features _Coarseness 1');display(coars)
disp('NGTDM features _Contrast 1');display(contr)
disp('NGTDM features _Busyiness 1');display(busyn)
disp('NGTDM features _Complexity 1');display(compl)
disp('NGTDM features _Strength 1');display(stren)
set(handles.edit27,'String',coars);
set(handles.edit28,'String',contr);
set(handles.edit29,'String',busyn);
set(handles.edit30,'String',compl);
set(handles.edit31,'String',stren);