Displaying images with GUI in matlab
3 次查看(过去 30 天)
显示 更早的评论
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
2012-1-16
Please format your code as explained in the "Markup help" link on this page. What is your question?
采纳的回答
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168165/image.jpeg)
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 个评论
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
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/168131/image.jpeg)
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);
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!