def test_is_ge(self): assert not common.is_ge( read_dicom_directory(test_data.SIEMENS_ANATOMICAL)) assert common.is_ge(read_dicom_directory(test_data.GE_ANATOMICAL)) assert not common.is_ge( read_dicom_directory(test_data.PHILIPS_ANATOMICAL)) assert not common.is_ge( read_dicom_directory(test_data.GENERIC_ANATOMICAL)) assert not common.is_ge( read_dicom_directory(test_data.HITACHI_ANATOMICAL))
def dicom_to_nifti(dicom_input, output_file=None): """ This is the main dicom to nifti conversion fuction for ge images. As input ge images are required. It will then determine the type of images and do the correct conversion Examples: See unit test :param output_file: the filepath to the output nifti file :param dicom_input: list with dicom objects """ assert common.is_ge(dicom_input) # remove duplicate slices based on position and data dicom_input = convert_generic.remove_duplicate_slices(dicom_input) # remove localizers based on image type dicom_input = convert_generic.remove_localizers_by_imagetype(dicom_input) # remove_localizers based on image orientation (only valid if slicecount is validated) dicom_input = convert_generic.remove_localizers_by_orientation(dicom_input) logger.info('Reading and sorting dicom files') grouped_dicoms = _get_grouped_dicoms(dicom_input) if _is_4d(grouped_dicoms): logger.info('Found sequence type: 4D') return _4d_to_nifti(grouped_dicoms, output_file) logger.info('Assuming anatomical data') return convert_generic.dicom_to_nifti(dicom_input, output_file)
def dicom_to_nifti(dicom_input, output_file=None): """ This is the main dicom to nifti conversion fuction for ge images. As input ge images are required. It will then determine the type of images and do the correct conversion Examples: See unit test :param output_file: the filepath to the output nifti file :param dicom_input: list with dicom objects """ assert common.is_ge(dicom_input) logger.info('Reading and sorting dicom files') grouped_dicoms = _get_grouped_dicoms(dicom_input) if _is_4d(grouped_dicoms): logger.info('Found sequence type: 4D') return _4d_to_nifti(grouped_dicoms, output_file) logger.info('Assuming anatomical data') return convert_generic.dicom_to_nifti(dicom_input, output_file)
def _get_vendor(dicom_input): """ This function will check the dicom headers to see which type of series it is Possibilities are fMRI, DTI, Anatomical (if no clear type is found anatomical is used) """ # check if it is siemens if common.is_siemens(dicom_input): logger.info('Found manufacturer: SIEMENS') return Vendor.SIEMENS # check if it is ge if common.is_ge(dicom_input): logger.info('Found manufacturer: GE') return Vendor.GE # check if it is philips if common.is_philips(dicom_input): logger.info('Found manufacturer: PHILIPS') return Vendor.PHILIPS # check if it is philips if common.is_hitachi(dicom_input): logger.info('Found manufacturer: HITACHI') return Vendor.HITACHI # generic by default logger.info('WARNING: Assuming generic vendor conversion (ANATOMICAL)') return Vendor.GENERIC
def test_is_ge(self): assert not common.is_ge(read_dicom_directory(test_data.SIEMENS_ANATOMICAL)) assert common.is_ge(read_dicom_directory(test_data.GE_ANATOMICAL)) assert not common.is_ge(read_dicom_directory(test_data.PHILIPS_ANATOMICAL)) assert not common.is_ge(read_dicom_directory(test_data.GENERIC_ANATOMICAL)) assert not common.is_ge(read_dicom_directory(test_data.HITACHI_ANATOMICAL))
def anonymize_directory(input_directory, output_directory=None): if output_directory is None: output_directory = input_directory study_uid = pydicom.uid.generate_uid() series_uid = pydicom.uid.generate_uid() date = datetime.datetime.now().strftime("%Y%m%d") time = datetime.datetime.now().strftime("%H%M%S.000000") fields_to_keep = { 'SpecificCharacterSet': None, 'ImageType': None, 'AcquisitionMatrix': None, 'SOPClassUID': None, 'SOPInstanceUID': None, # Will be replaced by file-unique UID 'StudyDate': date, 'SeriesDate': date, 'AcquisitionDate': date, 'ContentDate': date, 'StudyTime': time, 'AcquisitionTime': time, 'AcquisitionNumber': None, 'Modality': None, 'Manufacturer': None, 'ManufacturersModelName': None, 'PatientName': 'dicom2nifti', 'PatientID': 'dicom2nifti', 'PatientsBirthDate': date, 'PatientsSex': None, 'PatientsAge': '0Y', 'PatientPosition': None, 'ScanningSequence': None, 'SequenceVariant': None, 'MRAcquisitionType': None, 'SequenceName': 'dicom2nifti', 'RepetitionTime': None, 'EchoTime': None, 'InversionTime': None, 'DeviceSerialNumber': '1234', 'StudyInstanceUID': study_uid, 'SeriesInstanceUID': series_uid, 'StudyID': 'dicom2nifti', 'SeriesNumber': None, 'InstanceNumber': None, 'ImagePositionPatient': None, 'ImageOrientationPatient': None, 'SliceLocation': None, 'PhotometricInterpretation': None, 'Rows': None, 'Columns': None, 'PixelSpacing': None, 'BitsAllocated': None, 'BitsStored': None, 'HighBit': None, 'RescaleSlope': None, 'RescaleIntercept': None, 'PixelRepresentation': None, 'NumberOfFrames': None, 'SamplesPerPixel': None, 'SpacingBetweenSlices': None, # Pixel Data must be specified with hex code as it will not work for compressed dicoms (0x7fe0, 0x0010): None } if is_philips(read_dicom_directory(input_directory)): philips_fields = { (0x2001, 0x100a): None, (0x2001, 0x1003): None, (0x2001, 0x105f): None, (0x2005, 0x100d): None, (0x2005, 0x100e): None, (0x2005, 0x10b0): None, (0x2005, 0x10b1): None, (0x2005, 0x10b2): None, (0x0018, 0x9087): None, (0x0018, 0x9089): None, (0x5200, 0x9230): None, 'SharedFunctionalGroupsSequence': None } fields_to_keep.update(philips_fields) if is_siemens(read_dicom_directory(input_directory)): siemens_fields = { (0x0019, 0x100c): None, (0x0029, 0x1020): None, (0x0051, 0x100b): None, (0x0019, 0x100e): None } fields_to_keep.update(siemens_fields) if is_ge(read_dicom_directory(input_directory)): ge_fields = { (0x0020, 0x9056): None, (0x0020, 0x9057): None, (0x0043, 0x1039): None, (0x0019, 0x10bb): None, (0x0019, 0x10bc): None, (0x0019, 0x10bd): None } fields_to_keep.update(ge_fields) _anonymize_files(input_directory, output_directory, fields_to_keep)