Showing error in Matlab GUI interface code

12 次查看(过去 30 天)
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 03-May-2021 12:42:10
% 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, 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 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(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)
[filename,path]=uigetfile('*.*', 'Select an image');
filename=strcat(path,filename);
I=imresize(imread(filename),[256,256]);
axes(handles.axes2);
imshow(I);
handles.I = I;
guidata(hObject, handles);
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over popupmenu1.
function popupmenu1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu3
% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in rgbtogray.
function rgbtogray_Callback(hObject, eventdata, handles)
% hObject handle to rgbtogray (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
f=handles.I;
f= rgb2gray(f);
axes(handles.axes3);
imshow(f);
handles.f = f;
guidata(hObject, handles);
% --- Executes on selection change in Types_of_noise.
function Types_of_noise_Callback(hObject, eventdata, handles)
% hObject handle to Types_of_noise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns Types_of_noise contents as cell array
% contents{get(hObject,'Value')} returns selected item from Types_of_noise
h=handles.f;
contents = cellstr(get(hObject,'String'));
e=contents{get(hObject,'Value')};
if(strcmp(e,'salt and pepper noise'))
J = imnoise(h,'salt & pepper', 0.2);
axes(handles.axes4);
imshow(J);
elseif (strcmp(e,'Gaussian noise'))
J=imnoise(h,'gaussian',0,0.0125);
axes(handles.axes4);
imshow(J);
elseif (strcmp(e,'Poisson noise'))
J = imnoise(h,'poisson');
axes(handles.axes4);
imshow(J);
else
J = imnoise(h,'speckle');
axes(handles.axes4);
imshow(J);
end
handles.J = J;
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function Types_of_noise_CreateFcn(hObject, eventdata, handles)
% hObject handle to Types_of_noise (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in Denoising_filters.
function Denoising_filters_Callback(hObject, eventdata, handles)
% hObject handle to Denoising_filters (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns Denoising_filters contents as cell array
% contents{get(hObject,'Value')} returns selected item from Denoising_filters
c=handles.I;
u=handles.J;
contents = cellstr(get(hObject,'String'));
p=contents{get(hObject,'Value')};
if(strcmp(p,'Wiener filter'))
u=uint8(u);
[K,NOISE]=wiener2(u,[5,5]);
K=wiener2(u,[5 5]);
K=uint8(K);
axes(handles.axes5);
imshow(K);
handles.K = K;
guidata(hObject, handles);
elseif(strcmp(p,'Gaussian filter'))
u=uint8(u);
sigma=0.5;
kernel=zeros(5,5);
W=0;
for i=1:5
for j=1:5
dis=(i-3)^2+(j-3)^2;
kernel(i,j)=exp(-1*dis/2*sigma*sigma);
W=W+kernel(i,j);
end
end
kernel=kernel/W;
[m,n]=size(u);
output=zeros(m,n);
t=padarray(u,[2,2]);
for i=1:m
for j=1:n
temp=t(i:i+4,j:j+4);
temp=double(temp);
conv=temp.*kernel;
output(i,j)=sum(conv(:));
end
end
output=uint8(output);
axes(handles.axes5);
imshow(output);
handles.output = output;
guidata(hObject, handles);
elseif(strcmp(p,'Vector median filter'))
a1=c(:,:,1);
b1=u(:,:,1);
b1=double(b1);
a2=c(:,:,2);
b2=u(:,:,2);
b2=double(b2);
a3=c(:,:,3);
b3=u(:,:,3);
b3=double(b3);
a1=double(a1);
a2=double(a2);
a3=double(a3);
z1=zeros(256,256);
z2=zeros(256,256);
z3=zeros(256,256);
for i=2:255
for j=2:255
s1=reshape(b1(i-1:i+1,j-1:j+1),1,9);
s2=reshape(b2(i-1:i+1,j-1:j+1),1,9);
s3=reshape(b3(i-1:i+1,j-1:j+1),1,9);
for z=1:9
su=0;
for r=1:9
if (z~=1)
su=su+sqrt((s1(z)-s1(r)).^2+(s2(z)-s2(r)).^2+(s3(z)-s3(r)).^2);
end
end
m(z)=su;
end
q=min(m(:));
p=find(m(:)==q);
p1=s1(p(1));
p2=s2(p(1));
p3=s3(p(1));
z1(i,j)=p1;
z2(i,j)=p2;
z3(i,j)=p3;
end
end
z1=uint8(z1);
z2=uint8(z2);
z3=uint8(z3);
Y0=cat(3,z1,z2,z3);
Y0=uint8(Y0);
axes(handles.axes5);
imshow(Y0);
handles.Y0 = Y0;
guidata(hObject, handles);
else
u=uint8(u);
avg = fspecial('average');
avg1=filter2(avg,u);
axes(handles.axes5);
avg1=uint8(avg1);
imshow(avg1);
handles.avg1 = avg1;
guidata(hObject, handles);
end
% --- Executes during object creation, after setting all properties.
function Denoising_filters_CreateFcn(hObject, eventdata, handles)
% hObject handle to Denoising_filters (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function sigma_value_Callback(hObject, eventdata, handles)
% hObject handle to sigma_value (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of sigma_value as text
% str2double(get(hObject,'String')) returns contents of sigma_value as a double
% --- Executes during object creation, after setting all properties.
function sigma_value_CreateFcn(hObject, eventdata, handles)
% hObject handle to sigma_value (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in Mean_square_error.
function Mean_square_error_Callback(hObject, eventdata, handles)
% hObject handle to Mean_square_error (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 Peak_signal_to_noise_ratio.
function Peak_signal_to_noise_ratio_Callback(hObject, eventdata, handles)
% hObject handle to Peak_signal_to_noise_ratio (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit5_Callback(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit5 as text
% str2double(get(hObject,'String')) returns contents of edit5 as a double
% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit8_Callback(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit8 as text
% str2double(get(hObject,'String')) returns contents of edit8 as a double
% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in MSE.
function MSE_Callback(hObject, eventdata, handles)
% hObject handle to MSE (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns MSE contents as cell array
% contents{get(hObject,'Value')} returns selected item from MSE
f=handles.f;
contents = cellstr(get(hObject,'String'));
p1=contents{get(hObject,'Value')};
if(strcmp(p1,'wiener filter'))
K=handles.K;
v1=0;
for i=1:256
for j=1:256
v1=v1+mean(K(i,j)-f(i,j))^.2;
end
end
MSE=v1/(256*256);
set(handles.edit5,'string',MSE);
PSNR=10*log10(255^2*254^2/v1);
set(handles.edit8,'string',PSNR);
elseif (strcmp(p1,'gaussian filter'))
output=handles.output;
v2=0;
for i=1:256
for j=1:256
v2=v2+mean(output(i,j)-f(i,j))^.2;
end
end
MSE=v2/(256*256);
set(handles.edit5,'string',MSE);
PSNR=10*log10(255^2*254^2/v2);
set(handles.edit8,'string',PSNR);
elseif (strcmp(p1,'vector median filter'))
Y0=handles.Y0;
v3=0;
for i=1:256
for j=1:256
v3=v3+mean(Y0(i,j)-f(i,j))^.2;
end
end
MSE=v3/(256*256);
set(handles.edit5,'string',MSE);
PSNR=10*log10(255^2*254^2/v3);
set(handles.edit8,'string',PSNR);
else
avg1=handles.avg1;
v4=0;
for i=1:256
for j=1:256
v4=v4+mean(avg1(i,j)-f(i,j))^.2;
end
end
MSE=v4/(256*256);
set(handles.edit5,'string',MSE);
PSNR=10*log10(255^2*254^2/v4);
set(handles.edit8,'string',PSNR);
end
% --- Executes during object creation, after setting all properties.
function MSE_CreateFcn(hObject, eventdata, handles)
% hObject handle to MSE (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in PSNR.
function PSNR_Callback(hObject, eventdata, handles)
% hObject handle to PSNR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns PSNR contents as cell array
% contents{get(hObject,'Value')} returns selected item from PSNR
% --- Executes during object creation, after setting all properties.
function PSNR_CreateFcn(hObject, eventdata, handles)
% hObject handle to PSNR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
This is a code for image denoising techniques,I am faced few errors in it .Attaching the error below ,Please help
Reference to non-existent field 'avg1'.
Error in gui>MSE_Callback (line 466)
avg1=handles.avg1;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in gui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)gui('MSE_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
  2 个评论
Adam Danz
Adam Danz 2021-5-3
Help others help you. Make it very easy for people to help you by formatting your code.
Adam Danz
Adam Danz 2021-5-3
The error message states that this line is causing the problem
avg1=handles.avg1;
and the problem is that av1 does not exist.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Properties 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by