• 大小: 475KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: Matlab
  • 标签:

资源简介

MATLAB 灰度共生矩阵 纹理特征提取 粗糙度、对比度、方向度等,源代码

资源截图

代码片段和文件信息

% function Texture = Tamuratexture(gray)
%计算Tamura纹理特征

% t0=cputime;
I0=imread(‘LENA.BMP‘);
I = rgb2gray(I0);
[NxNy] = size(I);
Ng=256;
G=double(I);
%计算粗糙度(coarseness)
Sbest=zeros(NxNy);
E0h=zeros(NxNy);
E0v=zeros(NxNy);
E1h=zeros(NxNy);
E1v=zeros(NxNy);
E2h=zeros(NxNy);
E2v=zeros(NxNy);
E3h=zeros(NxNy);
E3v=zeros(NxNy);
E4h=zeros(NxNy);
E4v=zeros(NxNy);
E5h=zeros(NxNy);
E5v=zeros(NxNy);
flag=0;

for i=1:Nx
    for j=2:Ny
        E0h(ij)=G(ij)-G(ij-1);
    end
end
E0h=E0h/2;

for i=1:Nx-1
    for j=1:Ny
        E0v(ij)=G(ij)-G(i+1j);
    end
end
E0v=E0v/2;

%图片大小必须大于4*4才能计算E1h、E1v
if (Nx<4||Ny<4)
    flag=1;
end
if(flag==0)
    for i=1:Nx-1
        for j=3:Ny-1
            E1h(ij)=sum(sum(G(i:i+1j:j+1)))-sum(sum(G(i:i+1j-2:j-1)));
        end
    end
    for i=2:Nx-2
        for j=2:Ny
            E1v(ij)=sum(sum(G(i-1:ij-1:j)))-sum(sum(G(i+1:i+2j-1:j)));
        end
    end
    E1h=E1h/4;
    E1v=E1v/4;
end


%图片大小必须大于8*8才能计算E2h、E2v
if (Nx<8||Ny<8)
    flag=1;
end
if(flag==0)
    for i=2:Nx-2
        for j=5:Ny-3
            E2h(ij)=sum(sum(G(i-1:i+2j:j+3)))-sum(sum(G(i-1:i+2j-4:j-1)));
        end
    end
    for i=4:Nx-4
        for j=3:Ny-1
            E2v(ij)=sum(sum(G(i-3:ij-2:j+1)))-sum(sum(G(i+1:i+4j-2:j+1)));
        end
    end
    E2h=E2h/16;
    E2v=E2v/16;
end


%图片大小必须大于16*16才能计算E3h、E3v
if (Nx<16||Ny<16)
    flag=1
end
if(flag==0)
    for i=4:Nx-4
        for j=9:Ny-7
            E3h(ij)=sum(sum(G(i-3:i+4j:j+7)))-sum(sum(G(i-3:i+4j-8:j-1)));
        end
    end
    for i=8:Nx-8
        for j=5:Ny-3
            E3v(ij)=sum(sum(G(i-7:ij-4:j+3)))-sum(sum(G(i+1:i+8j-4:j+3)));
        end
    end
    E3h=E3h/64;
    E3v=E3v/64;
end


%图片大小必须大于32*32才能计算E4h、E4v 
if (Nx<32||Ny<32)
    flag=1;
end
if(flag==0)
    for i=8:Nx-8
        for j=17:Ny-15
            E4h(ij)=sum(sum(G(i-7:i+8j:j+15)))-sum(sum(G(i-7:i+8j-16:j-1)));
        end
    end
    for i=16:Nx-16
        for j=9:Ny-7
            E4v(ij)=sum(sum(G(i-15:ij-8:j+7)))-sum(sum(G(i+1:i+16j-8:j+7)));
        end
    end
    E4h=E4h/256;
    E4v=E4v/256;
end


%图片大小必须大于64*64才能计算E5h、E5v
if (Nx<64||Ny<64)
    flag=1;
end
if(flag==0)
    for i=16:Nx-16
        for j=33:Ny-31
            E5h(ij)=sum(sum(G(i-15:i+16j:j+31)))-sum(sum(G(i-15:i+16j-32:j-31)));
        end
    end
    for i=32:Nx-32
        for j=17:Ny-15
            E5v(ij)=sum(sum(G(i-31:ij-16:j+15)))-sum(sum(G(i+1:i+32j-16:j+15)));
        end
    end
    E5h=E5h/1024;
    E5v=E5v/1024;
end

for i=1:Nx
    for j=1:Ny
        [maxvindex]=max([E0h(ij)E0v(ij)E1h(ij)E1v(ij)E2h(ij)E2v(ij)E3h(ij)E3v(ij)E4h(ij)E4v(ij)E5h(ij)E5v(ij)]);
        k=floor((index+1)/2);
        Sbest(ij)=2.^k;
    end
end
Fcoarseness=sum(sum(Sbest))/(Nx*Ny);
%计算对比度
[countsgraylevels]=imhist(I);
PI=counts/(Nx*Ny);
averagevalue=sum(g

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     786486  2000-08-28 12:02  Tamuratexture\LENA.BMP

     文件       5051  2013-07-17 21:01  Tamuratexture\Tamuratexture.m

     目录          0  2013-07-17 21:11  Tamuratexture

----------- ---------  ---------- -----  ----

               791537                    3


评论

共有 条评论