Create a 3D volume figure as a grid of images. Args: volume: 3D volume to display. data shape can be `BCHWD`, `CHWD` or `HWD`. Higher dimensional arrays will be reshaped into (-1, H, W, [C]), `C` depends on `channel_dim` arg. A list of channel-first (C, H[,
(
volume: NdarrayOrTensor,
fig: Any = None,
title: str | None = None,
figsize: tuple[int, int] = (10, 10),
frames_per_row: int | None = None,
frame_dim: int = -3,
channel_dim: int | None = None,
vmin: float | None = None,
vmax: float | None = None,
every_n: int = 1,
interpolation: str = "none",
show: bool = False,
fill_value: Any = np.nan,
margin: int = 1,
dtype: DtypeLike = np.float32,
**kwargs: Any,
)
| 32 | |
| 33 | |
| 34 | def matshow3d( |
| 35 | volume: NdarrayOrTensor, |
| 36 | fig: Any = None, |
| 37 | title: str | None = None, |
| 38 | figsize: tuple[int, int] = (10, 10), |
| 39 | frames_per_row: int | None = None, |
| 40 | frame_dim: int = -3, |
| 41 | channel_dim: int | None = None, |
| 42 | vmin: float | None = None, |
| 43 | vmax: float | None = None, |
| 44 | every_n: int = 1, |
| 45 | interpolation: str = "none", |
| 46 | show: bool = False, |
| 47 | fill_value: Any = np.nan, |
| 48 | margin: int = 1, |
| 49 | dtype: DtypeLike = np.float32, |
| 50 | **kwargs: Any, |
| 51 | ) -> tuple[Any, np.ndarray]: |
| 52 | """ |
| 53 | Create a 3D volume figure as a grid of images. |
| 54 | |
| 55 | Args: |
| 56 | volume: 3D volume to display. data shape can be `BCHWD`, `CHWD` or `HWD`. |
| 57 | Higher dimensional arrays will be reshaped into (-1, H, W, [C]), `C` depends on `channel_dim` arg. |
| 58 | A list of channel-first (C, H[, W, D]) arrays can also be passed in, |
| 59 | in which case they will be displayed as a padded and stacked volume. |
| 60 | fig: matplotlib figure or Axes to use. If None, a new figure will be created. |
| 61 | title: title of the figure. |
| 62 | figsize: size of the figure. |
| 63 | frames_per_row: number of frames to display in each row. If None, sqrt(firstdim) will be used. |
| 64 | frame_dim: for higher dimensional arrays, which dimension from (`-1`, `-2`, `-3`) is moved to |
| 65 | the `-3` dimension. dim and reshape to (-1, H, W) shape to construct frames, default to `-3`. |
| 66 | channel_dim: if not None, explicitly specify the channel dimension to be transposed to the |
| 67 | last dimensionas shape (-1, H, W, C). this can be used to plot RGB color image. |
| 68 | if None, the channel dimension will be flattened with `frame_dim` and `batch_dim` as shape (-1, H, W). |
| 69 | note that it can only support 3D input image. default is None. |
| 70 | vmin: `vmin` for the matplotlib `imshow`. |
| 71 | vmax: `vmax` for the matplotlib `imshow`. |
| 72 | every_n: factor to subsample the frames so that only every n-th frame is displayed. |
| 73 | interpolation: interpolation to use for the matplotlib `matshow`. |
| 74 | show: if True, show the figure. |
| 75 | fill_value: value to use for the empty part of the grid. |
| 76 | margin: margin to use for the grid. |
| 77 | dtype: data type of the output stacked frames. |
| 78 | kwargs: additional keyword arguments to matplotlib `matshow` and `imshow`. |
| 79 | |
| 80 | See Also: |
| 81 | - https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html |
| 82 | - https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.matshow.html |
| 83 | |
| 84 | Example: |
| 85 | |
| 86 | >>> import numpy as np |
| 87 | >>> import matplotlib.pyplot as plt |
| 88 | >>> from monai.visualize import matshow3d |
| 89 | # create a figure of a 3D volume |
| 90 | >>> volume = np.random.rand(10, 10, 10) |
| 91 | >>> fig = plt.figure() |
searching dependent graphs…