Ejemplo n.º 1
0
    def test_foreground_position(self, arguments, input_data, _):
        result = SpatialCropForegroundd(**arguments)(input_data)
        np.testing.assert_allclose(result["image_meta_dict"]["foreground_start_coord"], np.array([0, 1, 1]))
        np.testing.assert_allclose(result["image_meta_dict"]["foreground_end_coord"], np.array([1, 4, 4]))

        arguments["start_coord_key"] = "test_start_coord"
        arguments["end_coord_key"] = "test_end_coord"
        result = SpatialCropForegroundd(**arguments)(input_data)
        np.testing.assert_allclose(result["image_meta_dict"]["test_start_coord"], np.array([0, 1, 1]))
        np.testing.assert_allclose(result["image_meta_dict"]["test_end_coord"], np.array([1, 4, 4]))
Ejemplo n.º 2
0
 def train_pre_transforms(self, context: Context):
     # Dataset preparation
     t: List[Any] = [
         LoadImaged(keys=("image", "label")),
         AddChanneld(keys=("image", "label")),
         SpatialCropForegroundd(keys=("image", "label"),
                                source_key="label",
                                spatial_size=self.roi_size),
         Resized(keys=("image", "label"),
                 spatial_size=self.model_size,
                 mode=("area", "nearest")),
         NormalizeIntensityd(keys="image", subtrahend=208.0,
                             divisor=388.0),  # type: ignore
     ]
     if self.dimension == 3:
         t.append(FindAllValidSlicesd(label="label", sids="sids"))
     t.extend([
         AddInitialSeedPointd(label="label",
                              guidance="guidance",
                              sids="sids"),
         AddGuidanceSignald(image="image", guidance="guidance"),
         EnsureTyped(keys=("image", "label"), device=context.device),
         SelectItemsd(keys=("image", "label", "guidance")),
     ])
     return t
Ejemplo n.º 3
0
def get_pre_transforms(roi_size, model_size, dimensions):
    t = [
        LoadImaged(keys=('image', 'label')),
        AddChanneld(keys=('image', 'label')),
        SpatialCropForegroundd(keys=('image', 'label'),
                               source_key='label',
                               spatial_size=roi_size),
        Resized(keys=('image', 'label'),
                spatial_size=model_size,
                mode=('area', 'nearest')),
        NormalizeIntensityd(keys='image', subtrahend=208.0, divisor=388.0)
    ]
    if dimensions == 3:
        t.append(FindAllValidSlicesd(label='label', sids='sids'))
    t.extend([
        AddInitialSeedPointd(label='label', guidance='guidance', sids='sids'),
        AddGuidanceSignald(image='image', guidance='guidance'),
        ToTensord(keys=('image', 'label'))
    ])
    return Compose(t)
Ejemplo n.º 4
0
def get_pre_transforms(roi_size, model_size, dimensions):
    t = [
        LoadImaged(keys=("image", "label")),
        AddChanneld(keys=("image", "label")),
        SpatialCropForegroundd(keys=("image", "label"),
                               source_key="label",
                               spatial_size=roi_size),
        Resized(keys=("image", "label"),
                spatial_size=model_size,
                mode=("area", "nearest")),
        NormalizeIntensityd(keys="image", subtrahend=208.0, divisor=388.0),
    ]
    if dimensions == 3:
        t.append(FindAllValidSlicesd(label="label", sids="sids"))
    t.extend([
        AddInitialSeedPointd(label="label", guidance="guidance", sids="sids"),
        AddGuidanceSignald(image="image", guidance="guidance"),
        EnsureTyped(keys=("image", "label")),
    ])
    return Compose(t)
 def test_correct_results(self, arguments, input_data, expected_result):
     result = SpatialCropForegroundd(**arguments)(input_data)
     np.testing.assert_allclose(result["image"], expected_result)
Ejemplo n.º 6
0
 def test_correct_shape(self, arguments, input_data, expected_shape):
     result = SpatialCropForegroundd(**arguments)(input_data)
     np.testing.assert_equal(result["image"].shape, expected_shape)