MATLAB Answers

0

hey ,I make GUI Application in matlab for brain tumor segmentation and I have this problem

Asked by Mohamed Nasr on 6 Jul 2019
Latest activity Edited by Geoff Hayes
on 8 Jul 2019
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 06-Jul-2019 01:31:00
% 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.
function load_Callback(hObject, eventdata, handles)
% hObject handle to load (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
msbox(sprintf('Invalide selection'),'Error','Error');
return
end
im=imread(path); %read the path of the image
im=im2double(im); %convert to double
im2=im; %Backup of image
axes(handles.axes1);
imshow(im)
title('\fontsize{18}\color[rgb]{0.635 0.078 0.184}Patient''s Brain')
% --- Executes on button press in detect.
function detect_Callback(hObject, eventdata, handles)
% hObject handle to detect (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(handles.axes2);
bw=imbinarize(img,0.7); %Thresholding value if less than 0.7 color is black ,if morr than 0.7 color is white
label = bwlabel(logical(bw)); %area of tumor
stats = regionprops(label , 'Solidity', 'Area'); % properties of healthy region
denisty = [stats.Solidity];
area = [stats.Area];
high_dense_area = denisty > 0.5 ; %Area of tumor
max_area = max(area(high_dense_area)); %max area
tumor_label = find(area == max_area); %place of tumor
tumor = ismember(label, tumor_label);
se = strel('square',5);
tumor = imdilate(tumor,se);
B= bwboundaries(tumor,'noholes');
imshow(im);
hold on
for i=1:length(B)
plot(B{i}(:,2), B{i}(:,1),'y','linewidth',1.45)
end
title('\fontsize{18}\color[rgb]{0.635 0.078 0.184}Detect Brain')
hold off
% --------------------------------------------------------------------
function about_Callback(hObject, eventdata, handles)
% hObject handle to about (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function author_Callback(hObject, eventdata, handles)
% hObject handle to author (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
msgbox(sprintf('Name:Aml omar\nEmail:amlomar782@gmail.com\nID1100602'),'Author','Help')
and problem is
Error in GUi (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUi('detect_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.

  0 Comments

Sign in to comment.

1 Answer

Answer by Geoff Hayes
on 8 Jul 2019
Edited by Geoff Hayes
on 8 Jul 2019

Mohamed - you haven't copied and pasted the full error message, but looking at the code to your callback
function detect_Callback(hObject, eventdata, handles)
% hObject handle to detect (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(handles.axes2);
bw=imbinarize(img,0.7); %Threshol
there is a global variable named im but you are passing img into the imbinarize function. I suspect that you mean to do
bw=imbinarize(im,0.7); %Threshol
instead.
Please note that using the handles structure to store user data is an alternative to using global variables.

  0 Comments

Sign in to comment.