Example #1
0
 def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
     """
     Args:
         img: numpy arrays with required dimension `dim` removed
     """
     if self.dim is None:
         return img.squeeze()
     # for pytorch/numpy unification
     if img.shape[self.dim] != 1:
         raise ValueError("Can only squeeze singleton dimension")
     return img.squeeze(self.dim)
Example #2
0
    def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
        # if img has channel dim, squeeze it
        if img.ndim == 4 and img.shape[0] == 1:
            img = img.squeeze(0)

        result = [(img == 1) | (img == 4),
                  (img == 1) | (img == 4) | (img == 2), img == 4]
        # merge labels 1 (tumor non-enh) and 4 (tumor enh) and 2 (large edema) to WT
        # label 4 is ET
        return torch.stack(result, dim=0) if isinstance(
            img, torch.Tensor) else np.stack(result, axis=0)