Example #1
0
def register_images(image_dict, atlas_img):
    registration = fltr_reg.MultiModalRegistration()
    registration_params = fltr_reg.MultiModalRegistrationParams(atlas_img)
    # todo execute the registration with the T1-weighted image and the registration parameters
    registered_t1 = None  # todo: modify here

    gt_img = image_dict[structure.BrainImageTypes.GroundTruth]
    # todo: apply transform to GroundTruth image (gt_img) (hint: sitk.Resample, referenceImage=atlas_img,
    #  transform=registration.transform, interpolator=sitk.sitkNearestNeighbor
    registered_gt = None  # todo: modify here

    return registered_t1, registered_gt
Example #2
0
def pre_process(id_: str, paths: dict, **kwargs) -> structure.BrainImage:
    """Loads and processes an image.

    The processing includes:

    - Registration
    - Pre-processing
    - Feature extraction

    Args:
        id_ (str): An image identifier.
        paths (dict): A dict, where the keys are an image identifier of type structure.BrainImageTypes
            and the values are paths to the images.

    Returns:
        (structure.BrainImage):
    """

    print('-' * 10, 'Processing', id_)

    # load image
    path = paths.pop(
        id_, '')  # the value with key id_ is the root directory of the image
    img = {img_key: sitk.ReadImage(path) for img_key, path in paths.items()}
    img = structure.BrainImage(id_, path, img)

    # construct T1 pipeline
    pipeline_t1 = fltr.FilterPipeline()
    if kwargs.get('zscore_pre', False):
        pipeline_t1.add_filter(fltr_prep.NormalizeZScore())
    if kwargs.get('registration_pre', False):
        pipeline_t1.add_filter(fltr_reg.MultiModalRegistration())
        pipeline_t1.set_param(fltr_reg.MultiModalRegistrationParams(atlas_t1),
                              1)

    # execute pipeline on T1 image
    img.images[structure.BrainImageTypes.T1] = pipeline_t1.execute(
        img.images[structure.BrainImageTypes.T1])

    # construct T2 pipeline
    pipeline_t2 = fltr.FilterPipeline()
    if kwargs.get('zscore_pre', False):
        pipeline_t2.add_filter(fltr_prep.NormalizeZScore())

    # execute pipeline on T2 image
    img.images[structure.BrainImageTypes.T2] = pipeline_t2.execute(
        img.images[structure.BrainImageTypes.T2])

    if kwargs.get('registration_pre', False):
        # get transformation
        transform = pipeline_t1.filters[1].transform

        # apply transformation of T1 image registration to T2 image
        image_t2 = img.images[structure.BrainImageTypes.T2]
        image_t2 = sitk.Resample(image_t2, atlas_t1, transform,
                                 sitk.sitkLinear, 0.0,
                                 image_t2.GetPixelIDValue())
        img.images[structure.BrainImageTypes.T2] = image_t2

        # apply transformation of T1 image registration to ground truth
        image_ground_truth = img.images[structure.BrainImageTypes.GroundTruth]
        image_ground_truth = sitk.Resample(
            image_ground_truth, atlas_t1, transform, sitk.sitkNearestNeighbor,
            0, image_ground_truth.GetPixelIDValue())
        img.images[structure.BrainImageTypes.GroundTruth] = image_ground_truth

        # update image properties to atlas image properties after registration
        img.image_properties = conversion.ImageProperties(atlas_t1)

    # extract the features
    feature_extractor = FeatureExtractor(img, **kwargs)
    img = feature_extractor.execute()

    img.feature_images = {}

    return img