getting error in gui

1 次查看(过去 30 天)
priti kale
priti kale 2019-2-25
I have error is below=
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in gui (line 44)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
And my code is
function varargout = gui(varargin)
% GUI MATLAB code for gui.fig
% GUI, by itself, creates a new GUI or raises the existing
% singleton*.
%
% H = GUI returns the handle to a new GUI or the handle to
% the existing singleton*.
%
% GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI.M with the given input arguments.
%
% GUI('Property','Value',...) creates a new GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_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 gui
% Last Modified by GUIDE v2.5 23-Feb-2019 14:48:40
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_OpeningFcn, ...
'gui_OutputFcn', @gui_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 gui is made visible.
function gui_OpeningFcn(hObject, ~, 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 gui (see VARARGIN)
% Choose default command line output for gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui_OutputFcn(~, ~, 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(~, ~, 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)
[filename, pathname] = uigetfile({'*.jpg'},'choose file');
global img_1;
if (filename ~= 0)
img_1 = strcat(pathname,filename);
axes(handles.axes1)
imshow(img_1)
end
% now second image
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(~, ~, 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)
[filename, pathname] = uigetfile({'*.jpg'},'choose file');
global img_2;
if (filename ~= 0)
img_2 = strcat(pathname,filename);
axes(handles.axes2)
imshow(img_2)
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(~, ~, 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)
% --- Executes during object creation, after setting all properties.
global img_1;
global img_2;
image_rgb1 = imread(img_1);
image_lab1 = rgb2lab(image_rgb1);
image_lab1 = im2double(image_lab1);
w = size(image_lab1,2);
h = size(image_lab1,2);
l11 = image_lab1(:,:,1); %red
a11 = image_lab1(:,:,2); %green
b11 = image_lab1(:,:,3); %blue
image_rgb2 = imread(img_2);
image_rgb2 = imresize(image_rgb2,[w h]);
image_lab2 = rgb2lab(image_rgb2);
image_lab2 = im2double(image_lab2);
l22 = image_lab2(:,:,1); %red
a22 = image_lab2(:,:,2); %green
b22 = image_lab2(:,:,3); %blue
DA = 0;
DE = 0;
DC = 0;
for k = 1:w
for k = 1:h
l1 = l11(k,1i);
l2 = l22(k,1i);
a1 = a11(k,1i);
a2 = a22(k,1i);
b1 = b11(k,1i);
b2 = b22(k,1i);
C1 = sqrt( (a1*a1) + (b1*b1) );
C2 = sqrt( (a1*a1) + (b1*b1) );
DC = C1 - c2 ;
Dl = l1 - l2;
Da = a1 - a2;
Db = b1 - b2;
DH = sqrt((Da * Da) + (Db * Db) - (Dc * DC));
if( l1 < l6)
SL = 0.511 ;
end
SC = ((0.0638 * c1)/ (1+0.0131*c1)) + 0.638;
H1 = atan2(b1,a1);
if((H1 >= 164 ) && ( H1 <= 345 ))
T = 0.56 + abs((0.2 * cos(H1+168)));
else
T = 0.36 + abs((0.4 * cos(H1+35)));
end
F = sqrt((c1*c1*c1*c1)/(c1*c1*c1*c1)+1900);
SH = SC * (F * T + 1 - F);
DE = sqrt( ( (Dl/SL) * (Dl/SL) + (DC/SC) * (DC/SC) + (DH/SH) * (DH/SH) ) );
DA = DA + DE;
end
end
e=w*h;
DA=DA/e;
distance = strcat('The distance : ', num2str(DA));
set(handles.text2,'string',distance);
function pushbutton3_CreateFcn(~, ~, ~)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
  1 个评论
Geoff Hayes
Geoff Hayes 2019-3-3
Priti - it isn't clear which line of code is generating the error message. Is it the line of code that reads the image - with imread - using the global variable img_1 or the line that reads the image using global variable img_2? Perhaps one or both of these isn't set when you press the third push button. Please provide more details.
You can avoid using global variables and use the handles structure (which is accessible b all callbacks) instead. See Store or retrieve UI data for details.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2019-3-3
Your code in pushbutton3_Callback does not protect against the cases that img_1 or img_2 are empty or do not name a recognized file.
Your code in pushbutton1_Callback and pushbutton2_Callback should be using fullfile() instead of strcat()
If you are using R2014a or earlier, rgb2lab() does not exist.
Your code in pushbutton3_Callback does not protect against the case that img_1 names a grayscale or pseudocolor image, so the third dimension might not exist for it.

类别

Help CenterFile Exchange 中查找有关 Interaction Control 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by