Ejemplo n.º 1
0
 def __init__(
         self,
         num_control_points: Union[int, Tuple[int, int, int]] = 7,
         max_displacement: Union[float, Tuple[float, float, float]] = 7.5,
         locked_borders: int = 2,
         image_interpolation: Interpolation = Interpolation.LINEAR,
         p: float = 1,
         seed: Optional[int] = None,
         is_tensor = False,
         ):
     super().__init__(p=p, seed=seed, is_tensor=is_tensor)
     self._bspline_transformation = None
     self.num_control_points = to_tuple(num_control_points, length=3)
     self.parse_control_points(self.num_control_points)
     self.max_displacement = to_tuple(max_displacement, length=3)
     self.parse_max_displacement(self.max_displacement)
     self.num_locked_borders = locked_borders
     self.is_tensor = is_tensor
     if locked_borders not in (0, 1, 2):
         raise ValueError('locked_borders must be 0, 1, or 2')
     if locked_borders == 2 and 4 in self.num_control_points:
         message = (
             'Setting locked_borders to 2 and using less than 5 control'
             'points results in an identity transform. Lock fewer borders'
             ' or use more control points.'
         )
         raise ValueError(message)
     self.interpolation = self.parse_interpolation(image_interpolation)
Ejemplo n.º 2
0
 def __init__(
         self,
         data: TypeData,
         patch_size: TypeTuple,
         patch_overlap: TypeTuple,
         ):
     self.array = data
     patch_size = to_tuple(patch_size, n=3)
     patch_overlap = to_tuple(patch_overlap, n=3)
     self.locations = self._grid_spatial_coordinates(
         self.array,
         patch_size,
         patch_overlap,
     )
Ejemplo n.º 3
0
 def __init__(
         self,
         data: Union[np.ndarray, torch.Tensor],
         patch_size: Union[int, Sequence[int]],
         patch_overlap: Union[int, Sequence[int]],
         ):
     self.array = data
     patch_size = to_tuple(patch_size)
     patch_overlap = to_tuple(patch_overlap)
     self.locations = self._grid_spatial_coordinates(
         self.array,
         patch_size,
         patch_overlap,
     )
Ejemplo n.º 4
0
 def parse_axes(axes: Union[int, Tuple[int, ...]]):
     axes_tuple = to_tuple(axes)
     for axis in axes_tuple:
         is_int = isinstance(axis, int)
         if not is_int or axis not in (0, 1, 2):
             raise ValueError('All axes must be 0, 1 or 2')
     return axes_tuple
Ejemplo n.º 5
0
 def __init__(
     self,
     data: Union[torch.Tensor, np.ndarray],
     patch_overlap: Union[int, Sequence[int]],
 ):
     self.output_array = np.full(
         data.shape,
         fill_value=0,
         dtype=np.uint16,
     )
     self.patch_overlap = to_tuple(patch_overlap)
Ejemplo n.º 6
0
 def test_to_tuple(self):
     assert to_tuple(1) == (1,)
     assert to_tuple((1,)) == (1,)
     assert to_tuple(1, length=3) == (1, 1, 1)
     assert to_tuple((1, 2)) == (1, 2)
     assert to_tuple((1, 2), length=3) == (1, 2)
     assert to_tuple([1, 2], length=3) == (1, 2)
Ejemplo n.º 7
0
 def test_to_tuple(self):
     assert to_tuple(1) == (1, )
     assert to_tuple((1, )) == (1, )
     assert to_tuple(1, n=3) == (1, 1, 1)
     assert to_tuple((1, 2)) == (1, 2)
     assert to_tuple((1, 2), n=3) == (1, 2)
     assert to_tuple([1, 2], n=3) == (1, 2)