[ SKILL_DOCUMENTATION ]
# 图像处理与渲染
本参考指南涵盖了访问原始像素数据、图像渲染以及在 OMERO 中创建新图像的相关内容。
## 访问原始像素数据
### 获取单个平面
python
# 获取图像
image = conn.getObject("Image", image_id)
# 获取维度
size_z = image.getSizeZ()
size_c = image.getSizeC()
size_t = image.getSizeT()
# 获取像素对象
pixels = image.getPrimaryPixels()
# 获取单个平面(返回 NumPy 数组)
z, c, t = 0, 0, 0 # 第一个 Z 轴切片、通道和时间点
plane = pixels.getPlane(z, c, t)
print(f"形状: {plane.shape}")
print(f"数据类型: {plane.dtype.name}")
print(f"最小值: {plane.min()}, 最大值: {plane.max()}")
### 获取多个平面
python
import numpy as np
# 获取特定通道和时间点的 Z 轴堆栈
pixels = image.getPrimaryPixels()
c, t = 0, 0 # 第一个通道和时间点
# 构建 (z, c, t) 坐标列表
zct_list = [(z, c, t) for z in range(size_z)]
# 一次获取所有平面
planes = pixels.getPlanes(zct_list)
# 堆叠为 3D 数组
z_stack = np.array([p for p in planes])
print(f"Z 轴堆栈形状: {z_stack.shape}")
### 获取超立方体(5D 数据的子集)
python
# 获取 5D 数据的子集 (Z, C, T)
zct_list = []
for z in range(size_z // 2, size_z): # Z 轴的后半部分
for c in range(size_c): # 所有通道
for t in range(size_t): # 所有时间点
zct_list.append((z, c, t))
# 获取平面
planes = pixels.getPlanes(zct_list)
# 处理每个平面
for i, plane in enumerate(planes):
z, c, t = zct_list[i]
print(f"平面 Z={z}, C={c}, T={t}: 最小值={plane.min()}, 最大值={plane.max()}")
### 获取切片(感兴趣区域)
python
# 定义切片坐标
x, y = 50, 50 # 左上角
width, height = 100, 100 # 切片大小
tile = (x, y, width, height)
# 获取特定 Z, C, T 的切片
z, c, t = 0, 0, 0
zct_list = [(z, c, t, tile)]
tiles = pixels.getTiles(zct_list)
tile_data = tiles[0]
print(f"切片形状: {tile_data.shape}") # 应为 (height, width)
### 获取多个切片
python
# 从 Z 轴堆栈获取切片
c, t = 0, 0
tile = (50, 50, 100, 100) # x, y, width, height
# 构建带切片的列表
zct_list = [(z, c, t, tile) for z in range(size_z)]
tiles = pixels.getTiles(zct_list)
for i, tile_data in enumerate(tiles):
print(f"切片 Z={i}: {tile_data.shape}, 最小值={tile_data.min()}")
## 图像直方图
### 获取直方图
python
# 获取第一个通道的直方图
channel_index = 0
num_bins = 256
z, t = 0, 0
histogram = image.getHi