def convert_ima(input_dir, output_dir): import dicom2nifti import dicom2nifti.settings as settings settings.disable_validate_orthogonal() settings.enable_resampling() settings.set_resample_spline_interpolation_order(1) settings.set_resample_padding(-1000) dicom2nifti.convert_directory(input_dir, output_dir)
def test_convert_directory(self): tmp_output_dir = tempfile.mkdtemp() try: settings.enable_resampling() settings.set_resample_spline_interpolation_order(1) settings.set_resample_padding(-1000) settings.disable_validate_slice_increment() settings.disable_validate_orthogonal() convert_directory.convert_directory("/Users/abrys/Downloads/dicom_CT_UNKNOWN_3", "/Users/abrys/Downloads") finally: shutil.rmtree(tmp_output_dir)
def test_convert_directory(self): tmp_output_dir = tempfile.mkdtemp() try: settings.enable_resampling() settings.set_resample_spline_interpolation_order(1) settings.set_resample_padding(-1000) settings.disable_validate_slice_increment() settings.disable_validate_orthogonal() convert_directory.convert_directory("/Users/abrys/Downloads/test", "/Users/abrys/Downloads") finally: shutil.rmtree(tmp_output_dir)
def generate_inconsistent_slice_incement(): settings.disable_validate_orthogonal() settings.disable_validate_slice_increment() settings.enable_resampling() settings.set_resample_padding(0) settings.set_resample_spline_interpolation_order(1) dicom_directory = os.path.join( os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'tests', 'data', 'failing', 'sliceincrement', '002') output_file = dicom_directory + '_ground_truth.nii.gz' reoriented_file = dicom_directory + '_ground_truth_reoriented.nii.gz' generate_ground_truth(dicom_directory, output_file, reoriented_file) settings.disable_resampling() settings.enable_validate_slice_increment() settings.enable_validate_orientation()
def test_inconsistent_slice_increment_resampling(self): tmp_output_dir = tempfile.mkdtemp() try: settings.disable_validate_orthogonal() settings.disable_validate_slice_increment() settings.enable_resampling() settings.set_resample_padding(0) settings.set_resample_spline_interpolation_order(1) results = convert_generic.dicom_to_nifti(read_dicom_directory(test_data.FAILING_SLICEINCREMENT_2), os.path.join(tmp_output_dir, 'test.nii.gz')) assert_compare_nifti(results['NII_FILE'], ground_thruth_filenames(test_data.FAILING_SLICEINCREMENT_2)[0]) self.assertTrue(isinstance(results['NII'], nibabel.nifti1.Nifti1Image)) finally: settings.disable_resampling() settings.enable_validate_slice_increment() settings.enable_validate_orientation() shutil.rmtree(tmp_output_dir)
def generate_inconsistent_slice_incement(): settings.disable_validate_orthogonal() settings.disable_validate_slice_increment() settings.enable_resampling() settings.set_resample_padding(0) settings.set_resample_spline_interpolation_order(1) dicom_directory = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'tests', 'data', 'failing', 'sliceincrement', '002') output_file = dicom_directory + '_ground_truth.nii.gz' reoriented_file = dicom_directory + '_ground_truth_reoriented.nii.gz' generate_ground_truth(dicom_directory, output_file, reoriented_file) settings.disable_resampling() settings.enable_validate_slice_increment() settings.enable_validate_orientation()
def test_inconsistent_slice_increment_resampling(self): tmp_output_dir = tempfile.mkdtemp() try: settings.disable_validate_orthogonal() settings.disable_validate_slice_increment() settings.enable_resampling() settings.set_resample_padding(0) settings.set_resample_spline_interpolation_order(1) results = convert_generic.dicom_to_nifti( read_dicom_directory(test_data.FAILING_SLICEINCREMENT_2), os.path.join(tmp_output_dir, 'test.nii.gz')) assert_compare_nifti( results['NII_FILE'], ground_thruth_filenames(test_data.FAILING_SLICEINCREMENT_2)[0]) self.assertTrue( isinstance(results['NII'], nibabel.nifti1.Nifti1Image)) finally: settings.disable_resampling() settings.enable_validate_slice_increment() settings.enable_validate_orientation() shutil.rmtree(tmp_output_dir)
def setUp(self): settings.disable_validate_orthogonal() settings.enable_resampling() settings.set_resample_padding(-1000) settings.set_resample_spline_interpolation_order(1)
# Import necessary dcm2niix python wrapper import dicom2nifti import dicom2nifti.settings as settings # Set settings for conversion settings.enable_resampling() settings.set_resample_spline_interpolation_order(1) settings.set_resample_padding(-3024) dicom2nifti.settings.disable_validate_orthogonal() # Get directory of .dcm folder import os import shutil dirs = os.listdir("D:\MDRP/train/") # I'm going to output the file to a temporary folder because I can't rename the file # The script names the file as the modality instead of original folder name and I can't find how to change it in the python wrapper temp_folder = 'D:\MDRP/preprocessing/temp/' # This is the main output folder where we want our correctly named files output_folder = 'D:\MDRP/preprocessing/nifti_output/' for file in dirs: try: original_file = file # First we list the directories dicom_directory = 'D:\MDRP/train/' + (original_file) # Converting a file in the dcm directory to the temp folder