GUI界面是这样的
1、首先是选择dicom文件所在位置,并将其第一个dicom文件显示出来
function dicomOpen_Callback(hObject, eventdata, handles)
% hObject handle to dicomOpen (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global dirOutput; %dicom所在的文件夹
global num; %dicom文件的个数
global index; %读取第index个dicom文件
global pathname; %dicom文件名
pathname = uigetdir(cd,'pick a dicom folder');
if isequal(pathname,0)
return;
end
dirOutput=dir(fullfile(pathname,'*.dcm'));
num=size(dirOutput);
index=1; %默认显示文件夹下的第一副dicom图像
filename=dirOutput(index).name;
fpath=fullfile(pathname,filename);
disp(fpath);
axes(handles.axes1);
set(handles.axes1,'xtick',[]);
set(handles.axes1,'xtick',[]);
imgsrc=dicomread(fpath);
setappdata(handles.axes1,'imgsrc',imgsrc);
imshow(imgsrc,[]);
2、接下来是实现选择显示上/下一张dicom文件
2.1上一张按钮对应的回调函数
% --- Executes on button press in pre.
function pre_Callback(hObject, eventdata, handles)
% hObject handle to pre (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global dirOutput;
global index;
global pathname;
if(index<2)
f=warndlg('已经是第一张图片了哦!','警告');
return;
end
index=index-1;
filename=dirOutput(index).name;
fpath=fullfile(pathname,filename);
disp(fpath);
axes(handles.axes1);
set(handles.axes1,'xtick',[]);
set(handles.axes1,'xtick',[]);
imgsrc=dicomread(fpath);
setappdata(handles.axes1,'imgsrc',imgsrc);
imshow(imgsrc,[]);
2.2下一张按钮对应的回调函数
% --- Executes on button press in next.
function next_Callback(hObject, eventdata, handles)
% hObject handle to next (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global dirOutput;
global num;
global index;
global pathname;
if(index>num-1)
f=warndlg('已经是最后图片了哦!','警告');
return;
end
index=index+1;
filename=dirOutput(index).name;
fpath=fullfile(pathname,filename);
disp(fpath);
axes(handles.axes1);
set(handles.axes1,'xtick',[]);
set(handles.axes1,'xtick',[]);
imgsrc=dicomread(fpath);
setappdata(handles.axes1,'imgsrc',imgsrc);
imshow(imgsrc,[]);