根据特征索引号提取某一系列的特征值

     对样本进行分类时,需要提取该样本的特征。由于AdaBoost分类器是由一系列的基于一系列单个特征的弱分类器组成的,因此只需要提取弱分类器所需要的特征即可。以前采取的方式是,提取所有的特征,分类时获得所需要的特征即可;该过程提取了大量没有使用的特征,这些没有使用的特征花费了大量的计算,是无效计算。现在需要解决这个问题。当需要某个特征时,则计算该特征;不需要该特征时,则不计算该特征。但该方法也存在重复计算问题。比如计算Gabor变换特征,需要先进行Gabor变换,然后再计算特征某特征A,或者某特征B;如果同时需要计算两个特征A和B,那么对图像进行了两次Gabor变换,其中有一次属重复计算。

     现在采取折中的方式。当需要某特征时,则计算该系列的所有特征。

%  
%  identifySeriesFeatureByIndex
%  
%  计算该特征编号所属的一个系列的特征值
%  
%  seriesFeatures 提取的包含index号特征的系列特征
%  seriesIndex    该系列特征在该方法中的绝对索引位置
%  
%   2007 - 11 - 06
function [seriesFeatures,seriesIndex]
= identifySeriesFeatureByIndex(image,index)
feaCntSequence
= [ 1   12   12   12   64   176   15   64   15   21 ];   %  每种方法能够获取的特征数量列表
feaCntCumSequence
= cumsum(feaCntSequence);         %  累计特征数量
methodCnt
= length(feaCntCumSequence);              %  特征提取方法的种类 

