当前位置:   article > 正文

lbp特征的matlab实现_matlab lbp函数

matlab lbp函数

matlab自带函数extractLBPFeatures可以很好地提取lbp特征,但是不好进行改进,因此在网上找了人家用maltab实现的lbp特征提取,但是性能比自带函数稍差,代码主要来自
http://www.cse.oulu.fi/wsgi/MVG/Downloads/LBPMatlab
针对lbp特征提取部分,有稍微进行修改,代码如下:
testmylbp.m

%lbp的参数是以下,直接在这改,就不用在函数里一个一个的改动了
lbpcellsize=48;
mapping=getmapping(8,'u2');%以统一模式lbp去映射 
radius=1;
neighbors=8;
mode='L2';%h仅仅只是直方图,没有归一化,‘nh’是L1归一化,'L2'是L2归一化

image=imread('rice.png');
imageSize=[256 256];
image = imresize(image,imageSize); %缩放
 % LBP
    [row,col,m]=size(image);
    if m>1
        image=rgb2gray(image);
    end   
    
lbpfeature=mylbp(image,row,col,lbpcellsize,lbpcellsize,radius,neighbors,mapping,mode);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

mylbp.m(可以针对子块提取lbp特征,需要调用lbp函数)


function H2=mylbp(img,row,col,blocksizerow,blocksizecol,radius,neighbors,mapping,mode)
% [row,col,k]=size(img);
% if  k>1
%      img=rgb2gray(img);
% end
new_row = floor(row/blocksizerow) * blocksizerow;%ceil是向上取整,floor向下
new_col = floor(col/blocksizecol) * blocksizecol;
new_img = imresize(img, [new_row new_col], 'bilinear');%以双线性插值来缩放

[y_row y_col dim] = size(new_img);
row_blk_num = y_row/blocksizerow;  % 3
col_blk_num = y_col/blocksizecol;  % 6

blocks = 1;
for i = 1:row_blk_num
    for j = 1:col_blk_num
%         disp(blocks);
        block = new_img((i - 1) * blocksizerow + 1 : i * blocksizerow, (j - 1) * blocksizecol + 1 : j * blocksizecol, :);
        H1(blocks,:)=lbp(block,radius,neighbors,mapping,mode);
        
%         imshow(block);
        %imwrite(block, ['./' num2str(blocks) '.jpg']);
        blocks = blocks + 1;
    end
end
H2=reshape(H1,1,[]);%变成行向量
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

lbp.m 代码如下

%LBP returns the local binary pattern image or LBP histogram of an image.
%  J = LBP(I,R,N,MAPPING,MODE) returns either a local binary pattern
%  coded image or the local binary pattern histogram of an intensity
%  image I. The LBP codes are computed using N sampling points on a 
%  circle of radius R and using mapping table defined by MAPPING.
  • 1
  • 2
  • 3
  • 4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/898915
推荐阅读
相关标签
  

闽ICP备14008679号