用 Matlab GUI搭建一个简单的CBIR图像检索系统(二)
上一篇文章介绍了CBIR的流程和图像特征的提取以及图像特征库的建立。在这一篇文章中,将创建一个基于直方图的图像检索GUI。
如上图所示,就是利用matlab gui建立的一个图像检索的框架,其中用到的控件有按钮、单选按钮、静态文本框、坐标轴框以及面板。
ImageRead按钮的Callbacall函数为
% --- Executes on button press in ChooseImage.
function ChooseImage_Callback(hObject, eventdata, handles)
% hObject handle to ChooseImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,PathName] = uigetfile({'*.BMP';'*.bmp';'*.tif';'*.jpg';'*.png'},'选择图像');
str = [PathName filename];
if PathName ~=0
OrginImage_O = imread(str);
OrginImage_O = OrginImage_O(:,:,1:3);
if get(handles.btn_total,'value')
OrginImage=OrginImage_O;
OrginImage = imresize(OrginImage,[256,256]);
elseif get(handles.btn_part,'value')
figure(2),imshow(OrginImage_O);
OrginImage=imcrop(); %这里把要裁剪的图像框出来
OrginImage = imresize(OrginImage,[256,256]);
close(2);
axes(handles.axes1);
imshow(OrginImage);
setappdata(handles.ChooseImage,'OrginImage',OrginImage);
end
Image Capture为调用相机程序获取图片的方法,
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
open ('C:\Program Files (x86)\Canon\EOS Utility\EOS Utility.exe');
Retrieval按钮对应的事件:
(1)提取读取图像的对应特征
(2)计算检索图像的特征和特征库中的特征的相似度
(3)按照相似度的大小将检索结果显示在右边的坐标轴框中
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
IndexOfPoints=[];
OrginImage=getappdata(handles.ChooseImage,'OrginImage');
if get(handles.btn_ch,'value')
load('HISTFeatures.mat');
[m,n]=size(HISTFeatures);
OrginImage_Gray = rgb2gray(OrginImage);
[Count1,x] = imhist(OrginImage_Gray) ;
for index = 1:m
Count2 = HISTFeatures{index,2};
PathData = HISTFeatures{index,1};
Sum1=sum(Count1);Sum2=sum(Count2);
Sumup = sqrt(Count1.*Count2);
SumDown = sqrt(Sum1*Sum2);
Sumup = sum(Sumup);
IndexOfBashi=1-sqrt(1-Sumup/SumDown);
IndexOfPoint{index,1}=IndexOfBashi;
IndexOfPoint{index,2}=PathData;
IndexOfPoint=sortrows(IndexOfPoint);
axes(handles.axes2);
Serch = imread(IndexOfPoint{m,2});
Serch = Serch(:,:,1:3);
imshow(Serch);
axes(handles.axes3);
Serch = imread(IndexOfPoint{(m-1),2});
Serch = Serch(:,:,1:3);
imshow(Serch);
axes(handles.axes4);
Serch = imread(IndexOfPoint{(m-2),2});
Serch = Serch(:,:,1:3);
imshow(Serch);
axes(handles.axes5);
Serch = imread(IndexOfPoint{(m-3),2});
Serch = Serch(:,:,1:3);
imshow(Serch);
axes(handles.axes6);
Serch = imread(IndexOfPoint{(m-4),2});
Serch = Serch(:,:,1:3);
imshow(Serch);
axes(handles.axes7);
Serch = imread(IndexOfPoint{(m-5),2});
Serch = Serch(:,:,1:3);
imshow(Serch);
axes(handles.axes8);
Serch = imread(IndexOfPoint{(m-6),2});
Serch = Serch(:,:,1:3);
imshow(Serch);
axes(handles.axes9);
Serch = imread(IndexOfPoint{(m-7),2});
Serch = Serch(:,:,1:3);
imshow(Serch);
axes(handles.axes10);
Serch = imread(IndexOfPoint{(m-8),2});
Serch = Serch(:,:,1:3);
imshow(Serch);
axes(handles.axes11);
Serch = imread(IndexOfPoint{(m-9),2});
Serch = Serch(:,:,1:3);
imshow(Serch);
axes(handles.axes12);
Serch = imread(IndexOfPoint{(m-10),2});
Serch = Serch(:,:,1:3);