MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / _get_metadata

Method _get_metadata

monai/data/wsi_reader.py:290–320  ·  view source on GitHub ↗

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
    )

Source from the content-addressed store, hash-verified

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,

Callers 1

get_dataMethod · 0.95

Calls 2

get_file_pathMethod · 0.95
arrayMethod · 0.80

Tested by

no test coverage detected