在网上找了人家用maltab实现的lpq特征提取,代码主要来自
http://www.cse.oulu.fi/wsgi/MVG/Downloads/LPQMatlab
针对lpq特征提取部分,有稍微进行修改,代码如下:
testlqp.m

%lpq的参数
lpqcellsize=50;%子块大小
winSize=3;
decorr=1;
freqestim=1;
mode='nh';mage=imread('rice.png');
imageSize=[256 256];
image = imresize(image,imageSize); %缩放% LBP[row,col,m]=size(image);if m>1image=rgb2gray(image);end   lpqfeatures=mylpq(image,row,col,lpqcellsize,lpqcellsize,winSize,decorr,freqestim,mode);

mylpq.m

% % clear;
% % clc;
% %  %分成64x64的子块
% % img = imread('rice.png');
% % mapping=getmapping(8,'u2');%以统一模式lbp去映射
% % radius=1;
% % neighbors=8;
% % mode='h'
% % [row,col,k]=size(img);
% % if  k>1
% %      img=rgb2gray(img);
% % end
% %
% % %% resize the image into the new size with 500x*500y
% %
% % blocksizerow=64;
% % blocksizecol=64;
% %
% % new_row = ceil(row/blocksizerow) * blocksizerow;%ceil是向上取整
% % new_col = ceil(col/blocksizecol) * blocksizecol;
% %
% % % new_r_img = imresize(r_img, [new_row new_col], 'bilinear');
% % % new_g_img = imresize(g_img, [new_row new_col], 'bilinear');
% % % new_b_img = imresize(b_img, [new_row new_col], 'bilinear');
% %
% % 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,[]);%变成行向量function H2=mylpq(img,row,col,blocksizerow,blocksizecol,winSize,decorr,freqestim,mode)
% [row,col,k]=size(img);
% if  k>1
%      img=rgb2gray(img);
% end
new_row = ceil(row/blocksizerow) * blocksizerow;%ceil是向上取整
new_col = ceil(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;  % 6blocks = 1;
for i = 1:row_blk_numfor j = 1:col_blk_num
%         disp(blocks);block = new_img((i - 1) * blocksizerow + 1 : i * blocksizerow, (j - 1) * blocksizecol + 1 : j * blocksizecol, :);H1(blocks,:)=lpq(block,winSize,decorr,freqestim,mode);%         imshow(block);%imwrite(block, ['./' num2str(blocks) '.jpg']);blocks = blocks + 1;end
end
H2=reshape(H1,1,[]);%变成行向量

lpq.m

function LPQdesc = lpq(img,winSize,decorr,freqestim,mode)
% Funtion LPQdesc=lpq(img,winSize,decorr,freqestim,mode) computes the Local Phase Quantization (LPQ) descriptor
% for the input image img. Descriptors are calculated using only valid pixels i.e. size(img)-(winSize-1).
%
% Inputs: (All empty or undefined inputs will be set to default values)
% img = N*N uint8 or double, format gray scale image to be analyzed.
% winSize = 1*1 double, size of the local window. winSize must be odd number and greater or equal to 3 (default winSize=3).
% decorr = 1*1 double, indicates whether decorrelation is used or not. Possible values are:
%                      0 -> no decorrelation,
%            (default) 1 -> decorrelation
% freqestim = 1*1 double, indicates which method is used for local frequency estimation. Possible values are:
%               (default) 1 -> STFT with uniform window (corresponds to basic version of LPQ)
%                         2 -> STFT with Gaussian window (equals also to Gaussian quadrature filter pair)
%                         3 -> Gaussian derivative quadrature filter pair.
% mode = 1*n char, defines the desired output type. Possible choices are:
%        (default) 'nh' -> normalized histogram of LPQ codewords (1*256 double vector, for which sum(result)==1)
%                  'h'  -> un-normalized histogram of LPQ codewords (1*256 double vector)
%                  'im' -> LPQ codeword image ([size(img,1)-r,size(img,2)-r] double matrix)
%
% Output:
% LPQdesc = 1*256 double or size(img)-(winSize-1) uint8, LPQ descriptors histogram or LPQ code image (see "mode" above)
%
% Example usage:
% img=imread('cameraman.tif');
% LPQhist = lpq(img,3);
% figure; bar(LPQhist);
%% Version published in 2010 by Janne Heikkil?, Esa Rahtu, and Ville Ojansivu
% Machine Vision Group, University of Oulu, Finland%% Defaul parameters
% Local window size
if nargin<2 || isempty(winSize)winSize=3; % default window size 3
end% Decorrelation
if nargin<3 || isempty(decorr)   decorr=1; % use decorrelation by default
end
rho=0.90; % Use correlation coefficient rho=0.9 as default% Local frequency estimation (Frequency points used [alpha,0], [0,alpha], [alpha,alpha], and [alpha,-alpha])
if nargin<4 || isempty(freqestim)freqestim=1; %use Short-Term Fourier Transform (STFT) with uniform window by default
end
STFTalpha=1/winSize;  % alpha in STFT approaches (for Gaussian derivative alpha=1)
sigmaS=(winSize-1)/4; % Sigma for STFT Gaussian window (applied if freqestim==2)
sigmaA=8/(winSize-1); % Sigma for Gaussian derivative quadrature filters (applied if freqestim==3)% Output mode
if nargin<5 || isempty(mode)mode='nh'; % return normalized histogram as default
end% Other
convmode='valid'; % Compute descriptor responses only on part that have full neigborhood. Use 'same' if all pixels are included (extrapolates image with zeros).%% Check inputs
if size(img,3)~=1error('Only gray scale image can be used as input');
end
if winSize<3 || rem(winSize,2)~=1error('Window size winSize must be odd number and greater than equal to 3');
end
if sum(decorr==[0 1])==0error('decorr parameter must be set to 0->no decorrelation or 1->decorrelation. See help for details.');
end
if sum(freqestim==[1 2 3])==0error('freqestim parameter must be 1, 2, or 3. See help for details.');
end
if sum(strcmp(mode,{'nh','h','im'}))==0error('mode must be nh, h, or im. See help for details.');
end%% Initialize
img=double(img); % Convert image to double
r=(winSize-1)/2; % Get radius from window size
x=-r:r; % Form spatial coordinates in window
u=1:r; % Form coordinates of positive half of the Frequency domain (Needed for Gaussian derivative)%% Form 1-D filters
if freqestim==1 % STFT uniform window% Basic STFT filtersw0=(x*0+1);w1=exp(complex(0,-2*pi*x*STFTalpha));w2=conj(w1);elseif freqestim==2 % STFT Gaussian window (equals to Gaussian quadrature filter pair)% Basic STFT filtersw0=(x*0+1);w1=exp(complex(0,-2*pi*x*STFTalpha)); w2=conj(w1);% Gaussian windowgs=exp(-0.5*(x./sigmaS).^2)./(sqrt(2*pi).*sigmaS);% Windowed filtersw0=gs.*w0;w1=gs.*w1;w2=gs.*w2;% Normalize to zero mean w1=w1-mean(w1);w2=w2-mean(w2);elseif freqestim==3 % Gaussian derivative quadrature filter pair% Frequency domain definition of filtersG0=exp(-x.^2*(sqrt(2)*sigmaA)^2);G1=[zeros(1,length(u)),0,u.*exp(-u.^2*sigmaA^2)];% Normalize to avoid small numerical values (do not change the phase response we use)G0=G0/max(abs(G0));   G1=G1/max(abs(G1));% Compute spatial domain correspondences of the filtersw0=real(fftshift(ifft(ifftshift(G0))));w1=fftshift(ifft(ifftshift(G1)));w2=conj(w1);% Normalize to avoid small numerical values (do not change the phase response we use) w0=w0/max(abs([real(max(w0)),imag(max(w0))]));w1=w1/max(abs([real(max(w1)),imag(max(w1))]));w2=w2/max(abs([real(max(w2)),imag(max(w2))]));
end%% Run filters to compute the frequency response in the four points. Store real and imaginary parts separately
% Run first filter
filterResp=conv2(conv2(img,w0.',convmode),w1,convmode);
% Initilize frequency domain matrix for four frequency coordinates (real and imaginary parts for each frequency).
freqResp=zeros(size(filterResp,1),size(filterResp,2),8);
% Store filter outputs
freqResp(:,:,1)=real(filterResp);
freqResp(:,:,2)=imag(filterResp);
% Repeat the procedure for other frequencies
filterResp=conv2(conv2(img,w1.',convmode),w0,convmode);
freqResp(:,:,3)=real(filterResp);
freqResp(:,:,4)=imag(filterResp);
filterResp=conv2(conv2(img,w1.',convmode),w1,convmode);
freqResp(:,:,5)=real(filterResp);
freqResp(:,:,6)=imag(filterResp);
filterResp=conv2(conv2(img,w1.',convmode),w2,convmode);
freqResp(:,:,7)=real(filterResp);
freqResp(:,:,8)=imag(filterResp);% Read the size of frequency matrix
[freqRow,freqCol,freqNum]=size(freqResp);%% If decorrelation is used, compute covariance matrix and corresponding whitening transform
if decorr == 1% Compute covariance matrix (covariance between pixel positions x_i and x_j is rho^||x_i-x_j||)[xp,yp]=meshgrid(1:winSize,1:winSize);pp=[xp(:) yp(:)];dd=dist(pp,pp');C=rho.^dd;% Form 2-D filters q1, q2, q3, q4 and corresponding 2-D matrix operator M (separating real and imaginary parts)q1=w0.'*w1;q2=w1.'*w0;q3=w1.'*w1;q4=w1.'*w2;u1=real(q1); u2=imag(q1);u3=real(q2); u4=imag(q2);u5=real(q3); u6=imag(q3);u7=real(q4); u8=imag(q4);M=[u1(:)';u2(:)';u3(:)';u4(:)';u5(:)';u6(:)';u7(:)';u8(:)'];% Compute whitening transformation matrix VD=M*C*M';A=diag([1.000007 1.000006 1.000005 1.000004 1.000003 1.000002 1.000001 1]); % Use "random" (almost unit) diagonal matrix to avoid multiple eigenvalues.  [U,S,V]=svd(A*D*A);% Reshape frequency responsefreqResp=reshape(freqResp,[freqRow*freqCol,freqNum]);% Perform whitening transformfreqResp=(V.'*freqResp.').';% Undo reshapefreqResp=reshape(freqResp,[freqRow,freqCol,freqNum]);
end%% Perform quantization and compute LPQ codewords
LPQdesc=zeros(freqRow,freqCol); % Initialize LPQ code word image (size depends whether valid or same area is used)
for i=1:freqNumLPQdesc=LPQdesc+(double(freqResp(:,:,i))>0)*(2^(i-1));
end%% Switch format to uint8 if LPQ code image is required as output
if strcmp(mode,'im')LPQdesc=uint8(LPQdesc);
end%% Histogram if needed
if strcmp(mode,'nh') || strcmp(mode,'h')LPQdesc=hist(LPQdesc(:),0:255);
end%% Normalize histogram if needed
if strcmp(mode,'nh')LPQdesc=LPQdesc/sum(LPQdesc);
end

lpq特征的matlab实现相关推荐

  1. 计算机视觉--GIST特征及其MATLAB代码实现

    原论文官网: Spatial envelopehttp://people.csail.mit.edu/torralba/code/spatialenvelope/ 代码下载:csdn - 安全中心ht ...

  2. 细胞空间结构特征之-细胞集群特征(Matlab实现)

    本文的目的是根据细胞的分割图像计算一些特征用于描述细胞的集群情况,细胞集群特征是细胞空间结构特征的一种,使用的编程工具为Matlab 2018b. 本文中使用例子为TCGA细胞分割数据集中的一张,原始 ...

  3. matlab怎么显示特征脸,matlab表情识别 Matlab表情识别,特征脸[1 ]作为面部表情分类的方法 联合开发网 - pudn.com...

    matlab表情识别 所属分类:其他 开发工具:matlab 文件大小:4575KB 下载次数:23 上传日期:2019-03-11 20:20:45 上 传 者:bbqQq 说明:  Matlab表 ...

  4. matlab怎么匹配特征参数,sift特征匹配matlab

    首先对彩色壁画图像提取 SIFT 特征 点与特征向量,然后对每个特征点提取 HSI 彩色特征,最后按定义的相似性度 量公式计算两个特征点之间的距离,确定二者是否匹配.... 通过计算机中 的 Matl ...

  5. 计算特征数据matlab代码,科学网—MATLAB特征提取代码 - 蒋样明的博文

    PS=imresize(PS,[300,300],'bilinear');%归一化大小 PS=rgb2gray(PS); [m,n]=size(PS);                       % ...

  6. matlab特征匹配,MATLAB图像处理-特征提取-形状特征 方法小结

    (一)特点 各种基于形状特征的检索方法都可以比较有效地利用图像中感兴趣的目标来进行检索,但它们也有一些共同的问题,包括:①目前基于形状的检索方法还缺乏比较完善的数学模型:②如果目标有变形时检索结果往往 ...

  7. 游程理论提取灾害事件特征---基于MATLAB语言的编程实现

    变强从来不是因为社会的阳光面,而是为了当社会的阴暗面向我或我们在意的人伸手时,我们能够干净利索地绞杀它们. 游程理论识别灾害事件---基于MATLAB语言的编程实现 前言 1. 版本 2. 摘要 3. ...

  8. sift特征匹配源码matlab,SIFT特征匹配 MATLAB 实现

    [实例简介] matlab实现的SIFT特征提取的全代码,可运行 可测试 很不错的sift原代码 [实例截图] [核心代码] sift的matlab代码,是最新的,效果不错,其中有很多详细说明,可以试 ...

  9. 【眼底检测】视网膜动静脉血管检测和特征计算matlab仿真

    目录 1.软件版本 2.系统程序 3.部分源码 4.仿真结论 5.参考文献 1.软件版本 matlab2019a

最新文章

  1. python3 sys.stdout.write print 区别
  2. 【人物】徐小平:远离创业的3个死亡陷阱
  3. 【Tyvj3500】【BZOJ1031】字符加密,后缀数组
  4. 快手:“我有一把大宝剑”
  5. python函数归值_Python函数基础与函数递归
  6. Linux内核RCU(Read Copy Update)锁简析-前传
  7. java try 性能损耗_Java 中的 try catch 影响性能吗?
  8. 用AtomicStampedReference解决ABA问题
  9. 51单片机直流电机调速
  10. MyBatis简介及下载
  11. 【限流算法】java实现滑动时间窗口算法
  12. 解决远程桌面最小化时,自动化UI(鼠标、键盘)指令不工作问题
  13. 第七届蓝桥杯大赛个人赛--小明被绑架到X星球的巫师W那里
  14. 阿里云PHP SDK(升级版)使用说明:
  15. RPA or 爬虫?模拟人工访问某服务平台—增加空间的访问量
  16. ATM异地跨行取钱收费大比拼
  17. 机械键盘组合键失灵、Windows键失灵
  18. android获取定位并标点,Android Studio 中实现高德定位并获取相应信息
  19. 大学物理 复习指导、公式推导精简过程、结论归纳 第四章 刚体和流体的运动
  20. php连接不同编码oracle,PHP连接Oracle出现中文乱码问题

热门文章

  1. Android基于腾讯云实时音视频实现类似微信视频通话最小化悬浮
  2. 更改NuGet包缓存位置
  3. 【iMessage苹果证书协议版本】软件安装APNSD-AppID配置中创建结构
  4. 联想Y510P ubuntu14.10双网卡(网卡双IP设置),双显卡设置
  5. GPS基础知识(十) 、定位方程解算和定位精度
  6. oracle必须运行netca,【监听配置】Oracle如何静默运行NETCA,使用netca.rsp文件
  7. sharepoint2010 list联合查询--(未整理)
  8. NPDP|产品经理的硬实力体现在哪里?
  9. 智能制造生产执行与控制
  10. 电脑高手最常用的五个组合键