Yield successive tuples of slices defining patches of size `patch_size` from an array of dimensions `image_size`. The iteration starts from position `start_pos` in the array, or starting at the origin if this isn't provided. Each patch is chosen in a contiguous grid using a rwo-major or
(
image_size: Sequence[int],
patch_size: Sequence[int] | int,
start_pos: Sequence[int] = (),
overlap: Sequence[float] | float = 0.0,
padded: bool = True,
)
| 128 | |
| 129 | |
| 130 | def iter_patch_slices( |
| 131 | image_size: Sequence[int], |
| 132 | patch_size: Sequence[int] | int, |
| 133 | start_pos: Sequence[int] = (), |
| 134 | overlap: Sequence[float] | float = 0.0, |
| 135 | padded: bool = True, |
| 136 | ) -> Generator[tuple[slice, ...], None, None]: |
| 137 | """ |
| 138 | Yield successive tuples of slices defining patches of size `patch_size` from an array of dimensions `image_size`. |
| 139 | The iteration starts from position `start_pos` in the array, or starting at the origin if this isn't provided. Each |
| 140 | patch is chosen in a contiguous grid using a rwo-major ordering. |
| 141 | |
| 142 | Args: |
| 143 | image_size: dimensions of array to iterate over |
| 144 | patch_size: size of patches to generate slices for, 0 or None selects whole dimension |
| 145 | start_pos: starting position in the array, default is 0 for each dimension |
| 146 | overlap: the amount of overlap of neighboring patches in each dimension (a value between 0.0 and 1.0). |
| 147 | If only one float number is given, it will be applied to all dimensions. Defaults to 0.0. |
| 148 | padded: if the image is padded so the patches can go beyond the borders. Defaults to False. |
| 149 | |
| 150 | Yields: |
| 151 | Tuples of slice objects defining each patch |
| 152 | """ |
| 153 | |
| 154 | # ensure patch_size has the right length |
| 155 | patch_size_ = get_valid_patch_size(image_size, patch_size) |
| 156 | |
| 157 | # create slices based on start position of each patch |
| 158 | for position in iter_patch_position( |
| 159 | image_size=image_size, patch_size=patch_size_, start_pos=start_pos, overlap=overlap, padded=padded |
| 160 | ): |
| 161 | yield tuple(slice(s, s + p) for s, p in zip(position, patch_size_)) |
| 162 | |
| 163 | |
| 164 | def dense_patch_slices( |
no test coverage detected
searching dependent graphs…