def test_image_properties(self):
        dut = pymia_fltr_prep.NormalizeZScore()
        out = dut.execute(self.image)
        self.assertEqual(self.image.GetSize(), out.GetSize())
        self.assertEqual(self.image.GetOrigin(), out.GetOrigin())
        self.assertEqual(self.image.GetSpacing(), out.GetSpacing())
        self.assertEqual(self.image.GetDirection(), out.GetDirection())
        self.assertEqual(self.image.GetDimension(), out.GetDimension())
        self.assertEqual(self.image.GetNumberOfComponentsPerPixel(), out.GetNumberOfComponentsPerPixel())

        self.assertEqual(sitk.sitkFloat64, out.GetPixelID())
Exemple #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
Exemple #3
0
    def test_normalization_with_param(self):
        dut = pymia_fltr_prep.NormalizeZScore()
        out = dut.execute(self.image, pymia_fltr.IFilterParams())
        out_arr = sitk.GetArrayFromImage(out)

        np.testing.assert_array_almost_equal(self.desired, out_arr, decimal=12)