[ PROMPT_NODE_26922 ]
感兴趣区域 (ROI)
[ SKILL_DOCUMENTATION ]
# 感兴趣区域 (ROIs)
本参考指南涵盖了在 OMERO 中创建、检索和分析 ROI 的相关内容。
## ROI 概述
OMERO 中的 ROI(感兴趣区域)是几何形状的容器,用于标记图像上的特定区域。每个 ROI 可以包含多个形状,且形状可以针对特定的 Z 轴切片和时间点。
### 支持的形状类型
- **Rectangle**: 矩形区域
- **Ellipse**: 圆形和椭圆形区域
- **Line**: 线段
- **Point**: 单个点
- **Polygon**: 多点多边形
- **Mask**: 基于像素的掩码
- **Polyline**: 多段线
## 创建 ROI
### 辅助函数
python
from omero.rtypes import rdouble, rint, rstring
import omero.model
def create_roi(conn, image, shapes):
"""
创建 ROI 并将其链接到形状。
参数:
conn: BlitzGateway 连接
image: 图像对象
shapes: 形状对象列表
返回:
已保存的 ROI 对象
"""
roi = omero.model.RoiI()
roi.setImage(image._obj)
for shape in shapes:
roi.addShape(shape)
updateService = conn.getUpdateService()
return updateService.saveAndReturnObject(roi)
def rgba_to_int(red, green, blue, alpha=255):
"""
将 RGBA 值 (0-255) 转换为 OMERO 的整数编码。
参数:
red, green, blue, alpha: 颜色值 (0-255)
返回:
整数颜色值
"""
return int.from_bytes([red, green, blue, alpha],
byteorder='big', signed=True)
### 矩形 ROI
python
from omero.rtypes import rdouble, rint, rstring
import omero.model
# 获取图像
image = conn.getObject("Image", image_id)
# 定义位置和大小
x, y = 50, 100
width, height = 200, 150
z, t = 0, 0 # Z 轴切片和时间点
# 创建矩形
rect = omero.model.RectangleI()
rect.x = rdouble(x)
rect.y = rdouble(y)
rect.width = rdouble(width)
rect.height = rdouble(height)
rect.theZ = rint(z)
rect.theT = rint(t)
# 设置标签和颜色
rect.textValue = rstring("Cell Region")
rect.fillColor = rint(rgba_to_int(255, 0, 0, 50)) # 红色,半透明
rect.strokeColor = rint(rgba_to_int(255, 255, 0, 255)) # 黄色边框
# 创建 ROI
roi = create_roi(conn, image, [rect])
print(f"已创建 ROI ID: {roi.getId().getValue()}")
### 椭圆形 ROI
python
# 中心位置和半径
center_x, center_y = 250, 250
radius_x, radius_y = 100, 75
z, t = 0, 0
# 创建椭圆
ellipse = omero.model.EllipseI()
ellipse.x = rdouble(center_x)
ellipse.y