help image processing code

1 view (last 30 days)
Hi all
I want to display multiple images using GUI. I have 135 image. i want load 135 images in axes, then when i slide, it will show the image from 1 to 135. This is my code that i know to read 135 image:
P = zeros(256, 256, 135);
for K = 1 : 135
petname = sprintf('PET_I1001_PT%03d.dcm', K);
P(:,:,K) = dicomread(petname);
end
how to me write the command for 'load image button' and 'slider' in m file ??
hope anyone can help me

Accepted Answer

Image Analyst
Image Analyst on 21 Jan 2018
Set up your scroll bar to have 135 as the max and 1 as the min. Then in the scrollbar callback function:
scrollBarValue = round(handles.scrollbar1.Value);
petName = sprintf('PET_I1001_PT%03d.dcm', scrollBarValue);
fullFileName = fullfile(folder, petName);
thisImage = dicomread(fullFileName);
imshow(thisImage);
No loop is needed.
  4 Comments
mohd akmal masud
mohd akmal masud on 27 Feb 2018
this is my code, but still not work
function varargout = gui123(varargin)
% GUI123 MATLAB code for gui123.fig
% GUI123, by itself, creates a new GUI123 or raises the existing
% singleton*.
%
% H = GUI123 returns the handle to a new GUI123 or the handle to
% the existing singleton*.
%
% GUI123('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI123.M with the given input arguments.
%
% GUI123('Property','Value',...) creates a new GUI123 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui123_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui123_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 gui123
% Last Modified by GUIDE v2.5 28-Feb-2018 00:33:09
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui123_OpeningFcn, ...
'gui_OutputFcn', @gui123_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 gui123 is made visible.
function gui123_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 gui123 (see VARARGIN)
% Choose default command line output for gui123
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui123 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui123_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 slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
scrollBarValue = round(handles.scrollbar1.Value);
petName = sprintf('PET_I1001_PT%03d.dcm', scrollBarValue);
fullFileName = fullfile('D:\Images PET and CT\CT', petName);
thisImage = dicomread(fullFileName);
imshow(thisImage);
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
if true
% code
end
mohd akmal masud
mohd akmal masud on 27 Feb 2018
is it true like this? but the GUI appear as picture attach
function varargout = gui123(varargin)
% GUI123 MATLAB code for gui123.fig
% GUI123, by itself, creates a new GUI123 or raises the existing
% singleton*.
%
% H = GUI123 returns the handle to a new GUI123 or the handle to
% the existing singleton*.
%
% GUI123('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI123.M with the given input arguments.
%
% GUI123('Property','Value',...) creates a new GUI123 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before gui123_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to gui123_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 gui123
% Last Modified by GUIDE v2.5 28-Feb-2018 00:52:21
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui123_OpeningFcn, ...
'gui_OutputFcn', @gui123_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 gui123 is made visible.
function gui123_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 gui123 (see VARARGIN)
% Choose default command line output for gui123
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes gui123 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = gui123_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 slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
scrollBarValue = round(handles.scrollbar1.Value);
petName = sprintf('PET_I1001_PT%03d.dcm', scrollBarValue);
fullFileName = fullfile('D:\Images PET and CT\CT', petName);
thisImage = dicomread(fullFileName);
imshow(thisImage);
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!