function varargout = dicomCopier_gui(varargin) % DICOMCOPIER_GUI MATLAB code for dicomCopier_gui.fig % DICOMCOPIER_GUI, by itself, creates a new DICOMCOPIER_GUI or raises the existing % singleton*. % % H = DICOMCOPIER_GUI returns the handle to a new DICOMCOPIER_GUI or the handle to % the existing singleton*. % % DICOMCOPIER_GUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in DICOMCOPIER_GUI.M with the given input arguments. % % DICOMCOPIER_GUI('Property','Value',...) creates a new DICOMCOPIER_GUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before dicomCopier_gui_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to dicomCopier_gui_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 dicomCopier_gui % Last Modified by GUIDE v2.5 31-Oct-2013 09:01:18 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @dicomCopier_gui_OpeningFcn, ... 'gui_OutputFcn', @dicomCopier_gui_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 dicomCopier_gui is made visible. function dicomCopier_gui_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 dicomCopier_gui (see VARARGIN) % Choose default command line output for dicomCopier_gui handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes dicomCopier_gui wait for user response (see UIRESUME) % uiwait(handles.figure1); movegui('center') % --- Outputs from this function are returned to the command line. function varargout = dicomCopier_gui_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 button press in loadbutton. function loadbutton_Callback(hObject, eventdata, handles) % hObject handle to loadbutton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % make clean if isfield(handles, 'myinfo'); handles = rmfield(handles, 'myinfo'); end if isfield(handles, 'mydicom'); handles = rmfield(handles, 'mydicom'); end %[handles.dicomlist, handles.dicomdir] = uigetfile('D:\DICOM\*.*','Select the images to load','MultiSelect', 'on'); [handles.dicomlist, handles.dicomdir] = uigetfile('C:\Users\dewarrat\Documents\current projects\Scapula segmentation\raw\Cases 12.2014 n2\*.*','Select the images to load','MultiSelect', 'on'); if ~handles.dicomdir return end handles.N = length(handles.dicomlist); set(handles.slider_slice, 'Max', handles.N) set(handles.slider_slice, 'Value', int32(handles.N/2)) set(handles.slider_slice, 'SliderStep',[1/handles.N 10/handles.N]) set(handles.slider_slice, 'Min', 1) set(handles.info_text, 'ForegroundColor', 'black', 'FontWeight', 'normal') % Read dicom data handles.myinfo(1) = dicominfo(sprintf('%s%s', handles.dicomdir, char(handles.dicomlist(1)))); set(handles.IPP_text, 'String', sprintf('%s (%s%s)', handles.myinfo(1).PatientID, handles.myinfo(1).PatientName.FamilyName(1), handles.myinfo(1).PatientName.GivenName(1))) set(handles.resolution_text, 'String', sprintf('%f mm', handles.myinfo(1).PixelSpacing(1))) set(handles.CTdate_text, 'String', sprintf('%s', handles.myinfo(1).AcquisitionDate)) if isfield(handles.myinfo(1), 'ConvolutionKernel') if strfind(handles.myinfo(1).ConvolutionKernel, 'BONE') set(handles.radiobutton0, 'Value', 0) set(handles.radiobutton1, 'Value', 1) set(handles.radiobutton2, 'Value', 0) elseif strfind(handles.myinfo(1).ConvolutionKernel, 'STANDARD') set(handles.radiobutton0, 'Value', 0) set(handles.radiobutton1, 'Value', 0) set(handles.radiobutton2, 'Value', 1) else set(handles.radiobutton0, 'Value', 1) set(handles.radiobutton1, 'Value', 0) set(handles.radiobutton2, 'Value', 0) end else set(handles.radiobutton0, 'Value', 1) set(handles.radiobutton1, 'Value', 0) set(handles.radiobutton2, 'Value', 0) end % pre-allocate ? % handles.mydicom = zeros(handles.myinfo(1).Height, handles.myinfo(1).Width, handles.N,'int16'); handles.mydicom(:,:,int32(handles.N/2)) = dicomread(sprintf('%s%s', handles.dicomdir, char(handles.dicomlist(int32(handles.N/2))))); handles.slice = int32(handles.N / 2); handles.CTmin = -200; handles.CTmax = 2000; handles.bigmax = 3000; handles.bigmin = -2000; set(handles.slider_contrast, 'Max', handles.bigmax - handles.bigmin - 1) set(handles.slider_contrast, 'Min', 0) set(handles.slider_contrast, 'Value', 900) set(handles.slider_brightness, 'Max', handles.bigmax) set(handles.slider_brightness, 'Min', handles.bigmin) set(handles.slider_brightness, 'Value', 1100) set(handles.slice_num, 'String', handles.slice) imshow(handles.mydicom(:,:,handles.slice), [handles.CTmin handles.CTmax]) guidata(hObject,handles) % --- Executes on slider movement. function slider_slice_Callback(hObject, eventdata, handles) % hObject handle to slider_slice (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider handles.slice = int32(get(hObject,'Value')); set(handles.slice_num, 'String', handles.slice) handles.mydicom(:,:,handles.slice) = dicomread(sprintf('%s%s', handles.dicomdir, char(handles.dicomlist(handles.slice)))); imshow(handles.mydicom(:,:,handles.slice), [handles.CTmin handles.CTmax]) guidata(hObject,handles) % --- Executes during object creation, after setting all properties. function slider_slice_CreateFcn(hObject, eventdata, handles) % hObject handle to slider_slice (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 function patient_num_Callback(hObject, eventdata, handles) % hObject handle to patient_num (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of patient_num as text % str2double(get(hObject,'String')) returns contents of patient_num as a double % --- Executes during object creation, after setting all properties. function patient_num_CreateFcn(hObject, eventdata, handles) % hObject handle to patient_num (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on slider movement. function slider_contrast_Callback(hObject, eventdata, handles) % hObject handle to slider_contrast (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider if ~isfield(handles, 'mydicom'); return end handles.CTmax = (get(handles.slider_brightness,'Max') + get(handles.slider_brightness,'Min') - get(handles.slider_brightness,'Value')) + (get(hObject,'Max') - get(hObject,'Value'))/2; handles.CTmin = (get(handles.slider_brightness,'Max') + get(handles.slider_brightness,'Min') - get(handles.slider_brightness,'Value')) - (get(hObject,'Max') - get(hObject,'Value'))/2; if handles.CTmax > handles.bigmax handles.CTmax = handles.bigmax; end if handles.CTmin < handles.bigmin handles.CTmin = handles.bigmin; end imshow(handles.mydicom(:,:,handles.slice), [handles.CTmin handles.CTmax]) guidata(hObject,handles) % --- Executes during object creation, after setting all properties. function slider_contrast_CreateFcn(hObject, eventdata, handles) % hObject handle to slider_contrast (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 % --- Executes on slider movement. function slider_brightness_Callback(hObject, eventdata, handles) % hObject handle to slider_brightness (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider if ~isfield(handles, 'mydicom'); return end handles.CTmax = (get(hObject,'Max') + get(hObject,'Min') - get(hObject,'Value')) + (get(handles.slider_contrast,'Max') - get(handles.slider_contrast,'Value'))/2; handles.CTmin = (get(hObject,'Max') + get(hObject,'Min') - get(hObject,'Value')) - (get(handles.slider_contrast,'Max') - get(handles.slider_contrast,'Value'))/2; if handles.CTmax > handles.bigmax handles.CTmax = handles.bigmax; end if handles.CTmin < handles.bigmin handles.CTmin = handles.bigmin; end imshow(handles.mydicom(:,:,handles.slice), [handles.CTmin handles.CTmax]) guidata(hObject,handles) % --- Executes during object creation, after setting all properties. function slider_brightness_CreateFcn(hObject, eventdata, handles) % hObject handle to slider_brightness (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 % --- Executes on button press in copy_button. function copy_button_Callback(hObject, eventdata, handles) % hObject handle to copy_button (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) sortPictures = 1; if isempty(get(handles.patient_num,'String')) set(handles.info_text, 'ForegroundColor', 'red', 'FontWeight', 'bold', 'String', 'Please give a patient number') return else patient = get(handles.patient_num,'String'); end if isempty(get(handles.output_dir,'String')) outputdir = uigetdir; if outputdir set(handles.output_dir,'String', outputdir) end else outputdir = get(handles.output_dir,'String'); end if ~outputdir set(handles.info_text, 'ForegroundColor', 'red', 'FontWeight', 'bold', 'String', 'Please select an output directoy') return end set(handles.info_text, 'ForegroundColor', 'black', 'FontWeight', 'normal') % Create name string newname = [patient, '-', handles.myinfo(1).PatientID, '_', handles.myinfo(1).PatientName.FamilyName(1), handles.myinfo(1).PatientName.GivenName(1)]; if get(handles.radiobutton1,'Value') newname = [newname, '-bone.']; elseif get(handles.radiobutton2,'Value') newname = [newname, '-soft.']; else newname = [newname, '.']; end % Create output directory outputdir = [outputdir, '\', patient, '-', handles.myinfo(1).PatientID, '\', 'CT-', patient, '-', handles.myinfo(1).PatientID, '-xxx\dicom\']; mkdir(outputdir) % Sort pictures in correct order if sortPictures == 1 for h = 1:handles.N infoTemp = dicominfo(sprintf('%s%s', handles.dicomdir, char(handles.dicomlist(h)))); SliceLoc(h,1) = h; SliceLoc(h,2) = infoTemp.SliceLocation; end SliceSorted = sortrows(SliceLoc,2); end % Read all data for i = 1:handles.N str = sprintf('Copying dicom...\n%d / %d\n', i, handles.N); set(handles.info_text, 'String', str) drawnow % Anonymous if sortPictures == 1 caseID = SliceSorted(i,1); else caseID = i; end handles.myinfo(i) = dicominfo(sprintf('%s%s', handles.dicomdir, char(handles.dicomlist(caseID)))); if get(handles.radiobutton1,'Value') handles.myinfo(i).PatientName.GivenName = [handles.myinfo(i).PatientName.FamilyName(1), handles.myinfo(i).PatientName.GivenName(1), '_bone']; elseif get(handles.radiobutton2,'Value') handles.myinfo(i).PatientName.GivenName = [handles.myinfo(i).PatientName.FamilyName(1), handles.myinfo(i).PatientName.GivenName(1), '_soft']; else handles.myinfo(i).PatientName.GivenName = [handles.myinfo(i).PatientName.FamilyName(1), handles.myinfo(i).PatientName.GivenName(1)]; end handles.myinfo(i).PatientName.FamilyName = [patient, '_', handles.myinfo(1).PatientID]; % Read and copy dicomwrite(dicomread(sprintf('%s%s', handles.dicomdir, char(handles.dicomlist(caseID)))),[outputdir, newname, sprintf('%04d',i), '.dcm'], handles.myinfo(i)); end set(handles.info_text, 'String', 'Copied') function output_dir_Callback(hObject, eventdata, handles) % hObject handle to output_dir (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of output_dir as text % str2double(get(hObject,'String')) returns contents of output_dir as a double % --- Executes during object creation, after setting all properties. function output_dir_CreateFcn(hObject, eventdata, handles) % hObject handle to output_dir (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of radiobutton1 if get(hObject,'Value') set(handles.radiobutton0,'Value',0) set(handles.radiobutton2,'Value',0) else set(hObject,'Value',1) end % --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of radiobutton2 if get(hObject,'Value') set(handles.radiobutton0,'Value',0) set(handles.radiobutton1,'Value',0) else set(hObject,'Value',1) end % --- Executes on button press in radiobutton0. function radiobutton0_Callback(hObject, eventdata, handles) % hObject handle to radiobutton0 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of radiobutton0 if get(hObject,'Value') set(handles.radiobutton1,'Value',0) set(handles.radiobutton2,'Value',0) else set(hObject,'Value',1) end