Displaying images with GUI in matlab

조회 수: 7 (최근 30일)
REHANA M.B
REHANA M.B 2012년 1월 16일
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
  댓글 수: 2
Jan
Jan 2012년 1월 16일
Please format your code as explained in the "Markup help" link on this page. What is your question?
REHANA M.B
REHANA M.B 2012년 1월 17일
The code is as follows....
files = dir(fullfile('C:','Program Files','MATLAB','images\*.dcm'));
for i = 1 : numel(files)
[X, map] = dicomread(fullfile('C:','ProgramFiles','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

댓글을 달려면 로그인하십시오.

채택된 답변

Chandra Kurniawan
Chandra Kurniawan 2012년 1월 17일
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.
  댓글 수: 27
REHANA M.B
REHANA M.B 2012년 1월 18일
Hi.... we can display 'n' number of images .. no need to take AXES.
we can take additional 'figure' means frame in GUI and give the path name to display on that....
Think on this..and let me know
Mirco
Mirco 2012년 1월 23일
Hi,
I have a problem similar to REHANA M.B, so I tried your Code...like REHANA the only thing I changed is that I used imread instead of dicomread, because I wanted to display jpg-images.
As a matter of fact, when starting the GUI no image was displayed and when trying the next Button or the previous Button I got the message :
"??? Reference to non-existent field 'index'.
Error in ==> disp_image>next_Callback at 36
handles.index = handles.index + 1;
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> disp_image at 11
else gui_mainfcn(gui_State, varargin{:}); end
Error in ==>
@(hObject,eventdata)disp_image('next_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback"
do you maybe have any suggestions what mistake i might have made? in case it matters, i used Matlab 7.10.0...thank you in advance :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chandra Kurniawan
Chandra Kurniawan 2012년 1월 16일
Hi,
If you want to display it on the GUI, first you have to design the GUI.
Make a GUI with four axes, as shown in the image below :
Then add a pushbutton and write the callback
function pushbutton1_Callback(hObject, eventdata, handles)
handles.output = hObject;
files = dir(fullfile('C:','Program Files','MATLAB','images\*.dcm'));
hlist = {handles.axes1, handles.axes2, handles.axes3, handles.axes4};
for i = 1 : 4
X = dicomread(fullfile('C:','Program Files','MATLAB','images',files(i).name));
axes(hlist{i});
imshow(X, []);
end
guidata(hObject, handles);
  댓글 수: 2
REHANA M.B
REHANA M.B 2012년 1월 17일
Thank you..
but for every image we have to use axes? then what about for huge number of images in a folder??
can we display n number of images on a single axes??
REHANA M.B
REHANA M.B 2012년 1월 17일
it is giving the error
??? Reference to non-existent field 'axes3'.
Error in ==> gui_new>pushbutton1_Callback at 83
hlist = {handles.axes1, handles.axes2, handles.axes3, handles.axes4};
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> gui_new at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> @(hObject,eventdata)gui_new('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by