与3D图像(肾脏组织)交互#

在本教程中,我们交互式地探索了一个具有三个空间维度和三个颜色维度(通道)的生物医学图像。有关3D图像处理的一般介绍,请参阅 探索3D图像(细胞)。我们在这里使用的数据对应于用共聚焦荧光显微镜成像的肾脏组织(更多细节请参见 [1] 中的 kidney-tissue-fluorescence.tif)。

import matplotlib.pyplot as plt
import numpy as np

import plotly
import plotly.express as px
from skimage import data

加载图像#

这张生物医学图像可通过 scikit-image 的数据注册表获取。

返回的数据集是一个三维多通道图像:

print(f'number of dimensions: {data.ndim}')
print(f'shape: {data.shape}')
print(f'dtype: {data.dtype}')
number of dimensions: 4
shape: (16, 512, 512, 3)
dtype: uint16

维度按以下顺序提供:(z, y, x, c),即 [平面, 行, 列, 通道]

现在我们只考虑数据的一个切片(2D平面)。更具体地说,我们考虑位于堆栈中间的切片。imshow 函数可以显示灰度和RGB(A) 2D图像。

plot 3d interaction
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers). Got range [64..4095].

<matplotlib.image.AxesImage object at 0x175236bd0>

根据警告信息,数值范围是出乎意料的。图像的色彩呈现显然不令人满意。

vmin, vmax = data.min(), data.max()
print(f'range: ({vmin}, {vmax})')
range: (10, 4095)

我们转向 Plotly 的 plotly.express.imshow() 函数的实现,因为它支持浮点数的 值范围 超过 (0.0, 1.0) 和整数的 (0, 255)

这里是你需要的,*荧光*显微镜!

标准化每个通道的范围#

一般来说,我们可能希望在每个通道的基础上对值范围进行归一化。让我们沿着通道轴对数据进行分面(切片)。这样,我们得到三个单通道图像,其中每个图像的最大值被使用:

fig = px.imshow(
    data[n_plane // 2], facet_col=2, binary_string=True, labels={'facet_col': 'channel'}
)
plotly.io.show(fig)

每个颜色通道的值范围是多少?我们通过在所有非通道轴上取最小值和最大值来检查。

vmin_0, vmin_1, vmin_2 = np.min(data, axis=(0, 1, 2))
vmax_0, vmax_1, vmax_2 = np.max(data, axis=(0, 1, 2))
print(f'range for channel 0: ({vmin_0}, {vmax_0})')
print(f'range for channel 1: ({vmin_1}, {vmax_1})')
print(f'range for channel 2: ({vmin_2}, {vmax_2})')
range for channel 0: (10, 4095)
range for channel 1: (68, 4095)
range for channel 2: (35, 4095)

让我们非常具体地根据每个通道传递值范围:

Plotly 允许你通过平移、放大和缩小以及将所需图形导出为 PNG 格式的静态图像来与此可视化交互。

探索切片作为动画帧#

点击播放按钮以沿着 z 轴移动,穿过所有16个切片的堆栈。

fig = px.imshow(
    data,
    zmin=[vmin_0, vmin_1, vmin_2],
    zmax=[vmax_0, vmax_1, vmax_2],
    animation_frame=0,
    binary_string=True,
    labels={'animation_frame': 'plane'},
)
plotly.io.show(fig)

结合通道分面和切片动画#

fig = px.imshow(
    data,
    animation_frame=0,
    facet_col=3,
    binary_string=True,
    labels={'facet_col': 'channel', 'animation_frame': 'plane'},
)
plotly.io.show(fig)

生物学家的眼睛可以识别出这两个明亮的斑点(在 channel=2 中看得最清楚)是肾小球 [2]

脚本总运行时间: (0 分钟 7.794 秒)

由 Sphinx-Gallery 生成的图库