Why is my GUI program producing an error when I 'Run' it?

45 visualizaciones (últimos 30 días)
A
A el 31 de Mayo de 2015
Comentada: Walter Roberson el 5 de Oct. de 2022
When I run the below .m file, it gives me the following error:
Error using feval
Undefined function 'frequency_axes_CreateFcn' for input arguments of type 'matlab.graphics.axis.Axes'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in TestInterface (line 43)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)TestInterface('frequency_axes_CreateFcn',hObject,eventdata,guidata(hObject))
Any idea why? Here's the code from my .m:
function varargout = TestInterface(varargin)
% TESTINTERFACE Application M-file for TestInterface.fig
% TESTINTERFACE, by itself, creates a new TESTINTERFACE or raises the existing
% singleton*.
%
% H = TESTINTERFACE returns the handle to a new TESTINTERFACE or the handle to
% the existing singleton*.
%
% TESTINTERFACE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TESTINTERFACE.M with the given input arguments.
%
% TESTINTERFACE('Property','Value',...) creates a new TESTINTERFACE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before two_axes_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to TestInterface_OpeningFcn via varargin.
%
% *See GUI Options - GUI allows only one instance to run (singleton).
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help TestInterface
% Copyright 2001-2006 The MathWorks, Inc.
% Last Modified by GUIDE v2.5 31-May-2015 00:38:11
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @TestInterface_OpeningFcn, ...
'gui_OutputFcn', @TestInterface_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 TestInterface is made visible.
function TestInterface_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 TestInterface (see VARARGIN)
% Choose default command line output for TestInterface
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes TestInterface wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = TestInterface_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;
% --------------------------------------------------------------------
function plot_button_Callback(hObject, eventdata, handles, varargin)
% hObject handle to plot_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(0,'DefaultFigureColor','White',...
'defaultaxesfontsize',8,...
'DefaultAxesFontname','Calibri',...
'DefaultTextFontName','Calibri')
x = [0:20];
y = [0:20];
% Get user input from GUI
f1 = str2double(get(handles.f1_input,'String'));
f2 = str2double(get(handles.f2_input,'String'));
constant = str2double(get(handles.constant,'String'));
% Calculate data
TestFormula = @(x,y)(x + y.*constant);
[X,Y] = meshgrid(x,y);
Z1 = TestFormula(X,Y);
Z2 = TestFormula(f1,f2);
% Create frequency plot in proper axes
%plot(handles.frequency_axes,f,m(1:257))
s1 = surf(X,Y,Z1)
set(handles.edit5,'String',Z2)
xlabel('X', 'fontweight', 'bold')
ylabel('Y', 'fontweight', 'bold')
%title('(A)', 'FontSize', 12, 'fontweight', 'bold')
view (135,15);
yh = get(gca,'YLabel'); % Handle of the y label
set(yh, 'Units', 'Normalized')
pos = get(yh, 'Position');
set(yh, 'Position',pos.*[0.85,0.6,1],'Rotation',-10.9)
xh = get(gca,'XLabel'); % Handle of the x label
set(xh, 'Units', 'Normalized')
pos = get(xh, 'Position');
set(xh, 'Position',pos.*[1,1,1],'Rotation',11.1)
zlabel('Z', 'fontweight', 'bold')
zh = get(gca,'ZLabel'); % Handle of the z label
set(zh, 'Units', 'Normalized')
pos = get(zh, 'Position');
set(zh, 'Position',pos.*[1.5,1,0],'Rotation',90)
%set(handles.frequency_axes,'XMinorTick','on')
axis tight
camlight
lighting phong
shading interp
set(s1,'FaceColor',[0 0.63 0.91], 'edgecolor',[0 0 0.4],'meshstyle','both','linewidth',.15);
grid on
function f1_input_Callback(hObject, eventdata, handles)
% hObject handle to f1_input (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 f1_input as text
% str2double(get(hObject,'String')) returns contents of f1_input
% as a double
% Validate that the text in the f1 field converts to a real number
f1 = str2double(get(hObject,'String'));
if isnan(f1) || ~isreal(f1)
% isdouble returns NaN for non-numbers and f1 cannot be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot f1')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
function f2_input_Callback(hObject, eventdata, handles)
% hObject handle to f2_input (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 f1_input as text
% str2double(get(hObject,'String')) returns contents of f1_input
% as a double
% Validate that the text in the f2 field converts to a real number
f2 = str2double(get(hObject,'String'));
if isnan(f2) ... % isdouble returns NaN for non-numbers
|| ~isreal(f2) % f1 should not be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot f2')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
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 constant_Callback(hObject, eventdata, handles)
% hObject handle to constant (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 constant as text
% str2double(get(hObject,'String')) returns contents of constant as a double
constant = str2double(get(hObject,'String'));
if isnan(constant) ... % isdouble returns NaN for non-numbers
|| ~isreal(constant) % f1 should not be complex
% Disable the Plot button and change its string to say why
set(handles.plot_button,'String','Cannot plot constant')
set(handles.plot_button,'Enable','off')
% Give the edit text box focus so user can correct the error
uicontrol(hObject)
else
% Enable the Plot button with its original name
set(handles.plot_button,'String','Plot')
set(handles.plot_button,'Enable','on')
end
% --- Executes during object creation, after setting all properties.
function constant_CreateFcn(hObject, eventdata, handles)
% hObject handle to constant (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
  4 comentarios

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 31 de Mayo de 2015
You probably copied a GUIDE-created .fig and edited it, instead of opening the interface in GUIDE and telling GUIDE to save it under a new name. Or perhaps you deleted an axes named frequency_axes without going through GUIDE to do so.
Are you launching the interface by double-clicking on the .fig or by commanding
TestInterface
on the command line? Double-clicking would invoke a callback saved with the .fig and it is that callback,
@(hObject,eventdata)TestInterface( 'frequency_axes_CreateFcn', hObject,eventdata,guidata(hObject))
that is causing the problem.
The quick fix is adding a function to your file,
function frequency_axes_Createfcn(varargin)
that does nothing.
The longer term fix is to use the figure browser to find that callback and delete it. Or you can use findobj() or findall() to retrieve the figure properties, look at the callback functions, find the errant one and overwrite it, and re-save the .fig.
  16 comentarios
Lee Yi Zhan
Lee Yi Zhan el 19 de Jun. de 2021
Need Help!!
Unrecognized function or variable 'textDistance_CreateFcn'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Distance1 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Distance1('textDistance_CreateFcn',hObject,eventdata,guidata(hObject))
>>
Lee Yi Zhan
Lee Yi Zhan el 19 de Jun. de 2021
Here is my full code
function varargout = Distance1(varargin)
% DISTANCE1 MATLAB code for Distance1.fig
% DISTANCE1, by itself, creates a new DISTANCE1 or raises the existing
% singleton*.
%
% H = DISTANCE1T returns the handle to a new DISTANCE1 or the handle to
% the existing singleton*.
%
% DISTANCE1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DISTANCE1.M with the given input arguments.
%
% DISTANCE1('Property','Value',...) creates a new DISTANCE1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Distance1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Distance1_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 Distance1
% Last Modified by GUIDE v2.5 26-Mar-2017 20:02:22
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Distance1_OpeningFcn, ...
'gui_OutputFcn', @Distance1_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 DistanceMeasurement is made visible.
function Distance1_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 DistanceMeasurement (see VARARGIN)
% Choose default command line output for DistanceMeasurement
handles.output = hObject;
% Delete any opened ports in MATLAB
delete(instrfind)
% Create a Serial Object
handles.ser = serial('COM3', 'BaudRate',115200,'Terminator','LF',...
'Timeout',10);
% Associate Serial Event, whenever Terminal Character is recived
handles.ser.BytesAvailableFcn = {@SerialEvent, hObject};
% Open Serial Port
fopen(handles.ser);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DistanceMeasurement wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Distance1_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;
function SerialEvent(sObject, eventdata, hGui)
% get the updated handle
handles = guidata(hGui);
% get data from serial port
tmp_c = fscanf(sObject);
set(handles.textDistance, 'String', tmp_c)
% Updates handle structure
guidata(hGui, handles)
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
fclose(handles.ser);
delete(handles.ser);
% Hint: delete(hObject) closes the figure
delete(hObject);

Iniciar sesión para comentar.

Más respuestas (17)

sai kumar
sai kumar el 24 de Oct. de 2017
Editada: Walter Roberson el 26 de Nov. de 2017
can you please help me rectify this, i guess it is similar to the above question??
Undefined function or variable 'dmessage_CreateFcn'.
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in trial (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)trial('dmessage_CreateFcn',hObject,eventdata,guidata(hObject))
  10 comentarios
Merveil Patient Noumbi Noumbi
Merveil Patient Noumbi Noumbi el 22 de Abr. de 2022
Please help me
Undefined function or variable ‘gui_state’.
Error in GUI_facedetection (line 42) gui_mainfcn(gui_state, varargin {:});
Image Analyst
Image Analyst el 22 de Abr. de 2022
@Merveil Patient Noumbi Noumbi Start your own question (not here), and attach your .fig file and .m file.

Iniciar sesión para comentar.


Johana Galarza
Johana Galarza el 26 de Nov. de 2017
Editada: Walter Roberson el 26 de Nov. de 2017
can you please help me rectify this, i guess it is similar to the above question??
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in Campos (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Campos('Calcular_Callback',hObject,eventdata,guidata(hObject))
  3 comentarios

Iniciar sesión para comentar.


Amelia van Leeuwen
Amelia van Leeuwen el 7 de Feb. de 2018
Editada: Walter Roberson el 2 de Abr. de 2018
Hi, I'm having similar issues! Here is my error message:
Undefined function or variable 'm2c_ratio_to_be_tested_KeyPressFcn'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUIWITP (line 65)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUIWITP('m2c_ratio_to_be_tested_KeyPressFcn',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl KeyPressFcn.
Undefined function or variable 'm2c_ratio_to_be_tested_KeyPressFcn'.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUIWITP (line 65)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUIWITP('m2c_ratio_to_be_tested_KeyPressFcn',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl KeyPressFcn.
  4 comentarios
Rungkiat Phatthanatapong
Rungkiat Phatthanatapong el 2 de Abr. de 2018
Editada: Walter Roberson el 2 de Abr. de 2018
Can you help me fix this problem ?
I am using ARTE
Error in drawrobot3d (line 173)
pieza_dibujar = robot.piece{i};
Error in teach>pushbutton_refresh_Callback (line 2911)
drawrobot3d(robot, robot.q)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in teach (line 68)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)teach('pushbutton_refresh_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Walter Roberson
Walter Roberson el 2 de Abr. de 2018
This appears to relate to http://arvc.umh.es/arte/index_en.html
We need a more complete error message, everything in red, and an outline of what you were doing at the time.

Iniciar sesión para comentar.


mohamed mohsen
mohamed mohsen el 30 de Mayo de 2018
Editada: Walter Roberson el 30 de Mayo de 2018
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in videodct (line 45)
gui_mainfcn(gui_State, varargin{:});
Error while evaluating UIControl Callback.
  6 comentarios
mohamed mohsen
mohamed mohsen el 30 de Mayo de 2018
after I add the code it worked but I had another problem
HL1=hufflen(Hi1);HL2=hufflen(Hi2);
Interrupt while evaluating DestroyedObject Callback.
Walter Roberson
Walter Roberson el 30 de Mayo de 2018
That code does not appear to exist in what you posted.

Iniciar sesión para comentar.


satuk Uckus
satuk Uckus el 2 de Jun. de 2018
Editada: Walter Roberson el 31 de Dic. de 2018
I'm taking this error. how ı can fix it?
Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error due to multiple causes.
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in GUI_MECWHEEL (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)GUI_MECWHEEL('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Caused by: Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Invalid setting in 'WMR_Project_sim_2013GUI/Constant4' for parameter 'Value'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error evaluating parameter 'Value' in 'WMR_Project_sim_2013GUI/Constant4' Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Not enough input arguments. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Invalid setting in 'WMR_Project_sim_2013GUI/Constant5' for parameter 'Value'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error evaluating parameter 'Value' in 'WMR_Project_sim_2013GUI/Constant5' Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Undefined function or variable 'b'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Invalid setting in 'WMR_Project_sim_2013GUI/Constant7' for parameter 'Value'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error evaluating parameter 'Value' in 'WMR_Project_sim_2013GUI/Constant7' Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Undefined function or variable 'r'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Invalid setting in 'WMR_Project_sim_2013GUI/Integrator1' for parameter 'InitialCondition'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error evaluating parameter 'InitialCondition' in 'WMR_Project_sim_2013GUI/Integrator1' Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Undefined function or variable 'Xs'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Invalid setting in 'WMR_Project_sim_2013GUI/Integrator5' for parameter 'InitialCondition'. Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Error evaluating parameter 'InitialCondition' in 'WMR_Project_sim_2013GUI/Integrator5' Error using GUI_MECWHEEL>pushbutton1_Callback (line 362) Undefined function or variable 'th_in'.
Error while evaluating UIControl Callback
  2 comentarios
Walter Roberson
Walter Roberson el 2 de Jun. de 2018
Do you have pushbutton1_Callback invoking sim()? If you are, then you are invoking a Simulink model that relies on some values being present in the workspace of the function that calls sim(). Those might be defined as parameters or there might be From Workspace blocks.
Walter Roberson
Walter Roberson el 2 de Jun. de 2018
The simulation needs
b
r
th_in
Xs
Your code does not define anything like b. Your code defines R with a capital R, but not lower-case r. Your code does not define anything like th_in. Your code defines Sx but not Xs
At the moment, I am not certain what is going on for WMR_Project_sim_2013GUI/Constant4 -- perhaps you left the definition of the constant empty in Simulink ?

Iniciar sesión para comentar.


jony shill
jony shill el 31 de Dic. de 2018
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 27-Dec-2018 10:52:34
% 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 Load_Image.
function Load_Image_Callback(hObject, eventdata, handles)
% hObject handle to Load_Image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im im2
[path, user_cancel] = imgetfile();
if user_cancel
msgbox(sprintf('Invalid Selection'),'Error','Error');
return
end
im = imread(path);
im = im2double(im);
im2 = im;
axes(handle.axes1);
imshow(im);
title('\fontsize(18)\color[rgb]{0.635 0.078 0.184} Patient''s Tooth')
% --- Executes on button press in Detected.
function Detected_Callback(hObject, eventdata, handles)
% hObject handle to Detected (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im
axes(handle.axes2);
wd=256;
Input=imresize(a,[256 256]);
figure(1),subplot(1,3,1),imshow(Input);
[r c p] = size(Input);
if p==3
Input= Input(:,:,2);
figure(1),subplot(1,3,2),imshow(Input);
Input = imadjust(Input,[0.4 0.8],[]);
figure(1),subplot(1,3,3),imshow(Input);
end
Input =double(Input);
Length = (r*c);
Dataset = reshape(Input,[Length,1]);
Clusters=5; %k CLUSTERS
Cluster1=zeros(Length,1);
Cluster2=zeros(Length,1);
Cluster3=zeros(Length,1);
Cluster4=zeros(Length,1);
Cluster5=zeros(Length,1);
miniv = min(min(Input));
maxiv = max(max(Input));
range = maxiv - miniv;
stepv = range/Clusters;
incrval = stepv;
for i = 1:Clusters
K(i).centroid = incrval;
incrval = incrval + stepv;
end
update1=0;
update2=0;
update3=0;
update4=0;
update5=0;
mean1=2;
mean2=2;
mean3=2;
mean4=2;
mean5=2;
while ((mean1 ~= update1) & (mean2 ~= update2) & (mean3 ~= update3) & (mean4 ~= update4) & (mean5 ~= update5))
mean1=K(1).centroid;
mean2=K(2).centroid;
mean3=K(3).centroid;
mean4=K(4).centroid;
mean5=K(5).centroid;
for i=1:Length
for j = 1:Clusters
temp= Dataset(i);
difference(j) = abs(temp-K(j).centroid);
end
[y,ind]=min(difference);
if ind==1
Cluster1(i) =temp;
end
if ind==2
Cluster2(i) =temp;
end
if ind==3
Cluster3(i) =temp;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%UPDATE CENTROIDS
cout1=0;
cout2=0;
cout3=0;
cout4=0;
cout5=0;
for i=1:Length
Load1=Cluster1(i);
Load2=Cluster2(i);
Load3=Cluster3(i);
Load4=Cluster4(i);
Load5=Cluster5(i);
if Load1 ~= 0
cout1=cout1+1;
end
if Load2 ~= 0
cout2=cout2+1;
end
%
if Load3 ~= 0
cout3=cout3+1;
end
if Load4 ~= 0
cout4=cout4+1;
end
if Load5 ~= 0
cout5=cout5+1;
end
end
Mean_Cluster(1)=sum(Cluster1)/cout1;
Mean_Cluster(2)=sum(Cluster2)/cout2;
Mean_Cluster(3)=sum(Cluster3)/cout3;
Mean_Cluster(4)=sum(Cluster4)/cout4;
Mean_Cluster(5)=sum(Cluster5)/cout5;
%reload
for i = 1:Clusters
K(i).centroid = Mean_Cluster(i);
end
update1=K(1).centroid;
update2=K(2).centroid;
update3=K(3).centroid;
update4=K(4).centroid;
update5=K(5).centroid;
end
AA1=reshape(Cluster1,[wd wd]);
AA2=reshape(Cluster2,[wd wd]);
AA3=reshape(Cluster3,[wd wd]);
AA4=reshape(Cluster4,[wd wd]);
AA5=reshape(Cluster5,[wd wd]);
figure(3),subplot(2,3,1),imshow(AA1);
subplot(2,3,2),imshow(AA2);
subplot(2,3,3),imshow(AA3);
subplot(2,3,4),imshow(AA4);
subplot(2,3,5),imshow(AA5);
a=AA5;
figure(4),subplot(1,3,1),imshow(a);
a1=im2bw(a);
subplot(1,3,2),imshow(a1);
hold on
mask = false(size(a1));
mask(50:150,40:20) = true;
visboundaries(mask,'Color','b');
bw2 = activecontour(a1, mask, 200, 'edge');
visboundaries(bw2,'Color','r');
title('Initial contour (blue) and final contour (red)');
Trial License -- for use to evaluate programs for possible purchase as an end-user only.
>> gui
The class handle has no Constant property or Static method named 'axes1'.
Error in gui>Load_Image_Callback (line 92)
axes(handle.axes1);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in gui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)gui('Load_Image_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
  6 comentarios
Walter Roberson
Walter Roberson el 25 de Abr. de 2019
That code does not contain a guidata call.
You need to replace the first ~ of the function definition of that callback with hObject
HEMANGI NALE
HEMANGI NALE el 29 de Abr. de 2019
thank you so much. now my code is working.

Iniciar sesión para comentar.


suoh mikoto
suoh mikoto el 28 de Abr. de 2019
I have same problem, help me.
Error using RGB>pushbutton1_Callback (line 84)
Dimensions of matrices being concatenated are not consistent.
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in RGB (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)RGB('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
  4 comentarios
Walter Roberson
Walter Roberson el 28 de Abr. de 2019
Your cell array for uigetfile has one column in the first row but 2 columns in the other rows.
suoh mikoto
suoh mikoto el 28 de Abr. de 2019
solved, thank you su much

Iniciar sesión para comentar.


Momen Elhassan
Momen Elhassan el 2 de Dic. de 2019
Editada: Momen Elhassan el 2 de Dic. de 2019
I have the same problem and only thing I've learned after browsing for so long is that the cause is the same in most cases, but no singular solution as far as I can tell. I've been searching the web for days trying to fix it to no avail.
The 'myecg' variable is an imported one that I had ready. I tried renaming it but that didn't work either.
Undefined function or variable 'myecg'.
Error in CEN320Project>pushbutton1_Callback (line 81)
y=myecg;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in CEN320Project (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)CEN320Project('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
  12 comentarios
Rik
Rik el 5 de Oct. de 2022
We are helping you. Ask a separate question after reading what Image Analyst linked you. You should also consider doing the Onramp tutorial, which is offered for free by Mathworks.
Walter Roberson
Walter Roberson el 5 de Oct. de 2022
using clear all in the middle of the program is like yanking out the chair you are standing on... together with the floor the chair is on, and the building that the floor is in, and the hill that the building is on, and the planet that the hill is on... and the sun that the planet orbits, and the local cluster that the sun is part of... and the galaxy that the local cluster is part of... and then hoping that the residual vacuum energy will still hold you up.

Iniciar sesión para comentar.


keith marcenaro
keith marcenaro el 9 de Dic. de 2019
Editada: keith marcenaro el 9 de Dic. de 2019
When I run the below .m file, it gives me the following error: helpme
Error using +
Matrix dimensions must agree.
Error in programacion1>pushbutton13_Callback (line 698)
segaltpiedesconoc=cotaaltpiedesconoc+presionaltpiedesconoc;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in programacion1 (line 47)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)programacion1('pushbutton13_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
  2 comentarios
Walter Roberson
Walter Roberson el 9 de Dic. de 2019
The .m file was not attached. Also it looks like we would need the .fig as well to execute the program.
Walter Roberson
Walter Roberson el 9 de Dic. de 2019
Also you should be creating a new Question for this.

Iniciar sesión para comentar.


Ganesh Pakanati
Ganesh Pakanati el 7 de En. de 2020
  1 comentario
Walter Roberson
Walter Roberson el 7 de En. de 2020
Either you do not have the Image Processing Toolbox installed (or licensed), or else you are using a MATLAB release before R2016a. I suspect you are using a MATLAB too old for imoverlay()

Iniciar sesión para comentar.


Iuliana Vlad
Iuliana Vlad el 10 de Mayo de 2020
Same Error.
Error in VladIuliana>calculeaza_Callback (line 876) [V1,m1,J1]=Ans2(((a3/2)/1000),(b2/1000),c2,0);
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in VladIuliana (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)VladIuliana('calculeaza_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback.

arvin
arvin el 15 de Ag. de 2020
Error using imread (line 349)
File "./sample/1.tiff" does not exist.
Error in CreateDatabase (line 20)
I = (imread(strcat('./sample/',TrainFiles(i).name)));
Error in MAIN_GUI_EMOTION>pushbutton2_Callback (line 143)
CreateDatabase(TrainDatabasePath);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in MAIN_GUI_EMOTION (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)MAIN_GUI_EMOTION('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
  1 comentario
Walter Roberson
Walter Roberson el 16 de Ag. de 2020
You are not cd'd to the directory that has a sample subdirectory inside it. Do not cd to the sample directory itself, cd to the directory that contains the sample directory.

Iniciar sesión para comentar.


BHOSALE MOHAN  VILASRAO
BHOSALE MOHAN VILASRAO el 3 de Sept. de 2020
Editada: BHOSALE MOHAN VILASRAO el 3 de Sept. de 2020
please help I am facing same kind of error:
Index exceeds matrix dimensions.
Error in RRR_Robot>btn_Forward_Callback (line 167)
handles.Pos_X.String = num2str(floor(T(1,4)));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in RRR_Robot (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)RRR_Robot('btn_Forward_Callback',hObject,eventdata,guidata(hObject))
167 handles.Pos_X.String = num2str(floor(T(1,4)));
java.lang.ClassCastException: [D cannot be cast to [Ljava.lang.Object;
at com.mathworks.toolbox.matlab.guide.LayoutArea.duplicateComplete(LayoutArea.java:960)
at com.mathworks.toolbox.matlab.guide.LayoutArea$DuplicateObserver.completed(LayoutArea.java:944)
at com.mathworks.toolbox.matlab.guide.utils.LayoutWorker.runOnMatlabThread(LayoutWorker.java:55)
at com.mathworks.jmi.MatlabWorker$2.run(MatlabWorker.java:79)
at com.mathworks.jmi.NativeMatlab.dispatchMTRequests(NativeMatlab.java:475)
K>> dbstop if error
and my code :
function varargout = RRR_Robot(varargin)
% RRR_ROBOT MATLAB code for RRR_Robot.fig
% RRR_ROBOT, by itself, creates a new RRR_ROBOT or raises the existing
% singleton*.
%
% H = RRR_ROBOT returns the handle to a new RRR_ROBOT or the handle to
% the existing singleton*.
%
% RRR_ROBOT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in RRR_ROBOT.M with the given input arguments.
%
% RRR_ROBOT('Property','Value',...) creates a new RRR_ROBOT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before RRR_Robot_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to RRR_Robot_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 RRR_Robot
% Last Modified by GUIDE v2.5 03-Sep-2020 17:09:35
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @RRR_Robot_OpeningFcn, ...
'gui_OutputFcn', @RRR_Robot_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 RRR_Robot is made visible.
function RRR_Robot_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 RRR_Robot (see VARARGIN)
% Choose default command line output for RRR_Robot
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes RRR_Robot wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = RRR_Robot_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;
function Theta_1_Callback(hObject, eventdata, handles)
% hObject handle to Theta_1 (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 Theta_1 as text
% str2double(get(hObject,'String')) returns contents of Theta_1 as a double
% --- Executes during object creation, after setting all properties.
function Theta_1_CreateFcn(hObject, eventdata, handles)
% hObject handle to Theta_1 (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 Theta_2_Callback(hObject, eventdata, handles)
% hObject handle to Theta_2 (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 Theta_2 as text
% str2double(get(hObject,'String')) returns contents of Theta_2 as a double
% --- Executes during object creation, after setting all properties.
function Theta_2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Theta_2 (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 Theta_3_Callback(hObject, eventdata, handles)
% hObject handle to Theta_3 (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 Theta_3 as text
% str2double(get(hObject,'String')) returns contents of Theta_3 as a double
% --- Executes during object creation, after setting all properties.
function Theta_3_CreateFcn(hObject, eventdata, handles)
% hObject handle to Theta_3 (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 btn_Forward.
function btn_Forward_Callback(hObject, eventdata, handles)
% hObject handle to btn_Forward (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Th_1 = str2double(handles.Theta_1.String)*pi/180;
Th_2 = str2double(handles.Theta_2.String)*pi/180;
Th_3 = str2double(handles.Theta_3.String)*pi/180;
L_1 = 20;
L_2 = 50;
L_3 = 40;
L(1) = Link([0 L_1 0 pi/2]);
L(2) = Link([0 0 L_2 0]);
L(3) = Link([0 0 L_3 0]);
Robot = SerialLink(L);
Robot.name = 'RRR_Robot';
Robot.plot([Th_1 Th_2 Th_3]);
T = Robot.fkine([Th_1 Th_2 Th_3]);
handles.Pos_X.String = num2str(floor(T(1,4)));
handles.Pos_Y.String = num2str(floor(T(2,4)));
handles.Pos_Z.String = num2str(floor(T(3,4)));
function Pos_X_Callback(hObject, eventdata, handles)
% hObject handle to Pos_X (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 Pos_X as text
% str2double(get(hObject,'String')) returns contents of Pos_X as a double
% --- Executes during object creation, after setting all properties.
function Pos_X_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pos_X (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 Pos_Y_Callback(hObject, eventdata, handles)
% hObject handle to Pos_Y (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 Pos_Y as text
% str2double(get(hObject,'String')) returns contents of Pos_Y as a double
% --- Executes during object creation, after setting all properties.
function Pos_Y_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pos_Y (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 Pos_Z_Callback(hObject, eventdata, handles)
% hObject handle to Pos_Z (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 Pos_Z as text
% str2double(get(hObject,'String')) returns contents of Pos_Z as a double
% --- Executes during object creation, after setting all properties.
function Pos_Z_CreateFcn(hObject, eventdata, handles)
% hObject handle to Pos_Z (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 btn_Inverse.
function btn_Inverse_Callback(hObject, eventdata, handles)
% hObject handle to btn_Inverse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
PX = str2double(handles.Pos_X.String);
PY = str2double(handles.Pos_Y.String);
PZ = str2double(handles.Pos_Z.String);
L_1 = 20;
L_2 = 50;
L_3 = 40;
L(1) = Link([0 L_1 0 pi/2]);
L(2) = Link([0 0 L_2 0]);
L(3) = Link([0 0 L_3 0]);
Robot = SerialLink(L);
Robot.name = 'RRR_Robot';
T = [ 1 0 0 PX;
0 1 0 PY;
0 0 1 PZ;
0 0 0 1];
J = Robot.ikine(T, [0 0 0], [1 1 1 0 0 0]) * 180/pi;
handles.Theta_1.String = num2str(floor(J(1)));
handles.Theta_2.String = num2str(floor(J(2)));
handles.Theta_3.String = num2str(floor(J(3)));
Robot.plot(J*pi/180);
  3 comentarios
BHOSALE MOHAN  VILASRAO
BHOSALE MOHAN VILASRAO el 4 de Sept. de 2020
it is giving error at handles part, the following is the result I got with breakpoint at that function.
28 gui_Singleton = 1;
K>> dbcont
166 T = Robot.fkine([Th_1 Th_2 Th_3]);
K>> dbcont
Index in position 2 exceeds array bounds (must not exceed 1).
Error in RRR_Robot>btn_Forward_Callback (line 167)
handles.Pos_X.String = num2str(floor(T(1,4)));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in RRR_Robot (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)RRR_Robot('btn_Forward_Callback',hObject,eventdata,guidata(hObject))
167 handles.Pos_X.String = num2str(floor(T(1,4)));
K>>
Walter Roberson
Walter Roberson el 7 de Sept. de 2020
Put a breakpoint at
T = Robot.fkine([Th_1 Th_2 Th_3]);
and single-step by typing dbstep ( not dbcont) . If you then ask to display T, what shows up?

Iniciar sesión para comentar.


Muhammad Hazrul
Muhammad Hazrul el 15 de Sept. de 2020
function varargout = EITAPP(varargin)
% EITAPP MATLAB code for EITAPP.fig
% EITAPP, by itself, creates a new EITAPP or raises the existing
% singleton*.
%
% H = EITAPP returns the handle to a new EITAPP or the handle to
% the existing singleton*.
%
% EITAPP('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EITAPP.M with the given input arguments.
%
% EITAPP('Property','Value',...) creates a new EITAPP or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before EITAPP_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to EITAPP_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 EITAPP
% Last Modified by GUIDE v2.5 18-Jul-2017 06:15:23
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @EITAPP_OpeningFcn, ...
'gui_OutputFcn', @EITAPP_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 EITAPP is made visible.
function EITAPP_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 EITAPP (see VARARGIN)
% Choose default command line output for EITAPP
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes EITAPP wait for user response (see UIRESUME)
% uiwait(handles.figure1);
set(handles.togglebutton5,'Enable','Off');
set(handles.pushbutton4,'Enable','Off');
cd C:\Users\hal19\Documents\MATLAB\eidors; %(for window)Change current folder to allow access to eidors
%%cd /Users/lekjianhong/Documents/MATLAB/supportpackages/eidors-v3.9/eidors;(for mac)
%%cd /Users/lekjianhong/Documents/MATLAB/supportpackages/eidors-v3.9/eidors;%!!!!!need to change the directory of the files!!!!!!
run startup;
% --- Outputs from this function are returned to the command line.
function varargout = EITAPP_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)hom
set(handles.togglebutton5,'Enable','On');
set(handles.togglebutton6,'Enable','Off');
set(handles.pushbutton1,'Enable','Off');
axes(handles.axes2);
clear
clc
%model=mk_common_model('d2c2',16);
%stim = mk_stim_patterns(16,1,'{ad}','{ad}',{},1);
model = mk_common_model('d2c2',8);
stim = mk_stim_patterns(8,1,'{ad}','{ad}',{},1);
model.fwd_model.stimulation = stim;
%Imghom = mk_image(model);
%H = calc_jacobian(Imghom);
%lambda = 0.001;
%alpha = 1;
%Nit = 100;
%model.RtR_prior = @prior_noser;
%model.hyperparameter.value = 0.08;
a=0;
runs=1;
global img;
img=1;
global true;
true=1;
global freeze;
freeze=0;
if ~isempty(instrfind)
fclose(instrfind);
delete(instrfind);
end
A = zeros(64,1);%Temp Data
B = zeros(64,1);%Temp Array use for calculation
C = zeros(40,1);%Array for Inhomogenoeus
D = zeros(40,1);%Array for Homogeneous
Arduino=serial('COM4','BaudRate',9600);%!!!!!!!!need to change the port for windows!!!!!!
fopen(Arduino);
writedata=uint16(500); %0x01F4
fwrite(Arduino,writedata,'uint16') %write datac
for s = 1:1
for i=1:64 %read 64 lines of data
%A(i,1) = fscanf(Arduino,'%f')
A(i,1) = fscanf(Arduino,'%f');
end
B(A,1) = abs(B(5,1)-B(6,1));
D(4,1) = abs(B(6,1)-B(7,1));
D(5,1) = abs(B(7,1)-B(8,1));
D(6,1) = abs(B(12,1)-B(13,1));
D(7,1) = abs(B(13,1)-B(14,1));
D(8,1) = abs(B(14,1)-B(15,1));
D(9,1) = abs(B(15,1)-B(16,1));
D(10,1) = abs(B(16,1)-B(9,1));
D(1,1) = abs(B(3,1)-B(4,1));
D(2,1) = abs(B(4,1)-B(5,1));
D(3,1);
D(11,1) = abs(B(17,1)-B(18,1));
D(12,1) = abs(B(21,1)-B(22,1));
D(13,1) = abs(B(22,1)-B(23,1));
D(14,1) = abs(B(23,1)-B(24,1));
D(15,1) = abs(B(24,1)-B(17,1));
D(16,1) = abs(B(25,1)-B(26,1));
D(17,1) = abs(B(26,1)-B(27,1));
D(18,1) = abs(B(30,1)-B(31,1));
D(19,1) = abs(B(31,1)-B(32,1));
D(20,1) = abs(B(32,1)-B(25,1));
D(21,1) = abs(B(33,1)-B(34,1));
D(22,1) = abs(B(34,1)-B(35,1));
D(23,1) = abs(B(35,1)-B(36,1));
D(24,1) = abs(B(39,1)-B(40,1));
D(25,1) = abs(B(40,1)-B(33,1));
D(26,1) = abs(B(41,1)-B(42,1));
D(27,1) = abs(B(42,1)-B(43,1));
D(28,1) = abs(B(43,1)-B(44,1));
D(29,1) = abs(B(44,1)-B(45,1));
D(30,1) = abs(B(48,1)-B(41,1));
D(31,1) = abs(B(49,1)-B(50,1));
D(32,1) = abs(B(50,1)-B(51,1));
D(33,1) = abs(B(51,1)-B(52,1));
D(34,1) = abs(B(52,1)-B(53,1));
D(35,1) = abs(B(53,1)-B(54,1));
D(36,1) = abs(B(58,1)-B(59,1));
D(37,1) = abs(B(59,1)-B(60,1));
D(38,1) = abs(B(60,1)-B(61,1));
D(39,1) = abs(B(61,1)-B(62,1));
D(40,1) = abs(B(62,1)-B(63,1));
Hom(:,s) = D;
end
disp('Homogeneous data DONE')
while true==1 %%Loop Program forever
try %%Keep trying for vector Data from ardunio file
for i=1:64 %read 64 lines of data
A(i,1) = fscanf(Arduino,'%f')
end
B = A;
C(1,1) = abs(B(3,1)-B(4,1));
C(2,1) = abs(B(4,1)-B(5,1));
C(3,1) = abs(B(5,1)-B(6,1));
C(4,1) = abs(B(6,1)-B(7,1));
C(5,1) = abs(B(7,1)-B(8,1));
C(6,1) = abs(B(12,1)-B(13,1));
C(7,1) = abs(B(13,1)-B(14,1));
C(8,1) = abs(B(14,1)-B(15,1));
C(9,1) = abs(B(15,1)-B(16,1));
C(10,1) = abs(B(16,1)-B(9,1));
C(11,1) = abs(B(17,1)-B(18,1));
C(12,1) = abs(B(21,1)-B(22,1));
C(13,1) = abs(B(22,1)-B(23,1));
C(14,1) = abs(B(23,1)-B(24,1));
C(15,1) = abs(B(24,1)-B(17,1));
C(16,1) = abs(B(25,1)-B(26,1));
C(17,1) = abs(B(26,1)-B(27,1));
C(18,1) = abs(B(30,1)-B(31,1));
C(19,1) = abs(B(31,1)-B(32,1));
C(20,1) = abs(B(32,1)-B(25,1));
C(21,1) = abs(B(33,1)-B(34,1));
C(22,1) = abs(B(34,1)-B(35,1));
C(23,1) = abs(B(35,1)-B(36,1));
C(25,1) = abs(B(39,1)-B(40,1));
C(25,1) = abs(B(40,1)-B(33,1));
C(26,1) = abs(B(41,1)-B(42,1));
C(27,1) = abs(B(42,1)-B(43,1));
C(28,1) = abs(B(43,1)-B(44,1));
C(29,1) = abs(B(44,1)-B(45,1));
C(30,1) = abs(B(48,1)-B(41,1));
C(31,1) = abs(B(49,1)-B(50,1));
C(32,1) = abs(B(50,1)-B(51,1));
C(33,1) = abs(B(51,1)-B(52,1));
C(34,1) = abs(B(52,1)-B(53,1));
C(35,1) = abs(B(53,1)-B(54,1));
C(36,1) = abs(B(58,1)-B(59,1));
C(37,1) = abs(B(59,1)-B(60,1));
C(38,1) = abs(B(60,1)-B(61,1));
C(39,1) = abs(B(61,1)-B(62,1));
C(40,1) = abs(B(62,1)-B(63,1));
%%Image=(inv_solve(mk_common_model('d2c2',16),Homogeneous,DataInHomogeneous)); %%Algorithm to solve 256 data points to reconstruct image
%D = mean(Hom,2);
Image1 = inv_solve(model,D,C); % regularization
T = 0.25*max(abs(Image1.elem_data(:)));
Image1.elem_data = soft(Image1.elem_data,T);
Image1.calc_colours.npoints = 128;
Image1.calc_slices.filter = ones(3)/9;
%{
Image2 = mk_image(model); % for ista
T = 0.25*max(abs(Image.elem_data(:)));
[x,~] = ista(C-D, H, lambda, alpha, Nit, T);
Image2.elem_data = x;
Image2.calc_colours.npoints = 128;
Image2.calc_slices.filter = ones(3)/9;
%}
%{
StdHom = std(Hom,0,2); % STD along Matrix rows
Maxstd = max(StdHom);
%}
%{
Diff = Hom - repmat(Hom(:,1),1,size(Hom,2));
Maxstd = max(max(Diff));
Img0 = Image1;
Img0.elem_data(:) = 1;
stdinhom = max(C-D);
X = ['Maximum Diff data is', num2str(Maxstd), 'and Std of Inhom is', num2str(stdinhom)];
disp(X);
%}
if freeze == 0
%if stdinhom <= Maxstd
%show_slices(Img0);
%else
show_slices(Image1);
%end
%show_slices(Image2);
else
pause(0.2);
end
fclose('all'); %%Keep closing txt file as to avoid crash in program
pause(0.2); %%Buffer time for program to process each individual(256 data points) for image reconstruction
catch %%Catch vector data invalidity from arduino file
pause(0.1);
% message = showinfowindow({'Please Wait...'... %%Display Message
% 'Acquiring Data...',...
% 'Refreshing...'},'Data Acquisition');
% pause(1); %%Buffer time for program to process ardunio inputs
% close(message)
% runs=runs+1;
% if(runs==10) %%Only 10 refresh cycles total before program terminates to avoid crash
% message1=warndlg('Restart Program...Too many Refreshes...Program Terminated.');
% waitfor(message1); %%Wait for user to close message box before terminating program
% close all hidden;
% break;
% end
end
end
% --- 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)
global true
true=0;
fclose('all');
close all force;
% --- 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)
global img;
F = getframe(handles.axes2);
Image = frame2im(F);
%%cd C:\Users\-\Desktop\DIP_DATA
cd C:\Users\hal19\Documents\MATLAB\eidors;
imwrite( Image, sprintf('image%d.jpg', img) );
img=img+1;
cd C:\Users\hal19\Documents\MATLAB\eidors;
%%cd C:\Users\-\Documents\MATLAB\eidors-v3.9\eidors;
% --- Executes on button press in togglebutton5.
function togglebutton5_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of togglebutton5
set(handles.pushbutton4,'Enable','On');
button_state = get(hObject,'Value');
global freeze;
if button_state == get(hObject,'Max')
set(handles.togglebutton5,'string','Unpause');
freeze=1;
else
set(handles.pushbutton4,'Enable','Off');
set(handles.togglebutton5,'string','Pause');
freeze=0;
end
% --- Executes on button press in togglebutton6.
function togglebutton6_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of togglebutton6
set(handles.pushbutton1,'Enable','Off');
button_state = get(hObject,'Value');
global true;
if button_state == get(hObject,'Max')
set(handles.togglebutton6,'string','Stop');
true=1;
imdl= mk_common_model('j2C',16);
img_1 = mk_image(imdl);
img_1.calc_colours.npoints = 128;
img_1.calc_slices.filter = ones(3)/9;
img_2 = img_1;
load('Simulation.mat','SimulationData');
xaxis=SimulationData(:,1);
yaxis=SimulationData(:,2);
counter=1;
radius=0.1;
while true==1
try
select_fcn =@(x,y,z) (x-(xaxis(counter))).^2+(y-(yaxis(counter))).^2<radius^2;
img_2.elem_data = 1 + elem_select(img_2.fwd_model, select_fcn);
if counter > 47 && counter<100
%radius=radius-0.001;
radius=radius-0;
elseif counter>=1 && counter<48
%radius=radius+0.001;
radius=radius+0;
end
stim = mk_stim_patterns(16,1,[0,1],[0,1],{},1);
img_1.fwd_model.stimulation = stim;
homg_data=fwd_solve( img_1 );
H = calc_jacobian(img_1);
lambda = 0.001; alpha = 1; Nit = 100;
%axes(handles.axes3);
%show_fem(img_2);
%show_slices(img_2);
img_2.fwd_model.stimulation = stim;
inhomg_data=fwd_solve( img_2 );
noise_level= std(inhomg_data.meas - homg_data.meas)/10^(20/20);
inhomg_data.meas = inhomg_data.meas + noise_level* ...
randn(size(inhomg_data.meas));
axes(handles.axes2);
[x,~] = ista(inhomg_data.meas-homg_data.meas, H, lambda, alpha, Nit);
img_2.elem_data = x;
show_slices(img_2);
axes(handles.axes3);
imgrec = inv_solve(mk_common_model('d2c2',16),homg_data,inhomg_data);
imgrec.elem_data = soft(imgrec.elem_data,0.005);
imgrec.calc_colours.npoints = 128;
imgrec.calc_slices.filter = ones(3)/9;
show_slices(imgrec);
counter=counter+1;
pause(0.2);
catch
message1=warndlg({'End of Simulation!'...
'Press stop to carry on with real system'},'Simulation');
waitfor(message1);
break;
end
end
else
true=0;
set(handles.togglebutton6,'string','Simulate');
set(handles.pushbutton1,'Enable','On');
cla(handles.axes2,'reset')
set(handles.axes2,'Color','black');
cla(handles.axes3,'reset')
set(handles.axes3,'Color','black');
set(handles.axes3,'YTick',[]);
set(handles.axes3,'XTick',[]);
end
Hi there,
I am currently facing the same issue here. Would be glad if you could assist me. I have tried the same method you issued to the first question and it gave me this.
Thank you

Taufiq Nashrullah
Taufiq Nashrullah el 9 de Nov. de 2020
when i run my .m file, i got error
Undefined function 'fitcknn' for input arguments
of type 'double'.
Error in Main>pushbutton3_Callback (line 123)
hasil1=fitcknn(Z,training,group);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Main (line 17)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)Main('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
this is i run dbstop if error , and the result
Undefined function 'fitcknn' for input arguments
of type 'double'.
Error in Main>pushbutton3_Callback (line 123)
hasil1=fitcknn(Z,training,group);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Main (line 17)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)Main('pushbutton3_Callback',hObject,eventdata,guidata(hObject))
123 hasil1=fitcknn(Z,training,group);
any idea why?, here's the code from .m
function varargout = Main(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton' , gui_Singleton, ...
'gui_OpeningFcn', @Main_OpeningFcn, ...
'gui_OutputFcn', @Main_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
function Main_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = Main_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
[filename,pathname] = uigetfile('*.jpg');
Img = imread(fullfile(pathname,filename));
handles.I = Img;
guidata(hObject,handles)
axes(handles.axes1)
imshow(Img)
title(filename);
function pushbutton3_Callback(hObject, eventdata, handles)
% split rgb
Img = handles.I;
% find the HSI value
RGB = im2double(Img);
Red = RGB(:,:,1);
Green = RGB(:,:,2);
Blue = RGB(:,:,3);
%Hue
atas=1/2*((Red-Green)+(Red-Blue));
bawah=((Red-Green).^2+((Red-Blue).*(Green-Blue))).^0.5;
teta = acosd (top ./ (bottom));
if Blue >= Green
H = 360 - theta;
else
H = theta;
end
H = H/360;
[r c] = size(H);
for i=1 : r
for j=1 : c
z = H(i,j);
z (isnan (z)) = 0; % isnan is is not none meaning if it's not a number it will give 0
H(i,j) = z;
end
end
%S
S = 1- (3 ./ (sum (RGB, 3))). * Min (RGB, [], 3);
[r c] = size(S);
for i=1 : r
for j=1 : c
z = S(i,j);
z(isnan(z)) = 0;
S(i,j) = z;
end
end
%I
I=(Red+Green+Blue)/3;
MeanR = mean2(Red);
MeanG = mean2 (Green);
MeanB = mean2(Blue);
MeanH = mean2(H);
MeanS = mean2(S);
MeanI = mean2(I);
VarRed = var (Red (:)); VarGreen = var (Green (:)); VarBlue = var (Blue (:));
VarH = var (H (:)); VarS = var (S (:)); VarI = var (I (:));
RangeR = ((max(max(Red)))-(min(min(Red))));
RangeG = ((max(max(Green)))-(min(min(Green))));
RangeB = ((max(max(Blue)))-(min(min(Blue))));
RangeH = ((max(max(H)))-(min(min(H))));
RangeS = ((max(max(S)))-(min(min(S))));
RangeI = ((max (max (I))) - (min (min (I))));
data = get(handles.uitable2,'Data');
data {1,1} = num2str (MeanR);
data {2,1} = num2str (MeanG);
data {3,1} = num2str (MeanB);
data {4,1} = num2str (MeanH);
data{5,1} = num2str(MeanS);
data{6,1} = num2str(MeanI);
data {1,2} = num2str (VarRed);
data {2,2} = num2str (VarGreen);
data {3,2} = num2str (VarBlue);
data {4,2} = num2str (VarH);
data {5.2} = num2str (VarS);
data{6,2} = num2str(VarI);
data{1,3} = num2str(RangeR);
data{2,3} = num2str(RangeG);
data{3,3} = num2str(RangeB);
data{4,3} = num2str(RangeH);
data{5,3} = num2str(RangeS);
data {6,3} = num2str (RangeI);
set(handles.uitable2,'Data',data,'ForegroundColor',[0 0 0])
training1 = xlsread('Data Training');
group = training1(:,25);
training = [training1(:,1) training1(:,2) training1(:,3) training1(:,4) training1(:,5) training1(:,6) training1(:,7) training1(:,8) training1(:,9) training1(:,10) training1(:,11) training1(:,12) training1(:,13) training1(:,14) training1(:,15) training1(:,16) training1(:,17) training1(:,18)];
Z = [MeanR MeanG MeanB MeanH MeanS MeanI VarRed VarGreen VarBlue VarH VarS VarI RangeR RangeG RangeB RangeH RangeS RangeI];
hasil1=fitcknn(Z,training,group);
if hasil1==1
x='MATURE';
elseif hasil1==2
x='HALF-MATURE';
elseif hasil1==3
x='IMMATURE';
end
set(handles.edit2,'string',x);
function pushbutton4_Callback(hObject, eventdata, handles)
image_folder = 'C: \ Users \ ASUS.DESKTOP-EHQUTKI \ Desktop \ SCREEN \ Program \ Program \ HSI Tomato Maturity Detection \ Training \ mature' ;
filenames = dir(fullfile(image_folder, '*.jpg'));
total_images = numel(filenames);
Z1=[];
for n = 1:total_images
full_name= fullfile(image_folder, filenames(n).name);
Img = imread(full_name);
% find the HSI value
RGB = im2double(Img);
Red = RGB(:,:,1);
Green = RGB(:,:,2);
Blue = RGB(:,:,3);
%Hue
atas=1/2*((Red-Green)+(Red-Blue));
bawah=((Red-Green).^2+((Red-Blue).*(Green-Blue))).^0.5;
teta = acosd (top ./ (bottom));
if Blue >= Green
H = 360 - theta;
else
H = theta;
end
H = H/360;
[r c] = size(H);
for i=1 : r
for j=1 : c
z = H(i,j);
z(isnan(z)) = 0;
H(i,j) = z;
end
end
%S
S = 1- (3 ./ (sum (RGB, 3))). * Min (RGB, [], 3);
[r c] = size(S);
for i=1 : r
for j=1 : c
z = S(i,j);
z(isnan(z)) = 0;
S(i,j) = z;
end
end
%I
I=(Red+Green+Blue)/3;
MeanR = mean2(Red);
MeanG = mean2 (Green);
MeanB = mean2(Blue);
MeanH = mean2(H);
MeanS = mean2(S);
MeanI = mean2(I);
VarRed = var (Red (:));
VarGreen = var (Green (:));
VarBlue = var (Blue (:));
VarH = var (H (:));
VarS = var (S (:));
VarI = var (I (:));
RangeR = ((max(max(Red)))-(min(min(Red))));
RangeG = ((max(max(Green)))-(min(min(Green))));
RangeB = ((max(max(Blue)))-(min(min(Blue))));
RangeH = ((max(max(H)))-(min(min(H))));
RangeS = ((max(max(S)))-(min(min(S))));
RangeI = ((max (max (I))) - (min (min (I))));
sdR = std2 (Red);
sdG = std2(Green);
sdB = std2(Blue);
sdH = std2(H);
sdS = std2(S);
sdI = std2(I);
Z = [MeanR MeanG MeanB MeanH MeanS MeanI VarRed VarGreen VarBlue VarH VarS VarI RangeR RangeG RangeB RangeH RangeS RangeI sdR sdG sdB sdH sdS sdI 1];
Z1=[Z1;Z];
end
image_folder = 'C: \ Users \ ASUS.DESKTOP-EHQUTKI \ Desktop \ SCRIPT \ Program \ HSI Tomato Maturity Detection \ Training \ half-mature' ;
filenames = dir(fullfile(image_folder, '*.jpg'));
total_images = numel(filenames);
for n = 1:total_images
full_name= fullfile(image_folder, filenames(n).name);
Img = imread(full_name);
% find the HSI value
RGB = im2double(Img);
Red = RGB(:,:,1);
Green = RGB(:,:,2);
Blue = RGB(:,:,3);
%Hue
atas=1/2*((Red-Green)+(Red-Blue));
bawah=((Red-Green).^2+((Red-Blue).*(Green-Blue))).^0.5;
teta = acosd (top ./ (bottom));
if Blue >= Green
H = 360 - theta;
else
H = theta;
end
H = H/360;
[r c] = size(H);
for i=1 : r
for j=1 : c
z = H(i,j);
z(isnan(z)) = 0;
H(i,j) = z;
end
end
%S
S = 1- (3 ./ (sum (RGB, 3))). * Min (RGB, [], 3);
[r c] = size(S);
for i=1 : r
for j=1 : c
z = S(i,j);
z(isnan(z)) = 0;
S(i,j) = z;
end
end
%I
I=(Red+Green+Blue)/3;
MeanR = mean2(Red);
MeanG = mean2 (Green);
MeanB = mean2(Blue);
MeanH = mean2(H);
MeanS = mean2(S);
MeanI = mean2(I);
VarRed = var (Red (:));
VarGreen = var (Green (:));
VarBlue = var (Blue (:));
VarH = var (H (:));
VarS = var (S (:));
VarI = var (I (:));
RangeR = ((max(max(Red)))-(min(min(Red))));
RangeG = ((max(max(Green)))-(min(min(Green))));
RangeB = ((max(max(Blue)))-(min(min(Blue))));
RangeH = ((max(max(H)))-(min(min(H))));
RangeS = ((max(max(S)))-(min(min(S))));
RangeI = ((max (max (I))) - (min (min (I))));
sdR = std2 (Red);
sdG = std2(Green);
sdB = std2(Blue);
sdH = std2(H);
sdS = std2(S);
sdI = std2(I);
Z = [MeanR MeanG MeanB MeanH MeanS MeanI VarRed VarGreen VarBlue VarH VarS VarI RangeR RangeG RangeB RangeH RangeS RangeI sdR sdG sdB sdH sdS sdI 2];
Z1=[Z1;Z];
end
image_folder = 'C: \ Users \ ASUS.DESKTOP-EHQUTKI \ Desktop \ SCRIPT \ Program \ HSI Tomato Maturity Detection \ Training \ immature' ;
filenames = dir(fullfile(image_folder, '*.jpg'));
total_images = numel(filenames);
for n = 1:total_images
full_name= fullfile(image_folder, filenames(n).name);
Img = imread(full_name);
% find the HSI value
RGB = im2double(Img);
Red = RGB(:,:,1);
Green = RGB(:,:,2);
Blue = RGB(:,:,3);
%Hue
atas=1/2*((Red-Green)+(Red-Blue));
bawah=((Red-Green).^2+((Red-Blue).*(Green-Blue))).^0.5;
teta = acosd (top ./ (bottom));
if Blue >= Green
H = 360 - theta;
else
H = theta;
end
H = H/360;
[r c] = size(H);
for i=1 : r
for j=1 : c
z = H(i,j);
z(isnan(z)) = 0;
H(i,j) = z;
end
end
%S
S = 1- (3 ./ (sum (RGB, 3))). * Min (RGB, [], 3);
[r c] = size(S);
for i=1 : r
for j=1 : c
z = S(i,j);
z(isnan(z)) = 0;
S(i,j) = z;
end
end
%I
I=(Red+Green+Blue)/3;
MeanR = mean2(Red);
MeanG = mean2 (Green);
MeanB = mean2(Blue);
MeanH = mean2(H);
MeanS = mean2(S);
MeanI = mean2(I);
VarRed = var (Red (:));
VarGreen = var (Green (:));
VarBlue = var (Blue (:));
VarH = var (H (:));
VarS = var (S (:));
VarI = var (I (:));
RangeR = ((max(max(Red)))-(min(min(Red))));
RangeG = ((max(max(Green)))-(min(min(Green))));
RangeB = ((max(max(Blue)))-(min(min(Blue))));
RangeH = ((max(max(H)))-(min(min(H))));
RangeS = ((max(max(S)))-(min(min(S))));
RangeI = ((max (max (I))) - (min (min (I))));
sdR = std2 (Red);
sdG = std2(Green);
sdB = std2(Blue);
sdH = std2(H);
sdS = std2(S);
sdI = std2(I);
Z = [MeanR MeanG MeanB MeanH MeanS MeanI VarRed VarGreen VarBlue VarH VarS VarI RangeR RangeG RangeB RangeH RangeS RangeI sdR sdG sdB sdH sdS sdI 3];
Z1=[Z1;Z];
end
xlswrite('Data Training',Z1);
set(handles.edit1,'string','Training Color Done');
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function uitable2_CellEditCallback(hObject, eventdata, handles)
Please answer !

SHALINI SATHYA
SHALINI SATHYA el 9 de En. de 2021
CAN ANYONE HELP ME TO SOLVE THIS ERROR:
Unrecognized function or variable 'svmtrain'.
Error in main>multisvm (line 991)
models(k) = svmtrain(TrainingSet,G1vAll);
Error in main>pushbutton14_Callback (line 866)
result = multisvm(data_feat,data_label,test_data);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in main (line 18)
gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)main('pushbutton14_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
THIS IS MY CODE:
function varargout = main(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_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 main is made visible.
function main_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 main (see VARARGIN)
% Choose default command line output for main
% Update handles structure
guidata(hObject, handles);
axes(handles.axes1); axis off
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_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, pathname, filterindex]=uigetfile( ...
{'*.jpg','JPEG File (*.jpg)'; ...
'*.*','Any Image file (*.*)'}, ...
'Pick an image file');
var=strcat(pathname,filename);
k=imread(var);
handles.YY = k;
set(handles.edit1,'String',var);
z=k;
guidata(hObject,handles);
%guidata(hObject,handles);
axes(handles.axes1);
imshow(k);
% set(handles.axes1);
title('Input Image');
set(handles.pushbutton1,'enable','off');
set(handles.pushbutton16,'enable','on');
% --- 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)
k=handles.YY;
j=rgb2gray(k);
handles.XX=j;
figure,subplot(2,2,2),imshow(j);title('gray Image');
set(handles.pushbutton1,'enable','off');
set(handles.pushbutton2,'enable','off');
set(handles.pushbutton4,'enable','on');
% --- 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)
str=get(handles.edit1,'String');
I = imread(str);
h = ones(5,5)/25;
I2 = imfilter(I,h);
figure
imshow(I2)
title('Filtered Image')
set(handles.pushbutton3,'enable','off');
set(handles.pushbutton12,'enable','on');
% --- 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)
ei=25;
st=35;
%k=10
k=ei*st;
I=handles.YY;
%I = imread('1.jpg');
%h=filter matrx
h = ones(ei,st) / k;
I1 = imfilter(I,h,'symmetric');
IG=rgb2gray(I1);
%Converting to BW
I11 = imadjust(IG,stretchlim(IG),[]);
level = graythresh(I11);
BWJ = im2bw(I11,level);
dim = size(BWJ)
IN=ones(dim(1),dim(2));
BW=xor(BWJ,IN); %inverting
figure,subplot(2,2,2), imshow(BW), title('Black and White');
set(handles.pushbutton1,'enable','off');
set(handles.pushbutton2,'enable','off');
set(handles.pushbutton3,'enable','on');
set(handles.pushbutton4,'enable','off');
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (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 pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%I=imread('cancer.bmp');
I=handles.YY;
[y,x,z]=size(I);
myI=double(I);
H=zeros(y,x);
S=H;
HS_I=H;
for i=1:x
for j=1:y
HS_I(j,i)=((myI(j,i,1)+myI(j,i,2)+myI(j,i,3))/3);
S(j,i)=1-3*min(myI(j,i,:))/(myI(j,i,1)+myI(j,i,2)+myI(j,i,3));
if ((myI(j,i,1)==myI(j,i,2))&(myI(j,i,2)==myI(j,i,3)))
Hdegree=0;
else
Hdegree=acos(0.5*(2*myI(j,i,1)-myI(j,i,2)-myI(j,i,3))/((myI(j,i,1)-myI(j,i,2))^2+(myI(j,i,1)-myI(j,i,3))*(myI(j,i,2)-myI(j,i,3)))^0.5);
end
if (myI(j,i,2)>=myI(j,i,3))
H(j,i)=Hdegree;
else
H(j,i)=(2*pi-Hdegree);
end
end
end
Hth1=0.9*2*pi; Hth2=0.1*2*pi;
Nred=0;
for i=1:x
for j=1:y
if ((H(j,i)>=Hth1)||(H(j,i)<=Hth2))
Nred=Nred+1;
end
end
end
Ratio=Nred/(x*y);
if (Ratio>=0.6)
Red=1
else
Red=0
end
HS_I=uint8(HS_I);
figure(1);
imshow(I);
figure(2);
imshow(HS_I);
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
createffnn
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% NET = trainnet(net,IMGDB);
str=get(handles.edit1,'String');
I1 = imread(str);
I = im2double(I1);
HSV = rgb2hsv(I);
H = HSV(:,:,1); H = H(:);
S = HSV(:,:,2); S = S(:);
V = HSV(:,:,3); V = V(:);
idx = kmeans([H S V], 4);
imshow(I1);
figure,imshow(ind2rgb(reshape(idx, size(I,1), size(I, 2)), [0 0 1; 0 0.8 0]))
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (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 pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 [ Unow, center, now_obj_fcn ] = FCMforImage( img, clusterNum )
if nargin < 2
clusterNum = 2; % number of cluster
end
[row, col] = size(img);
expoNum = 2; % fuzzification parameter
epsilon = 0.001; % stopping condition
mat_iter = 100; % number of maximun iteration
Upre = rand(row, col, clusterNum);
dep_sum = sum(Upre, 3);
dep_sum = repmat(dep_sum, [1,1, clusterNum]);
Upre = Upre./dep_sum;
center = zeros(clusterNum,1);
for i=1:clusterNum
center(i,1) = sum(sum(Upre(:,:,i).*img))/sum(sum(Upre(:,:,i)));
end
pre_obj_fcn = 0;
for i=1:clusterNum
pre_obj_fcn = pre_obj_fcn + sum(sum((Upre(:,:,i) .*img - center(i)).^2));
end
%fprintf('Initial objective fcn = %f\n', pre_obj_fcn);
for iter = 1:mat_iter
Unow = zeros(size(Upre));
for i=1:row
for j=1:col
for uII = 1:clusterNum
tmp = 0;
for uJJ = 1:clusterNum
disUp = abs(img(i,j) - center(uII));
disDn = abs(img(i,j) - center(uJJ));
tmp = tmp + (disUp/disDn).^(2/(expoNum-1));
end
Unow(i,j, uII) = 1/(tmp);
end
end
end
now_obj_fcn = 0;
for i=1:clusterNum
now_obj_fcn = now_obj_fcn + sum(sum((Unow(:,:,i) .*img - center(i)).^2));
end
% fprintf('Iter = %d, Objective = %f\n', iter, now_obj_fcn);
if max(max(max(abs(Unow-Upre))))<epsilon || abs(now_obj_fcn - pre_obj_fcn)<epsilon
break;
else
Upre = Unow.^expoNum;
for i=1:clusterNum
center(i,1) = sum(sum(Upre(:,:,i).*img))/sum(sum(Upre(:,:,i)));
end
pre_obj_fcn = now_obj_fcn;
end
end
% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (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 pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str=get(handles.edit1,'String');
I1 = imread(str);
str=rgb2gray(I1);
imwrite(str,'img.tif','tiff');
img = double(imread('img.tif'));
clusterNum = 2;
[ Unow, center, now_obj_fcn ] = FCMforImage( img, clusterNum );
figure;
subplot(2,2,1); imshow(img,[]);
for i=1:clusterNum
subplot(2,2,i+1);
imshow(Unow(:,:,i),[]);
imwrite(Unow(:,:,i),'seg.jpg');
end
imshow('seg.jpg'); title('Segmented Image');
set(handles.pushbutton13,'enable','on');
set(handles.pushbutton12,'enable','off');
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s=get(handles.edit1,'String');
I = imread(s);
I=rgb2gray(I);
glcms = graycomatrix(I);
getData()
% Derive Statistics from GLCM
stats = graycoprops(glcms,'Contrast Correlation Energy Homogeneity');
Contrast = stats.Contrast;
Correlation = stats.Correlation;
Energy = stats.Energy;
Homogeneity = stats.Homogeneity;
seg_img=imread('seg.jpg');
Mean = mean2(seg_img);
Standard_Deviation = std2(seg_img);
Entropy = entropy(seg_img);
RMS = mean2(rms(seg_img));
%Skewness = skewness(img)
Variance = mean2(var(double(seg_img)));
a = sum(double(seg_img(:)));
Smoothness = 1-(1/(1+a));
Kurtosis = kurtosis(double(seg_img(:)));
Skewness = skewness(double(seg_img(:)));
% Inverse Difference Movement
m = size(seg_img,1);
n = size(seg_img,2);
in_diff = 0;
for i = 1:m
for j = 1:n
temp = seg_img(i,j)./(1+(i-j).^2);
in_diff = in_diff+temp;
end
end
IDM = double(in_diff);
feat = [Contrast,Correlation,Energy,Homogeneity, Mean, Standard_Deviation, Entropy, RMS, Variance, Smoothness, Kurtosis, Skewness, IDM];
img = imread(s);
gaborArray = gaborFilterBank(5,8,39,39); % Generates the Gabor filter bank
featureVector = gaborFeatures(img,gaborArray,4,4);
disp('Gabor Feature');
featureVector
save('Gaborfeature.mat','featureVector');
% GLCM2 = graycomatrix(I,'Offset',[2 0;0 2]);
% features = GLCM_Features1(GLCM2,0)
set(handles.pushbutton14,'enable','on');
set(handles.pushbutton13,'enable','off');
msgbox('Feature Extracted Done');
clear all;
function [out] = GLCM_Features1(glcmin,pairs)
if ((nargin > 2) || (nargin == 0))
error('Too many or too few input arguments. Enter GLCM and pairs.');
elseif ( (nargin == 2) )
if ((size(glcmin,1) <= 1) || (size(glcmin,2) <= 1))
error('The GLCM should be a 2-D or 3-D matrix.');
elseif ( size(glcmin,1) ~= size(glcmin,2) )
error('Each GLCM should be square with NumLevels rows and NumLevels cols');
end
elseif (nargin == 1)
pairs = 0;
if ((size(glcmin,1) <= 1) || (size(glcmin,2) <= 1))
error('The GLCM should be a 2-D or 3-D matrix.');
elseif ( size(glcmin,1) ~= size(glcmin,2) )
error('Each GLCM should be square with NumLevels rows and NumLevels cols');
end
end
format long e
if (pairs == 1)
newn = 1;
for nglcm = 1:2:size(glcmin,3)
glcm(:,:,newn) = glcmin(:,:,nglcm) + glcmin(:,:,nglcm+1);
newn = newn + 1;
end
elseif (pairs == 0)
glcm = glcmin;
end
size_glcm_1 = size(glcm,1);
size_glcm_2 = size(glcm,2);
size_glcm_3 = size(glcm,3);
out.autoc = zeros(1,size_glcm_3);
out.contr = zeros(1,size_glcm_3);
out.corrm = zeros(1,size_glcm_3);
out.corrp = zeros(1,size_glcm_3);
out.cprom = zeros(1,size_glcm_3);
out.cshad = zeros(1,size_glcm_3);
out.dissi = zeros(1,size_glcm_3);
out.energ = zeros(1,size_glcm_3);
out.entro = zeros(1,size_glcm_3);
out.homom = zeros(1,size_glcm_3);
out.homop = zeros(1,size_glcm_3);
out.maxpr = zeros(1,size_glcm_3);
out.sosvh = zeros(1,size_glcm_3);
out.savgh = zeros(1,size_glcm_3);
out.svarh = zeros(1,size_glcm_3);
out.senth = zeros(1,size_glcm_3);
out.dvarh = zeros(1,size_glcm_3);
out.denth = zeros(1,size_glcm_3);
out.inf1h = zeros(1,size_glcm_3);
out.inf2h = zeros(1,size_glcm_3);
out.indnc = zeros(1,size_glcm_3);
out.idmnc = zeros(1,size_glcm_3);
glcm_sum = zeros(size_glcm_3,1);
glcm_mean = zeros(size_glcm_3,1);
glcm_var = zeros(size_glcm_3,1);
u_x = zeros(size_glcm_3,1);
u_y = zeros(size_glcm_3,1);
s_x = zeros(size_glcm_3,1);
s_y = zeros(size_glcm_3,1);
p_x = zeros(size_glcm_1,size_glcm_3);
p_y = zeros(size_glcm_2,size_glcm_3);
p_xplusy = zeros((size_glcm_1*2 - 1),size_glcm_3);
p_xminusy = zeros((size_glcm_1),size_glcm_3);
hxy = zeros(size_glcm_3,1);
hxy1 = zeros(size_glcm_3,1);
hx = zeros(size_glcm_3,1);
hy = zeros(size_glcm_3,1);
hxy2 = zeros(size_glcm_3,1);
for k = 1:size_glcm_3
glcm_sum(k) = sum(sum(glcm(:,:,k)));
glcm(:,:,k) = glcm(:,:,k)./glcm_sum(k);
glcm_mean(k) = mean2(glcm(:,:,k));
glcm_var(k) = (std2(glcm(:,:,k)))^2;
for i = 1:size_glcm_1
for j = 1:size_glcm_2
out.contr(k) = out.contr(k) + (abs(i - j))^2.*glcm(i,j,k);
out.dissi(k) = out.dissi(k) + (abs(i - j)*glcm(i,j,k));
out.energ(k) = out.energ(k) + (glcm(i,j,k).^2);
out.entro(k) = out.entro(k) - (glcm(i,j,k)*log(glcm(i,j,k) + eps));
out.homom(k) = out.homom(k) + (glcm(i,j,k)/( 1 + abs(i-j) ));
out.homop(k) = out.homop(k) + (glcm(i,j,k)/( 1 + (i - j)^2));
out.sosvh(k) = out.sosvh(k) + glcm(i,j,k)*((i - glcm_mean(k))^2);
out.indnc(k) = out.indnc(k) + (glcm(i,j,k)/( 1 + (abs(i-j)/size_glcm_1) ));
out.idmnc(k) = out.idmnc(k) + (glcm(i,j,k)/( 1 + ((i - j)/size_glcm_1)^2));
u_x(k) = u_x(k) + (i)*glcm(i,j,k);
u_y(k) = u_y(k) + (j)*glcm(i,j,k);
end
end
out.maxpr(k) = max(max(glcm(:,:,k)));
end
for k = 1:size_glcm_3
for i = 1:size_glcm_1
for j = 1:size_glcm_2
p_x(i,k) = p_x(i,k) + glcm(i,j,k);
p_y(i,k) = p_y(i,k) + glcm(j,i,k); % taking i for j and j for i
if (ismember((i + j),[2:2*size_glcm_1]))
p_xplusy((i+j)-1,k) = p_xplusy((i+j)-1,k) + glcm(i,j,k);
end
if (ismember(abs(i-j),[0:(size_glcm_1-1)]))
p_xminusy((abs(i-j))+1,k) = p_xminusy((abs(i-j))+1,k) +...
glcm(i,j,k);
end
end
end
end
for k = 1:(size_glcm_3)
for i = 1:(2*(size_glcm_1)-1)
out.savgh(k) = out.savgh(k) + (i+1)*p_xplusy(i,k);
out.senth(k) = out.senth(k) - (p_xplusy(i,k)*log(p_xplusy(i,k) + eps));
end
end
for k = 1:(size_glcm_3)
for i = 1:(2*(size_glcm_1)-1)
out.svarh(k) = out.svarh(k) + (((i+1) - out.senth(k))^2)*p_xplusy(i,k);
end
end
for k = 1:size_glcm_3
for i = 0:(size_glcm_1-1)
out.denth(k) = out.denth(k) - (p_xminusy(i+1,k)*log(p_xminusy(i+1,k) + eps));
out.dvarh(k) = out.dvarh(k) + (i^2)*p_xminusy(i+1,k);
end
end
for k = 1:size_glcm_3
hxy(k) = out.entro(k);
for i = 1:size_glcm_1
for j = 1:size_glcm_2
hxy1(k) = hxy1(k) - (glcm(i,j,k)*log(p_x(i,k)*p_y(j,k) + eps));
hxy2(k) = hxy2(k) - (p_x(i,k)*p_y(j,k)*log(p_x(i,k)*p_y(j,k) + eps));
end
hx(k) = hx(k) - (p_x(i,k)*log(p_x(i,k) + eps));
hy(k) = hy(k) - (p_y(i,k)*log(p_y(i,k) + eps));
end
out.inf1h(k) = ( hxy(k) - hxy1(k) ) / ( max([hx(k),hy(k)]) );
out.inf2h(k) = ( 1 - exp( -2*( hxy2(k) - hxy(k) ) ) )^0.5;
end
corm = zeros(size_glcm_3,1);
corp = zeros(size_glcm_3,1);
for k = 1:size_glcm_3
for i = 1:size_glcm_1
for j = 1:size_glcm_2
s_x(k) = s_x(k) + (((i) - u_x(k))^2)*glcm(i,j,k);
s_y(k) = s_y(k) + (((j) - u_y(k))^2)*glcm(i,j,k);
corp(k) = corp(k) + ((i)*(j)*glcm(i,j,k));
corm(k) = corm(k) + (((i) - u_x(k))*((j) - u_y(k))*glcm(i,j,k));
out.cprom(k) = out.cprom(k) + (((i + j - u_x(k) - u_y(k))^4)*...
glcm(i,j,k));
out.cshad(k) = out.cshad(k) + (((i + j - u_x(k) - u_y(k))^3)*...
glcm(i,j,k));
end
end
s_x(k) = s_x(k) ^ 0.5;
s_y(k) = s_y(k) ^ 0.5;
out.autoc(k) = corp(k);
out.corrp(k) = (corp(k) - u_x(k)*u_y(k))/(s_x(k)*s_y(k));
out.corrm(k) = corm(k) / (s_x(k)*s_y(k));
end
function gaborArray = gaborFilterBank(u,v,m,n)
if (nargin ~= 4) % Check correct number of arguments
error('There must be four input arguments (Number of scales and orientations and the 2-D size of the filter)!')
end
%% Create Gabor filters
% Create u*v gabor filters each being an m by n matrix
gaborArray = cell(u,v);
fmax = 0.25;
gama = sqrt(2);
eta = sqrt(2);
for i = 1:u
fu = fmax/((sqrt(2))^(i-1));
alpha = fu/gama;
beta = fu/eta;
for j = 1:v
tetav = ((j-1)/v)*pi;
gFilter = zeros(m,n);
for x = 1:m
for y = 1:n
xprime = (x-((m+1)/2))*cos(tetav)+(y-((n+1)/2))*sin(tetav);
yprime = -(x-((m+1)/2))*sin(tetav)+(y-((n+1)/2))*cos(tetav);
gFilter(x,y) = (fu^2/(pi*gama*eta))*exp(-((alpha^2)*(xprime^2)+(beta^2)*(yprime^2)))*exp(1i*2*pi*fu*xprime);
end
end
gaborArray{i,j} = gFilter;
end
end
%% Show Gabor filters (Please comment this section if not needed!)
% Show magnitudes of Gabor filters:
figure('NumberTitle','Off','Name','Magnitudes of Gabor filters');
for i = 1:u
for j = 1:v
subplot(u,v,(i-1)*v+j);
imshow(abs(gaborArray{i,j}),[]);
end
end
% Show real parts of Gabor filters:
figure('NumberTitle','Off','Name','Real parts of Gabor filters');
for i = 1:u
for j = 1:v
subplot(u,v,(i-1)*v+j);
imshow(real(gaborArray{i,j}),[]);
end
end
function featureVector = gaborFeatures(img,gaborArray,d1,d2)
if (nargin ~= 4)
error('Please use the correct number of input arguments!')
end
if size(img,3) == 3
warning('The input RGB image is converted to grayscale!')
img = rgb2gray(img);
end
img = double(img);
[u,v] = size(gaborArray);
gaborResult = cell(u,v);
for i = 1:u
for j = 1:v
gaborResult{i,j} = imfilter(img, gaborArray{i,j});
end
end
featureVector = [];
for i = 1:u
for j = 1:v
gaborAbs = abs(gaborResult{i,j});
gaborAbs = downsample(gaborAbs,d1);
gaborAbs = downsample(gaborAbs.',d2);
gaborAbs = gaborAbs(:);
gaborAbs = (gaborAbs-mean(gaborAbs))/std(gaborAbs,1);
featureVector = [featureVector; gaborAbs];
end
end
function getData()
%adds an extraction angle per pixel
offsets = [0 1; -1 1;-1 0;-1 -1;2 2];
jpgImagesDir = fullfile('Dataset/Train', '*.jpg');
total = numel( dir(jpgImagesDir) );
jpg_files = dir(jpgImagesDir);
jpg_counter = 0;
%total=length(filename);
gambar={total};
data_feat={total};
stats={total};
data_label={total};
label=1;
limit=5;
j=1;
for i=1:total
%msgbox(jpg_files(j).name)
s=strcat(num2str(i),'.jpg');
file=fullfile('Dataset/Train',s);
%file=fullfile(pathname,filename{i});
gambar{i}=imread(file);
gambar{i}=imresize(gambar{i},[600 600]);
gambar{i}=rgb2gray(gambar{i});
% gambar{i}=imadjust(gambar{i},stretchlim(gambar{i} ));
% gambar{i}=imsharpen(gambar{i},'Radius',1,'Amount',0.5);
glcm=graycomatrix(gambar{i}, 'Offset', offsets, 'Symmetric', true);
stats{i}=graycoprops(glcm);
iglcm=1;
for x=1:5
data_feat{i,x}=stats{i}.Contrast(iglcm);
iglcm=iglcm+1;
end
iglcm=1;
for x=6:10
data_feat{i,x}=stats{i}.Correlation(iglcm);
iglcm=iglcm+1;
end
iglcm=1;
for x=12:16
data_feat{i,x}=stats{i}.Energy(iglcm);
iglcm=iglcm+1;
end
iglcm=1;
for x=18:22
data_feat{i,x}=stats{i}.Homogeneity(iglcm);
iglcm=iglcm+1;
end
data_feat{i,24}=mean2(gambar{i});
data_feat{i,25}=std2(gambar{i});
data_feat{i,26}=entropy(gambar{i});
data_feat{i,27}= mean2(var(double(gambar{i}))); %average image variance
data_feat{i,28}=kurtosis(double(gambar{i}(:)));
data_feat{i,29}=skewness(double(gambar{i}(:)));
%labeling
if i>limit
label=label+1;
data_label{i}=label;
limit=limit+5;
else
data_label{1,i}=label;
end
end
% data is converted to the appropriate data type so that svm is not confused
data_feat=cell2mat(data_feat);
disp(data_feat);
data_label=cell2mat(data_label);
save('data_1.mat','data_feat','data_label');
% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s=get(handles.edit1,'String');
test=imread(s);
test=imresize(test,[600 600]);
test=rgb2gray(test);
offsets = [0 1; -1 1;-1 0;-1 -1;2 2];
glcm=graycomatrix(test, 'Offset', offsets, 'Symmetric', true);
stats=graycoprops(glcm);
data_glcm=struct2array(stats);
iglcm=1;
glcm_contrast={5};
glcm_correlation={5};
glcm_energy={5};
glcm_homogeneity={5};
for x=1:5
glcm_contrast{x}=data_glcm(iglcm);
iglcm=iglcm+1;
end
for x=1:5
glcm_correlation{x}=data_glcm(iglcm);
iglcm=iglcm+1;
end
for x=1:5
glcm_energy{x}=data_glcm(iglcm);
iglcm=iglcm+1;
end
for x=1:5
glcm_homogeneity{x}=data_glcm(iglcm);
iglcm=iglcm+1;
end
rata2=mean2(test);
std_deviation=std2(test);
glcm_entropy=entropy(test);
rata2_variance= mean2(var(double(test)));
glcm_kurtosis=kurtosis(double(test(:)));
glcm_skewness=skewness(double(test(:)));
buat_train=[glcm_contrast(1:5),glcm_correlation(1:5),glcm_energy(1:5),glcm_homogeneity(1:5),rata2,std_deviation,glcm_entropy,rata2_variance,glcm_kurtosis,glcm_skewness];
test_data=cell2mat(buat_train);
disp('GLCM Feature')
disp('Contrast(1) Correlation(2) Energy(3) Homogeneity(4) Mean(5) Standard_Deviation(6) Entropy(7) RMS(8) Variance(9) smoothness(10) Kurtosis(11) Skewness(12) IDM(13)')
input_Feature=test_data
load('data_1.mat');
%load('Test_data.mat');
%disp('Gabor Feature');
load('Gaborfeature.mat');
%Input_Feat=test_data
result = multisvm(data_feat,data_label,test_data);
%result1 = multisvm(data_feat,data_label,data_feat1);
%[Cmat,Accuracy]= confusion_matrix(result1,data_label,{'Desert','Forest','Mountain','Residential','River'});
%[c_matrixp,Result]= confusion.getMatrix(data_label,result1);
%C = confusionmat(data_label,result1)
%disp(result);
if result == 1
A1 = 'actinic keratosis';
set(handles.edit2,'string',A1);
helpdlg('actinic keratosis');
disp('actinic keratosis');
elseif result == 2
A2 = 'Basel cell carcinoma';
set(handles.edit2,'string',A2);
helpdlg('Basel cell carcinoma');
disp('Basel cell carcinoma');
elseif result == 3
A3 = 'cherry nevus';
set(handles.edit2,'string',A3);
helpdlg('cherry nevus');
disp('cherry nevus');
elseif result == 4
A4 = 'dermatofibroma';
set(handles.edit2,'string',A4);
helpdlg('dermatofibroma');
disp('dermatofibroma');
elseif result == 5
A5 = 'Melanocytic nevus';
set(handles.edit2,'string',A5);
helpdlg('Melanocytic nevus');
disp('Melanocytic nevus');
elseif result == 6
A5 = 'Melanoma';
set(handles.edit2,'string',A5);
helpdlg('Melanoma');
disp('Melanoma');
end
% function [itrfin] = multisvm( T,C,test )
%
%
% itrind=size(test,1);
% itrfin=[];
% Cb=C;
% Tb=T;
% itr=1;
%
% for tempind=1:itrind
% tst=test(tempind,:);
% C=Cb;
% T=Tb;
% u=unique(C);
% N=length(u);
% c4=[];
% c3=[];
% j=1;
% k=1;
% if(N>2)
% itr=1;
% classes=0;
% cond=max(C)-min(C);
% while((classes~=1)&&(itr<=length(u))&& size(C,2)>1 && cond>0)
% %This while loop is the multiclass SVM Trick
% c1=(C==u(itr));
% newClass=c1;
% svmStruct = svmtrain(T,newClass,'kernel_function','rbf'); % I am using rbf kernel function, you must change it also
% classes = svmclassify(svmStruct,tst);
%
% % This is the loop for Reduction of Training Set
% for i=1:size(newClass,2)
% if newClass(1,i)==0;
% c3(k,:)=T(i,:);
% k=k+1;
% end
% end
% T=c3;
% c3=[];
% k=1;
%
% % This is the loop for reduction of group
% for i=1:size(newClass,2)
% if newClass(1,i)==0;
% c4(1,j)=C(1,i);
% j=j+1;
% end
% end
% C=c4;
% c4=[];
% j=1;
%
% cond=max(C)-min(C); % Condition for avoiding group
% %to contain similar type of values
% %and the reduce them to process
%
% % This condition can select the particular value of iteration
% % base on classes
% if classes~=1
% itr=itr+1;
% end
% end
% end
%
% valt=Cb==u(itr); % This logic is used to allow classification
% val=Cb(valt==1); % of multiple rows testing matrix
% val=unique(val);
% itrfin(tempind,:)=val;
% end
% Give more suggestions for improving the program.
function [result] = multisvm(TrainingSet,GroupTrain,TestSet)
u=unique(GroupTrain);
numClasses=length(u);
result = zeros(length(TestSet(:,1)),1);
%build models
for k=1:numClasses
%Vectorized statement that binarizes Group
%where 1 is the current class and 0 is all other classes
G1vAll=(GroupTrain==u(k));
models(k) = svmtrain(TrainingSet,G1vAll);
end
%classify test cases
for j=1:size(TestSet,1)
for k=1:numClasses
if(svmclassify(models(k),TestSet(j,:)))
break;
end
end
result(j) = k;
%[Cmat,Accuracy]= confusion_matrix(TestSet(j,:),models(k),{'A','B','C','D','E','F'});
%disp('Result')
%disp(result(j));
end
function exCode1()
folder = 'Dataset';
dirImage = dir( folder );
numData = size(dirImage,1);
M ={} ;
for i=1:numData
nama = dirImage(i).name;
if regexp(nama, '(D|F)-[0-9]{1,2}.jpg')
B = cell(1,2);
if regexp(nama, 'D-[0-9]{1,2}.jpg')
B{1,1} = double(imread([folder, '/', nama]));
B{1,2} = 1;
elseif regexp(nama, 'F-[0-9]{1,2}.jpg')
B{1,1} = double(imread([folder, '/', nama]));
B{1,2} = -1;
end
M = cat(1,M,B);
end
end
numDataTrain = size(M,1);
class = zeros(numDataTrain,1);
arrayImage = zeros(numDataTrain, 300 * 300);
for i=1:numDataTrain
im = M{i,1} ;
im = rgb2gray(im);
im = imresize(im, [300 300]);
im = reshape(im', 1, 300*300);
arrayImage(i,:) = im;
class(i) = M{i,2};
end
SVMStruct = svmtrain(arrayImage, class);
imTest = double(imread(s));
imTest = rgb2gray(imTest);
imTest = imresize(imTest, [300 300]);
imTest = reshape(imTest',1, 300*300);
result = svmclassify(SVMStruct, imTest);
if(result==1)
msgbox('Desert');
else
msgbox('Forest');
end
function exCode2()
folder = 'Dataset';
dirImage = dir( folder );
numData = size(dirImage,1);
M ={} ;
for i=1:numData
nama = dirImage(i).name;
if regexp(nama, '(M|R)-[0-9]{1,2}.jpg')
B = cell(1,2);
if regexp(nama, 'M-[0-9]{1,2}.jpg')
B{1,1} = double(imread([folder, '/', nama]));
B{1,2} = 1;
elseif regexp(nama, 'R-[0-9]{1,2}.jpg')
B{1,1} = double(imread([folder, '/', nama]));
B{1,2} = -1;
end
M = cat(1,M,B);
end
end
numDataTrain = size(M,1);
class = zeros(numDataTrain,1);
arrayImage = zeros(numDataTrain, 300 * 300);
for i=1:numDataTrain
im = M{i,1} ;
im = rgb2gray(im);
im = imresize(im, [300 300]);
im = reshape(im', 1, 300*300);
arrayImage(i,:) = im;
class(i) = M{i,2};
end
SVMStruct = svmtrain(arrayImage, class);
imTest = double(imread(s));
imTest = rgb2gray(imTest);
imTest = imresize(imTest, [300 300]);
imTest = reshape(imTest',1, 300*300);
result = svmclassify(SVMStruct, imTest);
if(result==1)
msgbox('Mountain');
else
msgbox('Residential');
end
function exCode3()
folder = 'Dataset';
dirImage = dir( folder );
numData = size(dirImage,1);
M ={} ;
for i=1:numData
nama = dirImage(i).name;
if regexp(nama, '(RI|D)-[0-9]{1,2}.jpg')
B = cell(1,2);
if regexp(nama, 'RI-[0-9]{1,2}.jpg')
B{1,1} = double(imread([folder, '/', nama]));
B{1,2} = 1;
elseif regexp(nama, 'D-[0-9]{1,2}.jpg')
B{1,1} = double(imread([folder, '/', nama]));
B{1,2} = -1;
end
M = cat(1,M,B);
end
end
numDataTrain = size(M,1);
class = zeros(numDataTrain,1);
arrayImage = zeros(numDataTrain, 300 * 300);
for i=1:numDataTrain
im = M{i,1} ;
im = rgb2gray(im);
im = imresize(im, [300 300]);
im = reshape(im', 1, 300*300);
arrayImage(i,:) = im;
class(i) = M{i,2};
end
SVMStruct = svmtrain(arrayImage, class);
imTest = double(imread(s));
imTest = rgb2gray(imTest);
imTest = imresize(imTest, [300 300]);
imTest = reshape(imTest',1, 300*300);
result = svmclassify(SVMStruct, imTest);
if(result==1)
msgbox('River');
else
msgbox('Desert');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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 pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (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 pushbutton16.
function pushbutton16_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton16 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
str=get(handles.edit1,'String');
I1 = imread(str);
I4 = imadjust(I1,stretchlim(I1));
I5 = imresize(I4,[300,400]);
figure
imshow(I5);title(' Processed Image ');
set(handles.pushbutton1,'enable','off');
set(handles.pushbutton16,'enable','off');
set(handles.pushbutton12,'enable','on');
% --- Executes on button press in pushbutton17.
function pushbutton17_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton17 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

Image Analyst
Image Analyst el 9 de En. de 2021
What does this show:
% Check that user has the specified Toolbox installed and licensed.
% hasLicenseForToolbox = license('test', 'image_toolbox'); % Check for Image Processing Toolbox.
% hasLicenseForToolbox = license('test', 'Image_Acquisition_Toolbox'); % Check for Image Acquisition Toolbox.
hasLicenseForToolbox = license('test', 'Statistics_Toolbox'); % Check for Statistics and Machine Learning Toolbox.
% hasLicenseForToolbox = license('test', 'Signal_Toolbox'); % Check for Signal Processing Toolbox.
% hasLicenseForToolbox = license('test', 'Video_and_Image_Blockset'); % Check for Computer Vision System Toolbox.
% hasLicenseForToolbox = license('test', 'Neural_Network_Toolbox'); % Check for Deep Learning Toolbox.
if ~hasLicenseForToolbox
% User does not have the toolbox installed, or if it is, there is no available license for it.
% For example, there is a pool of 10 licenses and all 10 have been checked out by other people already.
ver % List what toolboxes the user has licenses available for.
message = sprintf('Sorry, but you do not seem to have the Statistics and Machine Learning Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end

Categorías

Más información sobre Graphics Object Properties en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by