| Conditions | 2 |
| Total Lines | 14 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import torch |
||
| 21 | def __call__(self, sample: Subject) -> Generator[Subject, None, None]: |
||
| 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 | index_ini = [torch.randint(x + 1, (1,)).item() for x in valid_range] |
||
| 33 | index_ini_array = np.asarray(index_ini) |
||
| 34 | yield self.extract_patch(sample, index_ini_array) |
||
| 35 |