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