示例#1
0
def test_is_localizer():
    input_label = 'LOCALIZER'
    assert common_utils.is_localizer(input_label)
    input_label = 2
    assert not common_utils.is_localizer(input_label)
示例#2
0
def classify_CT(df, dcm_metadata, acquisition):
    '''
    Classifies a CT dicom series

    Args:
        df (DataFrame): A pandas DataFrame where each row is a dicom image header information
    Returns:
        dict: The dictionary for the CT classification
    '''
    log.info("Determining CT Classification...")
    header_dicom = dcm_metadata['info']['header']['dicom']
    series_description = header_dicom.get('SeriesDescription') or ''
    classification_source = {}
    classification = {}
    info_object = {}
    
    if common_utils.is_localizer(acquisition.label) or common_utils.is_localizer(series_description) or len(df) < 10:
        classification['Scan Type'] = ['Localizer']
    else:
        classification['Scan Type'] = \
            common_utils.get_scan_type_classification(
            acquisition.label, header_dicom)
        if not classification['Scan Type']:
            classification['Scan Type'] = \
                common_utils.get_scan_type_classification(
                series_description, header_dicom)

        # # Compute scan coverage
        scan_coverage, info_object = \
            common_utils.compute_scan_coverage_if_original(header_dicom, df,
                                                           info_object)
        
        # # Reconstruction window
        reconstruction_window = None
        reconstruction_window = common_utils.get_reconstruction_window(
            acquisition.label)
        if reconstruction_window:
            info_object['ReconstructionWindow'] = reconstruction_window
        
        # # Classify Scan orientation 
        classification['Scan Orientation'] = common_utils.get_scan_orientation(acquisition.label)
        if not classification['Scan Orientation']:
            classification['Scan Orientation'] = common_utils.get_scan_orientation(
                series_description)
            
            
        # # Classify Anatomy
        classification = common_utils.classify_anatomy(
            classification, acquisition, series_description, scan_coverage)

        # # Classify Contrast
        classification['Contrast'] = common_utils.get_contrast_classification(
            acquisition.label)
        if not classification['Contrast']:
            classification['Contrast'] = \
                common_utils.get_contrast_classification(
                series_description)



        # # Set Custom classification to 'Unknown' if any of the CT classification keys is absent or empty:
        if 'Scan Orientation' not in classification.keys():
            classification['Custom'] = ['Unknown']
        elif not classification['Scan Orientation']:
            classification['Custom'] = ['Unknown']
        else:
            # If classification exists  then create a tag in classification_source dict 
            # to indicate the source of Scan Orientation classification
            # This classification_source dict is then added to info object
            classification_source['Scan Orientation'] = 'Original'

        if 'Contrast' not in classification.keys():
            classification['Custom'] = ['Unknown']
        elif not classification['Contrast']:
            classification['Custom'] = ['Unknown']
        else:
            # If classification exists  then create a tag in classification_source dict 
            # to indicate the source of Contrast classification
            # This classification_source dict is then added to info object
            classification_source['Contrast'] = 'Original'

        if 'Anatomy' not in classification.keys():
            classification['Custom'] = ['Unknown']
        elif not classification['Anatomy']:
            classification['Custom'] = ['Unknown']
        else:
            # If classification exists  then create a tag in classification_source dict 
            # to indicate the source of Anatomy classification
            # This classification_source dict is then added to info object
            classification_source['Anatomy'] = 'Original'


        # # Scan Coverage
        if scan_coverage:
            spacing_between_slices = scan_coverage / len(df)
            info_object['SpacingBetweenSlices'] = round(spacing_between_slices, 2)
        
        info_object['ClassificationSource'] = classification_source
        dcm_metadata['info'].update(info_object)

    dcm_metadata['classification'] = classification

    return dcm_metadata
