区域纹理特征的度量

该博客介绍了如何使用MATLAB计算图像(区域)的纹理特征,主要依据《数字图像处理(冈萨雷斯)》一书。通过自定义statxture和statmoments两个函数,计算平均灰度水平、标准差、平滑度、第三矩、均匀性和熵等六个纹理度量指标。statxture函数首先获取直方图并归一化,然后调用statmoments函数计算三个矩,最后计算并返回六个纹理特征。statmoments函数则用于计算未归一化的矩。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

区域纹理特征的度量

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

第一步:自定义两个函数 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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值