Home > vbmeg > functions > tool_box > load_NIFTI > convert_dicom > convert_dicom_nifti.m

convert_dicom_nifti

PURPOSE ^

Convert DICOM to NIFTI file for VBMEG.

SYNOPSIS ^

function [RASout] = convert_dicom_nifti(dicom_file,output_dir)

DESCRIPTION ^

 Convert DICOM to NIFTI file for VBMEG.
 --- Usage 1
  convert_dicom_nifti;
   GUI mode. select one of DICOM file.
   NIfTI file will be created in the DICOM directory.
 --- Usage 2
  RASout = convert_dicom_nifti(dicom_file, output_dir)
  [Input]
      dicom_file : set one of dicom files.
      output_dir : output directory for NIfTI file.
  [Output]
    RASout : created NIfTI file path.

 [Note]
   NIfTI file is :  data order : RAS
                        origin : ceter of the image.
 [History]
  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)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [RASout] = convert_dicom_nifti(dicom_file,output_dir)
0002 % Convert DICOM to NIFTI file for VBMEG.
0003 % --- Usage 1
0004 %  convert_dicom_nifti;
0005 %   GUI mode. select one of DICOM file.
0006 %   NIfTI file will be created in the DICOM directory.
0007 % --- Usage 2
0008 %  RASout = convert_dicom_nifti(dicom_file, output_dir)
0009 %  [Input]
0010 %      dicom_file : set one of dicom files.
0011 %      output_dir : output directory for NIfTI file.
0012 %  [Output]
0013 %    RASout : created NIfTI file path.
0014 %
0015 % [Note]
0016 %   NIfTI file is :  data order : RAS
0017 %                        origin : ceter of the image.
0018 % [History]
0019 %  Masa-aki Sato 2010-01-10
0020 %       rhayashi 2010-05-13 supported not reorienting case
0021 %
0022 % Copyright (C) 2011, ATR All Rights Reserved.
0023 % License : New BSD License(see VBMEG_LICENSE.txt)
0024 
0025 RASout  = []; % RASname with path
0026 
0027 % path for 'dcm2niix' program
0028 prog_path = [];
0029 
0030 % select DICOM directory
0031 if ~exist('dicom_file','var'), 
0032     [this] = file_dialog;
0033     this.dialog_title = 'Select one of DICOM files';
0034     [dicom_dir, dicom_file] = visible(this);
0035     if length(dicom_file) == 0, return; end
0036     dicom_file = [dicom_dir filesep dicom_file{1}];
0037 else
0038     [dicom_dir, fname, fext] = vb_get_file_parts(dicom_file);
0039 end
0040 
0041 if ~exist('output_dir','var') || isempty(output_dir)
0042     output_dir = dicom_dir; 
0043 end
0044 h = msgbox('Now converting...');
0045 
0046 disp('============================================');
0047 disp('DICOM to RAS NIfTI file(.nii)');
0048 disp('Start converting...');
0049 
0050 % --- Convert DICOM to NIFTI file by 'dcm2niix'
0051 [status, nifti_filename] = convert_dicom_nifti_cmd(dicom_file, output_dir, prog_path);
0052 nifti_file = fullfile(output_dir, nifti_filename);
0053 
0054 % Convert original NIfTI to RAS NIfti(origin: ceter of the image)
0055 RASout = fullfile(output_dir, filesep, ['RAS_' nifti_filename]);
0056 convert_nifti_to_ras(nifti_file, RASout);
0057 fprintf('Saved RAS NIfTI file: %s\n', RASout);
0058 
0059 delete(nifti_file);
0060 
0061 disp('Finished converting.');
0062 disp('============================================');
0063 
0064 if ishandle(h)
0065     delete(h);
0066 end
0067 
0068 return
0069

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005