Convert DICOM to RAS-NIFTI and LAS-Analyze file by using dcm2nii Note: DICOM directory should include only DICOM files --- Usage 1 convert_dicom_nifti; : Select DICOM file by GUI --- Usage 2 [RASname,LASname,ORGname] = convert_dicom_nifti(dicom_file,output_dir) RASname : RASname with path LASname : LASname with path ORGname : Original name with path (Not reorienting case, This value will be returned) Masa-aki Sato 2010-01-10 rhayashi 2010-05-13 supported not reorienting case Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [RASname,LASname,ORGname] = ... 0002 convert_dicom_nifti(dicom_file,output_dir) 0003 % Convert DICOM to RAS-NIFTI and LAS-Analyze file by using dcm2nii 0004 % Note: DICOM directory should include only DICOM files 0005 % --- Usage 1 0006 % convert_dicom_nifti; 0007 % : Select DICOM file by GUI 0008 % --- Usage 2 0009 % [RASname,LASname,ORGname] = convert_dicom_nifti(dicom_file,output_dir) 0010 % RASname : RASname with path 0011 % LASname : LASname with path 0012 % ORGname : Original name with path 0013 % (Not reorienting case, This value will be returned) 0014 % Masa-aki Sato 2010-01-10 0015 % rhayashi 2010-05-13 supported not reorienting case 0016 % 0017 % Copyright (C) 2011, ATR All Rights Reserved. 0018 % License : New BSD License(see VBMEG_LICENSE.txt) 0019 0020 RASname = []; % RASname with path 0021 LASname = []; % LASname with path 0022 ORGname = []; % Original name 0023 % (Not reorienting case, This value will be return) 0024 0025 % path for 'dcm2nii' program 0026 prog_path = []; 0027 0028 % select DICOM directory 0029 if ~exist('dicom_file','var'), 0030 [this] = file_dialog; 0031 this.dialog_title = 'Select one of DICOM files'; 0032 [dicom_dir, dicom_file] = visible(this); 0033 if length(dicom_file) == 0, return; end 0034 dicom_file = [dicom_dir filesep dicom_file{1}]; 0035 else 0036 [dicom_dir, fname, fext] = fileparts(dicom_file); 0037 end 0038 0039 if ~exist('output_dir','var') || isempty(output_dir) 0040 output_dir = dicom_dir; 0041 end; 0042 disp('============================================'); 0043 disp('DICOM to LAS Analyze and RAS NIfTI'); 0044 disp('Start converting...'); 0045 0046 % --- Convert DICOM to NIFTI file by 'dcm2nii' 0047 convert_dicom_nifti_cmd(dicom_file, output_dir, prog_path); 0048 0049 % --- Output files by 'dcm2nii': Three set of NIFTI files are saved 0050 % fname.hdr/img : original image 0051 % o+fname.hdr/img : reoriented image with RAS orientation 0052 % co+fname.hdr/img : reoriented & cropped image with RAS orientation 0053 0054 % dcm2nii logfile name 0055 logname = [output_dir, '/dcm2nii.log']; 0056 0057 % Select RAS NIFTI file and delete other orientation files 0058 [RASname,fname] = select_nii_ras_fname(logname, output_dir); 0059 if isempty(RASname) 0060 ORGname = [output_dir, filesep, fname]; 0061 fprintf('Saved ORG NIFTI file: %s\n', ORGname); 0062 fprintf('RAS/LAS file did not create.\n'); 0063 else 0064 LASname = [output_dir filesep, 'LAS_' fname]; 0065 0066 % Convert RAS-NIFTI to LAS-Analyze file 0067 convert_nifti_to_las(RASname,LASname); 0068 0069 fprintf('Saved RAS NIFTI file: %s\n',RASname) 0070 fprintf('Saved LAS Analyze file: %s\n',LASname) 0071 end 0072 0073 disp('Finished converting.'); 0074 disp('============================================'); 0075 0076 return 0077 0078 % check .hdr file exist 0079 %fname = vb_get_ext_fname(dicom_dir,'.hdr'); 0080 % 0081 %if ~isempty(fname), 0082 % error('There are Analyze file in the directory'); 0083 %end 0084 0085 %if ~exist('dicom_file','var') || isempty(dicom_file) 0086 % dicom_file = vb_get_ext_fname(dicom_dir); 0087 %else 0088 % dcm_file = [dicom_dir filesep dicom_file{1}]; 0089 %end