how to implement a code of an algorithm in a GUI?
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I develop a code to find a query image among a cluster of images by applying GLCM and Kmeans algo. But there are some errors occuring that i dnt know how to compensate tham. Here is the code function varargout = Step_queryimage(varargin) % STEP_QUERYIMAGE MATLAB code for Step_queryimage.fig % STEP_QUERYIMAGE, by itself, creates a new STEP_QUERYIMAGE or raises the existing % singleton*. % % H = STEP_QUERYIMAGE returns the handle to a new STEP_QUERYIMAGE or the handle to % the existing singleton*. % % STEP_QUERYIMAGE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in STEP_QUERYIMAGE.M with the given input arguments. % % STEP_QUERYIMAGE('Property','Value',...) creates a new STEP_QUERYIMAGE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Step_queryimage_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Step_queryimage_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 Step_queryimage
% Last Modified by GUIDE v2.5 12-Jun-2014 16:19:16
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Step_queryimage_OpeningFcn, ... 'gui_OutputFcn', @Step_queryimage_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 Step_queryimage is made visible. function Step_queryimage_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) i=1; j=1; k=1; % varargin command line arguments to Step_queryimage (see VARARGIN)
% Choose default command line output for Step_queryimage handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes Step_queryimage wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = Step_queryimage_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 Browse_Image. function Browse_Image_Callback(hObject, eventdata, handles) % hObject handle to Browse_Image (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [filename direc]=uigetfile('*.jpg','pick a file'); if filename==0 return end image1=imread(fullfile(direc,filename)); axes(handles.axes1) image(image1) handles.browse_image=fullfile(direc,filename); guidata(hObject,handles)
% --- Executes on button press in Next_button. function Next_button_Callback(hObject, eventdata, handles) % hObject handle to Next_button (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.figure1,'Visible','off'); step2_GLCM(handles.figure2);
% --- Executes on button press in algorithm_button. function algorithm_button_Callback(hObject, eventdata, handles) % hObject handle to algorithm_button (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) list=dir('*.jpg'); for i=1:length(list) imag{i}=imread(list(i).name); listimage{i}=list(i).name; a{i}=rgb2gray(imag{i}); GLCM = graycomatrix(a{i},'Offset',[2 0]); stats{i} = graycoprops(GLCM,'all'); ent(i)=entropy(a{i});
avg(i)=(stats{i}.Contrast+stats{i}.Correlation+stats{i}.Energy+stats{i}.Homogeneity+ent(i))/5;
end
% --- Executes on button press in query_average. function query_average_Callback(hObject, eventdata, handles) % hObject handle to query_average (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if(strcmp(list(i).name,query_image_name)) query_im_avg=avg(i); end
% --- Executes on button press in Average_comparison. function Average_comparison_Callback(hObject, eventdata, handles) % hObject handle to Average_comparison (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) j=1; for m=1:length(avg) if(avg(m)>(query_im_avg-0.2) && avg(m)<(query_im_avg+0.2)) imagename{j}=listimage{m}; clus1img{j}=imread(listimage{m}); end end
% --- Executes on button press in show_image. function show_image_Callback(hObject, eventdata, handles) % hObject handle to show_image (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) j=1; clus1img1{j}=im2double(rgb2gray(clus1img{j})); dis{j}=pdist(clus1img1{j},'euclidean'); link{j}=linkage(dis{j}); cop(j)=cophenet(link{j},dis{j}); if(strcmp(list(j).name,query_image_name)) query_im_cop=cop(j); end j=j+1; axes(handles.axes1); imshow(image1);
Please help me...!!!
1 个评论
Image Analyst
2014-6-12
I wouldn't tackle that unless you attached your m-file and fig file. Use the paperclip icon.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!