Returns metadata of the extracted patch from the whole slide image. Args: wsi: the whole slide image object, from which the patch is loaded. patch: extracted patch from whole slide image. location: (top, left) tuple giving the top left pixel in t
(
self, wsi, patch: NdarrayOrTensor, location: tuple[int, int], size: tuple[int, int], level: int
)
| 288 | raise NotImplementedError(f"Subclass {self.__class__.__name__} must implement this method.") |
| 289 | |
| 290 | def _get_metadata( |
| 291 | self, wsi, patch: NdarrayOrTensor, location: tuple[int, int], size: tuple[int, int], level: int |
| 292 | ) -> dict: |
| 293 | """ |
| 294 | Returns metadata of the extracted patch from the whole slide image. |
| 295 | |
| 296 | Args: |
| 297 | wsi: the whole slide image object, from which the patch is loaded. |
| 298 | patch: extracted patch from whole slide image. |
| 299 | location: (top, left) tuple giving the top left pixel in the level 0 reference frame. Defaults to (0, 0). |
| 300 | size: (height, width) tuple giving the patch size at the given level (`level`). |
| 301 | If None, it is set to the full image size at the given level. |
| 302 | level: the level number. |
| 303 | |
| 304 | """ |
| 305 | if self.channel_dim >= len(patch.shape) or self.channel_dim < -len(patch.shape): |
| 306 | raise ValueError( |
| 307 | f"The desired channel_dim ({self.channel_dim}) is out of bound for image shape: {patch.shape}" |
| 308 | ) |
| 309 | channel_dim: int = self.channel_dim + (len(patch.shape) if self.channel_dim < 0 else 0) |
| 310 | metadata: dict = { |
| 311 | "backend": self.backend, |
| 312 | "original_channel_dim": channel_dim, |
| 313 | "spatial_shape": np.array(patch.shape[:channel_dim] + patch.shape[channel_dim + 1 :]), |
| 314 | WSIPatchKeys.COUNT.value: 1, |
| 315 | WSIPatchKeys.PATH.value: self.get_file_path(wsi), |
| 316 | WSIPatchKeys.LOCATION.value: np.asarray(location), |
| 317 | WSIPatchKeys.SIZE.value: np.asarray(size), |
| 318 | WSIPatchKeys.LEVEL.value: level, |
| 319 | } |
| 320 | return metadata |
| 321 | |
| 322 | def get_data( |
| 323 | self, |
no test coverage detected