%  特征提取方法索引号
%  索引与方法名称对应关系为
%   1   RGB颜色空间特征值      
%   2   HSI颜色空间特征值     
%   3   NTSC颜色空间特征值    
%   4   gabor变换提取的纹理特征 
%   5   灰度共生矩阵纹理特征值
%   6   灰度 - 梯度共生矩阵纹理特征  
%   7   灰度差分统计特征值: 
%   8   灰度行程长度统计方法
%   9   不变矩特征
methodIndex
= 0 ;    
if ( (index < feaCntCumSequence( 1 ))  ||  (index >= feaCntCumSequence(methodCnt)) )
    error([
' 特征编号( '  num2str(index)  ' )必须在区间[ '  num2str(feaCntCumSequence( 1 ))...
         
'   '  num2str(feaCntCumSequence(methodCnt) - 1 ' ]中! ' ]);
end

for  cnt = 1 :methodCnt  %  由索引号确定提取特征的方法
    
if ( (index >= feaCntCumSequence(cnt))  &&  (index < feaCntCumSequence(cnt + 1 )) )
        methodIndex
= cnt;
        
break ;
    end
end

%  特征提取方法内部索引号,通过该索引求取特征提取方法的参数
%  比如,第25号特征为第三种方法(NTSC颜色)的第1个特征(Y均值)
%  故methodIndex = 3 ,innerMethodIndex = 1
%  第47号特征为第四种方法(Gabor)的第11个特征
%  此时methodIndex = 4 ,innerMethodIndex = 11
%  通过索引11计算参数:频率索引( 1 ),频率值( 0.5 );方向索引( 6 ),方向( 1.9635 )
%  第234号特征为灰度共生矩阵纹理第134个特征
%  此时methodIndex = 4 ,innerMethodIndex = 134
%  通过索引134可计算参数:位置算子索引( 16 ),位置算子([ 5   2 ]),该位置算子上第2个特征
innerMethodIndex 
=  index - feaCntCumSequence(cnt) + 1 ;

if ( methodIndex > 3   ||  methodIndex < 9  )  %  纹理特征需要针对灰度图像
    grayimage
= rgb2gray(image);
end 
switch ( methodIndex )
    
case   1         %  RGB颜色空间特征值
        [seriesFeatures,seriesIndex]
= identifyColorFeatureByIndex(image, ' RGB ' ,innerMethodIndex);
    
case   2         %  HSI颜色空间特征值
        [seriesFeatures,seriesIndex]
= identifyColorFeatureByIndex(image, ' HSI ' ,innerMethodIndex);
    
case   3         %  NTSC颜色空间特征值
        [seriesFeatures,seriesIndex]
= identifyColorFeatureByIndex(image, ' NTSC ' ,innerMethodIndex);        
    
case   4         %  Gabor变换提取的纹理特征
        [seriesFeatures,seriesIndex]
= identifyGaborFeatureByIndex(grayimage,innerMethodIndex);
    
case   5         %  灰度共生矩阵纹理特征值
        [seriesFeatures,seriesIndex]
= identifyGLCMFeatureByIndex(grayimage,innerMethodIndex);
    
case   6         %  灰度 - 梯度共生矩阵纹理特征
        [seriesFeatures,seriesIndex]
= identifyGGLCMFeatureByIndex(grayimage,innerMethodIndex);
    
case   7         %  灰度差分统计特征值
        [seriesFeatures,seriesIndex]
= identifyGDSFeatureByIndex(grayimage,innerMethodIndex);
    
case   8         %  灰度行程长度统计方法
        [seriesFeatures,seriesIndex]
= identifyGRLSFeatureByIndex(grayimage,innerMethodIndex);
    
case   9         %  不变矩特征
        [seriesFeatures,seriesIndex]
= identifyIMFeatureByIndex(image,innerMethodIndex);
    otherwise
        error(
' 方法编号错误! ' );
end

seriesIndex
= feaCntCumSequence(methodIndex) - 1 + seriesIndex;  %  提取的系列特征的绝对索引位置


%  根据特征索引号确定 RGB、HSI、NTSC颜色空间特征值
%  colorspacename 仅能取值 ' RGB ' , ' HSI ' , ' NTSC '
%  index 应在1 - 12  之间
%  seriesFeatures 提取的包含index号特征的系列特征
%  seriesIndex    该系列特征在该方法中的相对位置
function [seriesFeatures,seriesIndex]
= identifyColorFeatureByIndex(image,colorspacename,index)
featureSpaceSize
= 12 ;                     %  特征空间维数
[seriesFeatures]
= extractColorFeature(image,colorspacename); %  提取特征 
seriesIndex
= 1 :featureSpaceSize;


%  根据特征索引号确定 Gabor变换提取的纹理特征
%  seriesFeatures 提取的包含index号特征的系列特征
%  seriesIndex    该系列特征在该方法中的相对索引位置
function [seriesFeatures,seriesIndex]
= identifyGaborFeatureByIndex(image,index)
fList
= [ 0.5   0.25   0.125   0.1 ];    %  Gabor变换的频率列表
thetaList
= (( 0 : 7 ) / 8 ). * pi;       %  Gabor变换方向(theta)列表
fLen
= length(fList);            %  频率数量
thetaLen
= length(thetaList);    %  方向数量
featureSpaceSize
= 2 ;            %  Gabor变换 特征空间大小

paramIndex
= floor((index - 1 ) / featureSpaceSize) + 1 ; %  确定参数的索引号
fIndex
= ceil(paramIndex / thetaLen);         %  参数索引:频率
thetaIndex
= mod(paramIndex - 1 ,thetaLen) + 1 %  参数索引:方向
[seriesFeatures]
= extractGaborFeature(image,fList(fIndex),thetaList(thetaIndex));
seriesIndex
= ((paramIndex - 1 ) * featureSpaceSize + 1 ):(paramIndex * featureSpaceSize);

%  根据特征索引号确定 灰度共生矩阵纹理特征值
%  seriesFeatures 提取的包含index号特征的系列特征
%  seriesIndex    该系列特征在该方法中的相对索引位置
function [seriesFeatures,seriesIndex]
= identifyGLCMFeatureByIndex(image,index)
%  位置算子
offset
= [ 0   1 ; 0   5 ; 1   0 ; 5   0 ; 1   1 ; 1   - 1 ; 5   5 ; 5   - 5 ; 2   5 ; 2   - 5 ; 4   5 ; 4   - 5 ; 5   2 ; 5   - 2 ; 5   4 ; 5   - 4 ];
featureSpaceSize
= 11 ;                      %  灰度共生矩阵 特征空间大小
offsetIndex
= floor((index - 1 ) / featureSpaceSize) + 1 ; %  参数索引:位置算子
[seriesFeatures]
= extractCoOccureTextFeature(image,offset(offsetIndex,:));
seriesIndex
= ((offsetIndex - 1 ) * featureSpaceSize + 1 ):(offsetIndex * featureSpaceSize);


%  根据特征索引号确定 灰度 - 梯度共生矩阵纹理特征
%  seriesFeatures 提取的包含index号特征的系列特征
%  seriesIndex    该系列特征在该方法中的相对索引位置
function [seriesFeatures,seriesIndex]
= identifyGGLCMFeatureByIndex(image,index)
featureSpaceSize
= 15 ;                      %  灰度 - 梯度共生矩阵 特征空间大小
[seriesFeatures]
= extractGGLCMSFeature(image);
seriesIndex
= 1 :featureSpaceSize;
 
%  根据特征索引号确定 灰度差分统计特征值
%  seriesFeatures 提取的包含index号特征的系列特征
%  seriesIndex    该系列特征在该方法中的相对索引位置
function [seriesFeatures,seriesIndex]
= identifyGDSFeatureByIndex(image,index)
%  灰度差分统计的位置算子
offset
= [ 0   1 ; 0   3 ; 0   5 ; 1   0 ; 3   0 ; 5   0 ; 1   1 ; 2   2 ; 4   4 ; 5   5 ; 1   3 ; 3   1 ; 2   4 ; 4   2 ; 3   5 ; 5   3 ];
featureSpaceSize
= 4 ;                       %  灰度差分统计 特征空间维数
offsetIndex
= floor((index - 1 ) / featureSpaceSize) + 1 ; %  参数索引:位置算子
[seriesFeatures]
= extractGrayDifferStatFeature(image,offset(offsetIndex,:));
seriesIndex
= ((offsetIndex - 1 ) * featureSpaceSize + 1 ):(offsetIndex * featureSpaceSize);


%  根据特征索引号确定 灰度行程长度统计方法
%  seriesFeatures 提取的包含index号特征的系列特征
%  seriesIndex    该系列特征在该方法中的相对索引位置
function [seriesFeatures,seriesIndex]
= identifyGRLSFeatureByIndex(image,index)
thetaList
= [ 0  pi / 4  pi / 2 ];      %  默认 行程方向
featureSpaceSize
= 5 ;           %  行程长度统计 特征空间维数
thetaIndex
= floor((index - 1 ) / featureSpaceSize) + 1 ; %  参数索引:行程方向
[seriesFeatures]
= extractGRLMFeature(image,thetaList(thetaIndex));
seriesIndex
= ((thetaIndex - 1 ) * featureSpaceSize + 1 ):(thetaIndex * featureSpaceSize);


%  根据特征索引号确定 不变矩特征
%  seriesFeatures 提取的包含index号特征的系列特征
%  seriesIndex    该系列特征在该方法中的相对索引位置
function [seriesFeatures,seriesIndex]
= identifyIMFeatureByIndex(image,index)
colorspacesize
= size(image, 3 );             %  颜色平面数量,灰度图像为1,彩色图像为3           
featureSpaceSize
= 7 ;                       %  不变矩特征 特征维数
spaceIndex
= floor((index - 1 ) / featureSpaceSize) + 1 ; %  参数索引:颜色平面索引
[seriesFeatures]
= extractInvariantMomentFeature(image,spaceIndex);
seriesIndex
= ((spaceIndex - 1 ) * featureSpaceSize + 1 ):(spaceIndex * featureSpaceSize);


测试100幅图片,原始方法需耗时132s,现在耗时34s,只有原来的1/4。但仍然重复计算了一些没有使用的特征。

仍需要改进。

 

由重新组织样本,修正特征、增加特征,已经花费了接近三周。速度太慢了。

余下工作:构建 级联AdaBoost 分类器(需在11月15日前完成)

                   12月前完成所有基于新样本的重复试验

                   12月 :prepare the paper

                    1月   :write paper

                  

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值