Conditions | 2 |
Total Lines | 14 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import torch |
||
20 | def __call__(self, sample: Subject) -> Generator[Subject, None, None]: |
||
21 | |||
22 | sample.check_consistent_spatial_shape() |
||
23 | |||
24 | if np.any(self.patch_size > sample.spatial_shape): |
||
|
|||
25 | message = ( |
||
26 | f'Patch size {tuple(self.patch_size)} cannot be' |
||
27 | f' larger than image size {tuple(sample.spatial_shape)}' |
||
28 | ) |
||
29 | raise RuntimeError(message) |
||
30 | |||
31 | valid_range = sample.spatial_shape - self.patch_size |
||
32 | corners = np.asarray([torch.randint(x+1,(1,)).item() for x in valid_range]) |
||
33 | yield self.extract_patch(sample, corners) |
||
34 |