区域纹理特征的度量

区域纹理特征的度量

参照书籍《数字图像处理(冈萨雷斯)》

第一步:自定义两个函数 statistical 和statmoments(我一开始只定义一个函数导致程序出现错误)

第二步:将自定义的两个函数分别写入两个脚本文件中。

第一个函数:

function [t]=statxture(f,scale)

 

%STATXTURE Computes statistical measures of texture in an image.

% T = STATXURE(F, SCALE) computes six measures of texture from an

% image (region) F. Parameter SCALE is a 6-dim row vector whose

% elements multiply the 6 corresponding elements of T for scaling

% purposes. If SCALE is not provided it defaults to all 1s. The

% output T is 6-by-1 vector with the following elements:

% T(1) = Average gray level

% T(2) = Average contrast

% T(3) = Measure of smoothness

% T(4) = Third moment

% T(5) = Measure of uniformity

% T(6) = Entropy

% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins

% Digital Image Processing Using MATLAB, Prentice-Hall, 2004

% $Revision: 1.5 $ $Date: 2004/11/04 22:33:43 $

if nargin==1

scale(1:6)=1;

else

scale=scale(:)'; % Make sure it's a row vector

end

%Obtain histogram and normalize it.

p=imhist(f); %pÊÇ256*1µÄÁÐÏòÁ¿

p=p./numel(f);

L=length(p);

% Compute the three moments. We need the unnormalized ones

% from function statemoments. There are in vector mu.

[v,mu]=statmoments(p,3);

%¼ÆËãÁù¸öÎÆÀíÌØÕ÷ Compute the six texture measures

t(1)=mu(1); %ƽ¾ùÖµ Average gray level

t(2)=mu(2).^0.5; %±ê×¼²î Standard deviation

varn=mu(2)/(L-1)^2; % First normalize the variance to [0 1] by dividing it by (L-1)^2.

t(3)=1-1/(1+varn); %ƽ»¬¶ÈÊ×ÏÈΪ£¨0~1£©Çø¼äͨ¹ý³ýÒÔ£¨L-1£©^2½«±äÁ¿±ê×¼»¯

t(4)=mu(3)/(L-1)^2; %Èý½×¾Ø£¨Í¨¹ý³ýÒÔ£¨L-1£©^2½«±äÁ¿±ê×¼»¯£© Third moment (normalized by (L-1)^2 also)

t(5)=sum(p.^2); %Ò»ÖÂÐÔ Uniformity

t(6)=-sum(p.*(log2(p+eps))); %ìØ Entropy

T=[t(1) t(2) t(3) t(4) t(5) t(6)]

%Ëõ·ÅÖµ£¬Ä¬ÈÏΪ1 Scale the value

t=t.*scale;

end

 

第二个:自定义函数

function [v,unv]=statmoments(p,n)

Lp=length(p);

if (Lp~=256)&(Lp~=65536)

error('p must be a 256- or 65536-element vector.');

end

G=Lp-1;

p=p/sum(p);p=p(:);

z=0:G;

z=z./G;

m=z*p;

z=z-m;

v=zeros(1,n);

v(1)=m;

for j=2:n

v(j)=(z.^j)*p;

end

if nargout>1

unv=zeros(1,n);

unv(1)=m.*G;

for j=2:n

unv(j)=((z*G).^j)*p

end

end

end

第三步:将读入图片的的格式改为灰度图像,这个不能处理除灰度图像以外的图像。

你可能感兴趣的:(区域纹理特征的度量)