示例#3
0
def classify_CT(df, dcm_metadata, acquisition):
    '''
    Classifies a CT dicom series

    Args:
        df (DataFrame): A pandas DataFrame where each row is a dicom image header information
    Returns:
        dict: The dictionary for the CT classification
    '''
    log.info("Determining CT Classification...")
    single_header_object = dcm_metadata['info']['header']['dicom']
    series_description = single_header_object.get('SeriesDescription') or ''
    classifications = {}
    info_object = {}

    if common_utils.is_localizer(
            acquisition.label) or common_utils.is_localizer(
                series_description) or len(df) < 10:
        classifications['Scan Type'] = ['Localizer']
    else:
        classifications['Scan Type'] = get_scan_type_classification(
            acquisition.label, single_header_object)
        if not classifications['Scan Type']:
            classifications['Scan Type'] = get_scan_type_classification(
                series_description, single_header_object)

        scan_coverage = None
        if single_header_object['ImageType'][0] == 'ORIGINAL':
            scan_coverage = common_utils.compute_scan_coverage(df)
        if scan_coverage:
            info_object['ScanCoverage'] = scan_coverage

        # # Reconstruction window
        reconstruction_window = None
        reconstruction_window = get_reconstruction_window(acquisition.label)
        if reconstruction_window:
            info_object['ReconstructionWindow'] = reconstruction_window

        # # Scan orientation
        scan_orientation = None
        scan_orientation = get_scan_orientation(acquisition.label)
        if scan_orientation:
            info_object['ScanOrientation'] = scan_orientation
        else:
            scan_orientation = get_scan_orientation(series_description)
            if scan_orientation:
                info_object['ScanOrientation'] = scan_orientation

        # # Anatomy
        classifications['Anatomy'] = get_anatomy_from_label(acquisition.label)
        if not classifications['Anatomy']:
            classifications['Anatomy'] = get_anatomy_from_label(
                series_description)
        if not classifications['Anatomy']:
            classifications['Anatomy'] = get_anatomy_from_scan_coverage(
                scan_coverage)

        # # Contrast
        classifications['Contrast'] = get_contrast_classification(
            acquisition.label)
        if not classifications['Contrast']:
            classifications['Contrast'] = get_contrast_classification(
                series_description)

        if scan_coverage:
            spacing_between_slices = scan_coverage / len(df)
            info_object['SpacingBetweenSlices'] = round(
                spacing_between_slices, 2)

        dcm_metadata['info'].update(info_object)

    dcm_metadata['classification'] = classifications

    return dcm_metadata
