赞
踩
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);
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,[]);%变成行向量
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.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。