function varargout = mylbUIp(varargin)
% MYLBUIP MATLAB code for mylbUIp.fig
% MYLBUIP, by itself, creates a new MYLBUIP or raises the existing
% singleton*.
%
% H = MYLBUIP returns the handle to a new MYLBUIP or the handle to
% the existing singleton*.
%
% MYLBUIP('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MYLBUIP.M with the given input arguments.
%
% MYLBUIP('Property','Value',...) creates a new MYLBUIP or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before mylbUIp_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to mylbUIp_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help mylbUIp
% Last Modified by GUIDE v2.5 17-Apr-2016 14:40:51
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mylbUIp_OpeningFcn, ...
'gui_OutputFcn', @mylbUIp_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before mylbUIp is made visible.
function mylbUIp_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to mylbUIp (see VARARGIN)
axes( handles.axes1 ) ;
imshow( 'img\rice.jpg' ) ;
% Choose default command line output for mylbUIp
handles.output = hObject;
% Update handles structure
guidata(hObject, handles); %更新一下数据
% UIWAIT makes mylbUIp wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = mylbUIp_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global filename;
global pathname;
[filename,pathname]=uigetfile({'*.jpg;*.tif;*.png;*.jpg','All Image Files';...
'*.*','All Files' });
inimg=imread([pathname,filename]);
%gfilename=filename;
%gpathname=pathname;
axes( handles.axes1 ) ;
imshow(inimg);
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton1.
function pushbutton1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%界面设置
set(handles.text1,'String','检索结果'); %显示该文本上的文字
set(handles.text3,'String','LBP响应图像'); %显示该文本上的文字
pagename=strcat('第 ',num2str(1),' 页');
set(handles.text4,'String',pagename); %显示该文本上的文字
set(handles.pushbutton3,'visible','on'); %显示该按钮
set(handles.pushbutton4,'visible','on'); %显示该按钮
%主程序//////////////////////////////////////////////////////////
global filename; %文件名 全局变量
global pathname; %文件路径
%计算输入图像的lbp特征及显示///////////////////////////////////////
I=imread([pathname,filename]); %读入rgb图像
G=rgb2gray(I); %转成灰度图像
Gm=imresize(G,[300 300],'nearest'); %图像缩放,欠采样,邻近插值算法
J=lbp(Gm,2,8,0,[]); %提取lbp特征
countsum=100; %灰度级数
[counts,x]=imhist(J,countsum);
axes( handles.axes2 ) ; %焦点到axes2中
%imshow(J) ; %显示到axes2中
stem(counts,x);
%计算数据库中的图像的lbp特征及和输入图像lbp特征的欧式距离///////////
Odist=[]; %欧式距离数组
global picnum; %数据库大小
picnum=80;
for i=1:1:picnum
values=strcat('',num2str(i),''); %从1开始
Ic=imread(['img\',values,'.jpg']);
Gc=rgb2gray(Ic);
Gmc=imresize(Gc,[300 300],'nearest'); %图像缩放,邻近插值算法
Jc=lbp(Gmc,2,8,0,[]); %提取lbp特征
[countsc,xc]=imhist(Jc,countsum);
[M,N]=size(Jc);
sum=0.0;
%计算欧式距离
for l=1:1:M
for k=1:1:N
Jdis=double((J(l,k)-Jc(l,k))^2/256);
sum=sum+Jdis;
end
end
for l=1:1:countsum
Jdis=double((countsc(l)-counts(l))^2/256);
sum=sum+Jdis;
end
Odist(i)=sqrt(double(sum)); %与第i张图片lbp的欧式距离
end
[Ordist,ind]=sort(Odist); %由小到大排序,ind存放序前的序号
%////////////////////////////////////显示/////////////////////////
global indx; %序号数组传给全局变量indx
indx=ind;
global pagenum; %全局变量浏览到第几页
pagenum=1;
for i=1:1:20 %共显示前20张
index=strcat('',num2str(indx(i)),''); %找到第i张图片名
Ord=imread(['img\',index,'.jpg']); %读出该张图片
switch i
case 1
axes( handles.axes3) ;imshow(Ord) ; %显示到axes3
case 2
axes( handles.axes4) ;imshow(Ord) ;
case 3
axes( handles.axes5) ;imshow(Ord) ;
case 4
axes( handles.axes6) ;imshow(Ord) ;
case 5
axes( handles.axes7) ;imshow(Ord) ;
case 6
axes( handles.axes8) ;imshow(Ord) ; %显示到axes3
case 7
axes( handles.axes9) ;imshow(Ord) ;
case 8
axes( handles.axes10) ;imshow(Ord) ;
case 9
axes( handles.axes11) ;imshow(Ord) ;
case 10
axes( handles.axes12) ;imshow(Ord) ;
case 11
axes( handles.axes13) ;imshow(Ord) ; %显示到axes3
case 12
axes( handles.axes14) ;imshow(Ord) ;
case 13
axes( handles.axes15) ;imshow(Ord) ;
case 14
axes( handles.axes16) ;imshow(Ord) ;
case 15
axes( handles.axes17) ;imshow(Ord) ;
case 16
axes( handles.axes18) ;imshow(Ord) ; %显示到axes3
case 17
axes( handles.axes19) ;imshow(Ord) ;
case 18
axes( handles.axes20) ;imshow(Ord) ;
case 19
axes( handles.axes21) ;imshow(Ord) ;
case 20
axes( handles.axes22) ;imshow(Ord) ;
end
end
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over text3.
funct