MATLAB: Displaying images with GUI in matlab

dicomread

I have a code working for displaying dicom images..
i want to display these in GUI, with help of pushbutton
please help me..
thanks in advance!!
the code is
files = dir(fullfile('C:','Program Files','MATLAB','images\*.dcm'));
for i = 1 : numel(files)
[X, map] = dicomread(fullfile('C:','Program Files','MATLAB','images',files(i).name));
if ~isempty(map)
subplot(2,2,i);
subimage(X,map);
else
subplot(2,2,i);
imshow(X, map);
end
end

Best Answer

Hi,
You asked me 'what about for huge number of images in a folder??'
I think of course we cannot create so many axes in this figure,
so I decided to display them in single axes.
Just use button 'back' and 'next' to display your next or previous image.
Here the code :
function varargout = untitled(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_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 untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.files = dir(fullfile('C:','Program Files','MATLAB','images\*.dcm'));
for i = 1 : length(handles.files)
handles.X{i} = dicomread(fullfile('C:','Program Files','MATLAB','images',handles.files(i).name));
end
imshow(handles.X{1},[]);
handles.index = 1;
Cek(hObject, eventdata, handles);
guidata(hObject, handles);
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function pushbutton1_Callback(hObject, eventdata, handles)
handles.output = hObject;
handles.index = handles.index - 1;
Cek(hObject, eventdata, handles);
imshow(handles.X{handles.index},[]);
guidata(hObject, handles);
function pushbutton2_Callback(hObject, eventdata, handles)
handles.output = hObject;
handles.index = handles.index + 1;
Cek(hObject, eventdata, handles);
imshow(handles.X{handles.index},[]);
guidata(hObject, handles);
function Cek(hObject, eventdata, handles)
handles.output = hObject;
n = length(handles.files);
if handles.index > 1, set(handles.pushbutton1,'enable','on');
else set(handles.pushbutton1,'enable','off'); end
if handles.index < n, set(handles.pushbutton2,'enable','on');
else set(handles.pushbutton2,'enable','off'); end
guidata(hObject, handles);
Please design the correct GUI as shown in the picture.
the tag for axes is axes1, tag for 'back' button is pushbutton1, tag for 'next' button is pushbutton2.
If you design it correctly, I believe no error will occurs.
Related Question