%A=imread('TB.jpg');A=double(A(:,:,1));
%A=imread('leiohyalinization.png');A=double(A(:,:,2));
A=imread('leio.png');A=double(A(:,:,2));

%A=filter2(ones(7)/49,A,'same');
A=uint8(A);

%Get image dimentions and GL max and min value
maximum=max(max(A));
minimum=min(min(A));
[rm,cm]=size(A);

CM=zeros(maximum-minimum+1);
%Compute the GLCM for my input image A
for i=1:rm
    for j=1:cm-1
            %  if A & B>0
            x=A(i,j);
            y=A(i,j+1);
            CM(x-minimum+1,y-minimum+1)=CM(x-minimum+1,y-minimum+1)+1;
            CM(y-minimum+1,x-minimum+1)=CM(y-minimum+1,x-minimum+1)+1;
            % end        
    end
end
%Normalisation of the Co-ocurence Matrix 
CM=CM/(sum(sum(CM)));

    
%Computation of texture measures Entropy: Hxy, Homogeneity:Hom, Contrast: Contr
i=0;j=0;Hxy=0;Hom=0;Contr=0;
 for i=1:(maximum-minimum+1)
	for j=1:(maximum-minimum+1),
		if  CM(i,j)>0 
			
            Hxy=Hxy-(CM(i,j))*log2(CM(i,j));
            Hom=Hom+CM(i,j)/(1+abs(i-j));
            Contr=Contr+((i-j)^2)*CM(i,j);
            
        end
    end
end

%Visualisation of the GLCM taking the log of it
%-----------------------------------------------------------------------------
for k=1:(maximum-minimum+1)
	for l=1:(maximum-minimum+1),
		if  CM(k,l)>0 
            CCM(k,l)=-log2(CM(k,l));
        end
    end
end
    %surfl(CCM);shading interp; colormap bone
    figure, imagesc(CCM)
-----------------------------------------------------------------------------

%Extraction of texture measures
fprintf('%f\t%f\t%f\n',Hxy,Hom,Contr);

 