示例#4
0
def infer_classification(label):
    """
    Get classification based on acquisition label
    """
    if not label:
        return {}
    else:
        classification = {}
        if is_anatomy_inplane(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['T1']
            classification['Features'] = ['In-Plane']
        elif is_fieldmap(label):
            classification['Intent'] = ['Fieldmap']
            classification['Measurement'] = ['B0']
        elif is_diffusion_derived(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['Diffusion']
            classification['Features'] = ['Derived']
        elif is_diffusion(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['Diffusion']
        elif is_functional_derived(label):
            classification['Intent'] = ['Functional']
            classification['Features'] = ['Derived']
        elif is_functional(label):
            classification['Intent'] = ['Functional']
            classification['Measurement'] = ['T2*']
        elif is_anatomy_t1(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['T1']
        elif is_anatomy_t2star(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['T2*']
        elif is_anatomy_t2(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['T2']
        elif is_anatomy(label):
            classification['Intent'] = ['Structural']
        elif is_swi(label) :
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['Susceptibility']
        elif common_utils.is_localizer(label):
            classification['Intent'] = ['Localizer']
            classification['Measurement'] = ['T2']
        elif is_shim(label):
            classification['Intent'] = ['Shim']
        elif is_calibration(label):
            classification['Intent'] = ['Calibration']
        elif is_coil_survey(label):
            classification['Intent'] = ['Calibration']
            classification['Measurement'] = ['B1']
        elif is_proton_density(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['PD']
        elif is_perfusion(label):
            classification['Measurement'] = ['Perfusion']
        elif is_spectroscopy(label):
            classification['Intent'] = ['Spectroscopy']
        elif is_phase_map(label):
            classification['Custom'] = ['Phase Map']
        elif is_screenshot(label):
            classification['Intent'] = ['Screenshot']
        else:
            print(label.strip('\n') + ' --->>>> unknown')
            

		# Add Contrast-agent
        if is_contrast(label):
            class_features = classification.get('Features', [])
            class_features.append('Contrast-Agent')
            classification['Features'] = class_features
        	

        # Add features to classification
        features = feature_check(label)
        if features:
            class_features = classification.get('Features', [])
            [class_features.append(x) for x in features if x not in class_features]
            classification['Features'] = class_features

        # Add measurements to classification
        measurements = measurement_check(label)
        if measurements:
            class_measurement = classification.get('Measurement', [])
            [class_measurement.append(x) for x in measurements if x not in class_measurement]
            classification['Measurement'] = class_measurement

        # Add intents to classification
        intents = intent_check(label)
        if intents:
            class_intent = classification.get('Intent', [])
            [class_intent.append(x) for x in intents if x not in class_intent]
            classification['Intent'] = class_intent
    
    return classification
示例#5
0
def infer_classification(label):
    '''
    Get classification based on acquisition label
    '''
    if not label:
        return {}
    else:
        classification = {}
        if is_anatomy_inplane(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['T1']
            classification['Features'] = ['In-Plane']
        elif is_fieldmap(label):
            classification['Intent'] = ['Fieldmap']
            classification['Measurement'] = ['B0']
        elif is_diffusion_derived(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['Diffusion']
            classification['Features'] = ['Derived']
        elif is_diffusion(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['Diffusion']
        elif is_functional_derived(label):
            classification['Intent'] = ['Functional']
            classification['Features'] = ['Derived']
        elif is_functional(label):
            classification['Intent'] = ['Functional']
            classification['Measurement'] = ['T2*']
        elif is_anatomy_t1(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['T1']
        elif is_anatomy_t2(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['T2']
        elif is_anatomy(label):
            classification['Intent'] = ['Structural']
        elif common_utils.is_localizer(label):
            classification['Intent'] = ['Localizer']
            classification['Measurement'] = ['T2']
        elif is_shim(label):
            classification['Intent'] = ['Shim']
        elif is_calibration(label):
            classification['Intent'] = ['Calibration']
        elif is_coil_survey(label):
            classification['Intent'] = ['Calibration']
            classification['Measurement'] = ['B1']
        elif is_proton_density(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['PD']
        elif is_perfusion(label):
            classification['Measurement'] = ['Perfusion']
        elif is_spectroscopy(label):
            classification['Intent'] = ['Spectroscopy']
        elif is_phase_map(label):
            classification['Custom'] = ['Phase Map']
        elif is_screenshot(label):
            classification['Intent'] = ['Screenshot']
        else:
            print(label.strip('\n') + ' --->>>> unknown')

    return classification
示例#6
0
def infer_classification(label):
    """
    Get classification based on acquisition label
    """
    if not label:
        return {}
    else:
        classification = {}
        if is_anatomy_inplane(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['T1']
            classification['Features'] = ['In-Plane']
        elif is_fieldmap(label):
            classification['Intent'] = ['Fieldmap']
            classification['Measurement'] = ['B0']
        elif is_diffusion_derived(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['Diffusion']
            classification['Features'] = ['Derived']
        elif is_diffusion(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['Diffusion']
        elif is_functional_derived(label):
            classification['Intent'] = ['Functional']
            classification['Features'] = ['Derived']
        elif is_functional(label):
            classification['Intent'] = ['Functional']
            classification['Measurement'] = ['T2*']
        elif is_anatomy_t1(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['T1']
        elif is_anatomy_t2(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['T2']
        elif is_anatomy(label):
            classification['Intent'] = ['Structural']
        elif is_swi(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['Susceptibility']
        elif common_utils.is_localizer(label):
            classification['Intent'] = ['Localizer']
            classification['Measurement'] = ['T2']
        elif is_shim(label):
            classification['Intent'] = ['Shim']
        elif is_calibration(label):
            classification['Intent'] = ['Calibration']
        elif is_coil_survey(label):
            classification['Intent'] = ['Calibration']
            classification['Measurement'] = ['B1']
        elif is_proton_density(label):
            classification['Intent'] = ['Structural']
            classification['Measurement'] = ['PD']
        elif is_perfusion(label):
            classification['Measurement'] = ['Perfusion']
        elif is_spectroscopy(label):
            classification['Intent'] = ['Spectroscopy']
        elif is_phase_map(label):
            classification['Custom'] = ['Phase Map']
        elif is_screenshot(label):
            classification['Intent'] = ['Screenshot']
        else:
            print(label.strip('\n') + ' --->>>> unknown')

        # Add features to classification
        features = feature_check(label)
        if features:
            class_features = classification.get('Features', [])
            [
                class_features.append(x) for x in features
                if x not in class_features
            ]
            classification['Features'] = class_features

        # Add measurements to classification
        measurements = measurement_check(label)
        if measurements:
            class_measurement = classification.get('Measurement', [])
            [
                class_measurement.append(x) for x in measurements
                if x not in class_measurement
            ]
            classification['Measurement'] = class_measurement

        # Add intents to classification
        intents = intent_check(label)
        if intents:
            class_intent = classification.get('Intent', [])
            [class_intent.append(x) for x in intents if x not in class_intent]
            classification['Intent'] = class_intent

        # Code for Contrast/ No-Contrast Classification ( New Feature added on May 13 2021)

        # Any label that satisfies the Contrast or No Contrast condition it would be tagged as Contrast/No Contrast
        # If a label satisfies both Contrast and No Contrast condition, Contrast would be negated and tagged as No Contrast
        # If a label doesn't satisfy both the conditions, the Classification would be left empty

        if is_contrast(label):

            classification['Contrast'] = ['Contrast']

        if is_not_contrast(label):

            classification['Contrast'] = ['No Contrast']

    return classification
示例#7
0
def classify_CT(df, dcm_metadata, acquisition):
    '''
    Classifies a CT dicom series

    Args:
        df (DataFrame): A pandas DataFrame where each row is a dicom image header information
    Returns:
        dict: The dictionary for the CT classification
    '''
    log.info("Determining CT Classification...")
    header_dicom = dcm_metadata['info']['header']['dicom']
    series_description = header_dicom.get('SeriesDescription') or ''
    classification = {}
    info_object = {}

    if common_utils.is_localizer(
            acquisition.label) or common_utils.is_localizer(
                series_description) or len(df) < 10:
        classification['Scan Type'] = ['Localizer']
    else:
        classification['Scan Type'] = \
            common_utils.get_scan_type_classification(
            acquisition.label, header_dicom)
        if not classification['Scan Type']:
            classification['Scan Type'] = \
                common_utils.get_scan_type_classification(
                series_description, header_dicom)

        # Compute scan coverage
        scan_coverage, info_object = \
            common_utils.compute_scan_coverage_if_original(header_dicom, df,
                                                           info_object)

        # # Reconstruction window
        reconstruction_window = None
        reconstruction_window = common_utils.get_reconstruction_window(
            acquisition.label)
        if reconstruction_window:
            info_object['ReconstructionWindow'] = reconstruction_window

        # # Scan orientation
        scan_orientation = None
        scan_orientation = common_utils.get_scan_orientation(acquisition.label)
        if scan_orientation:
            info_object['ScanOrientation'] = scan_orientation
        else:
            scan_orientation = common_utils.get_scan_orientation(
                series_description)
            if scan_orientation:
                info_object['ScanOrientation'] = scan_orientation

        # Classify Anatomy
        classification = common_utils.classify_anatomy(classification,
                                                       acquisition,
                                                       series_description,
                                                       scan_coverage)

        # # Contrast
        classification['Contrast'] = common_utils.get_contrast_classification(
            acquisition.label)
        if not classification['Contrast']:
            classification['Contrast'] = \
                common_utils.get_contrast_classification(
                series_description)

        if scan_coverage:
            spacing_between_slices = scan_coverage / len(df)
            info_object['SpacingBetweenSlices'] = round(
                spacing_between_slices, 2)

        dcm_metadata['info'].update(info_object)

    dcm_metadata['classification'] = classification

    return dcm_metadata