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 convertDicom2Nifti( inputFiles,outputDirectory ): mapOfFileNames = {} settings.disable_validate_orientation() settings.disable_validate_orthogonal() settings.disable_validate_slice_increment()
import asyncio from pydicom import dcmread from pydicom.tag import Tag import dicom2nifti import os import pathlib from pydcmq import * import dicom2nifti.settings as settings settings.disable_validate_orthogonal() settings.disable_validate_slice_increment() settings.enable_resampling() settings.set_resample_spline_interpolation_order(1) settings.set_resample_padding(-1024) async def dcmhandler(channel, ds, uri, routing_key): print(f"dcm2niix: converting {uri} ({ds.SeriesDescription})") outdir = f"{os.environ['HOME']}/.dcmq/nii/{ds.StudyInstanceUID}" pathlib.Path(outdir).mkdir(parents=True, exist_ok=True) count = 0 with os.scandir(uri) as it: for series in it: if series.is_dir(): with os.scandir(series) as it2: for instance in it2: if instance.is_file(): dcmfilename = instance.name break refds = dcmread(os.path.join(uri, series.name, dcmfilename)) try: