MATLAB: Fly Brain Image Processing GUI

gui

Hello.
I am trying to make GUI that processes an images in slides.
But I am having trouble with the radio buttons. You're supposed to be able to choose one when the GUI is first initiallized and then depending on which radio button is chosen the image will show in rgb or grayscale. The trouble happens when I run the GUI and try to choose gray scale it immidiatle deactavates the buttons so that I can't choose either. When RGB is selected the program runs fine and then it won't let me re run it to select another radio button. Any help with this would be greatly appreciated.
function varargout = gui_flybrain(varargin)
% GUI_FLYBRAIN MATLAB code for gui_flybrain.fig
% GUI_FLYBRAIN, by itself, creates a new GUI_FLYBRAIN or raises the existing
% singleton*.
%
% H = GUI_FLYBRAIN returns the handle to a new GUI_FLYBRAIN or the handle to
% the existing singleton*.
%
% GUI_FLYBRAIN('CALLBACK',hObject,eventData,handles,…) calls the local
% function named CALLBACK in GUI_FLYBRAIN.M with the given input arguments.
%
% GUI_FLYBRAIN('Property','Value',…) creates a new GUI_FLYBRAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui_flybrain_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui_flybrain_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_flybrain
% Last Modified by GUIDE v2.5 06-Nov-2020 17:44:59
% Begin initialization code – DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename,
'gui_Singleton', gui_Singleton,
'gui_OpeningFcn', @gui_flybrain_OpeningFcn,
'gui_OutputFcn', @gui_flybrain_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_flybrain is made visible.
function gui_flybrain_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_flybrain (see VARARGIN)
% Choose default command line output for gui_flybrain
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% file=uigetfile('*.tif');
%UIWAIT makes gui_flybrain wait for user response (see UIRESUME)
%uiwait(handles.figure1);
% — Outputs from this function are returned to the command line.
function varargout = gui_flybrain_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 rgb_radiobutton.
function rgb_radiobutton_Callback(hObject, eventdata, handles)
% hObject handle to rgb_radiobutton (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: state=get(hObject,'Value'); %returns toggle state of rgb_radiobutton
set(handles.rgb_radiobutton, 'Value', 0);
% — Executes on button press in grayscale_radiobutton.
function grayscale_radiobutton_Callback(hObject, eventdata, handles)
% hObject handle to grayscale_radiobutton (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 grayscale_radiobutton
set(handles.grayscale_radiobutton, 'Value', 0);
% — Executes on button press in Showimages_pushbutton.
function Showimages_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to Showimages_pushbutton (see GCBO)
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
file=uigetfile('*.tif');
info=imfinfo(file);
slides_num=numel(info);
status=0;
status_RGB = get(handles.rgb_radiobutton, 'Value');
status_GRAY= get(handles.grayscale_radiobutton, 'Value');
% set(handles.rgb_radiobutton, 'Enable','off');
% set(handles.grayscale_radiobutton, 'Enable','off');
for i=1:slides_num;
slide=imread(file,i);
switch status
case status_RGB==1
set(handles.grayscale_radiobutton, 'Enable','off');
axes(handles.axes1);
imshow(slide);
i
pause(0.05);
case status_GRAY == 1
set(handles.rgb_radiobutton, 'Enable','off');
G=rgb2gray(slide);
axes(handles.axes1);
imshow(slide);
i
pause(0.05);
end
set(handles.slidenum,'String',i);
end
set(handles.rgb_radiobutton, 'Enable','on');
set(handles.grayscale_radiobutton, 'Enable','on');
function slidenum_Callback(hObject, eventdata, handles)
% hObject handle to slidenum (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 slidenum as text
% str2double(get(hObject,'String')) returns contents of slidenum as a double
% — Executes during object creation, after setting all properties.
function slidenum_CreateFcn(hObject, eventdata, handles)
% hObject handle to slidenum (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 when selected object is changed in uibuttongroup1.
function uibuttongroup1_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in uibuttongroup1
% eventdata reserved – to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% get(eventdata.NewValue,'uibuttongroup1');

Best Answer

Rachel:
You turn the buttons off when you click them. Do not put any code in the callback for either radio button. rgb_radiobutton_Callback and grayscale_radiobutton_Callback should not have any code in them. Or if they do, it's just to apply a colormap to the image, but not to "set()" the value of the radio button to 0. In your Showimages_pushbutton_Callback() you can check the value of the radio button and also set the colormap there. But do NOT set the value of your radio button in Showimages_pushbutton_Callback(). If you still have trouble, attach both the m-file and the .fig file.
Related Question