使用pyp在图像上添加基于阵列的图形

2024-05-18 11:15:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在绘制一个来自CT的DICOM切片,我想在上面画一个感兴趣的区域(ROI)。问题是我还没有成功地在我的背景DICOM图像上显示这个ROI。我的想法是最后在我的背景DICOM图像上画一个彩色的圆圈。 代码如下:

import numpy as np
import matplotlib.pyplot as plt

ArrayDicom = np.ones((512, 512, 148))
plt.figure(figsize=(3, 3), dpi=300)
plt.axes().set_aspect('equal', 'datalim')
plt.axis('off')
plt.set_cmap(plt.gray())
x = np.arange(0, 512, 1)
y = np.arange(0, 512, 1)
plt.pcolormesh(x, y, np.flipud(ArrayDicom[:, :, 0]))  # ArrayDicom = Image 3D Array

nx, ny, nz = (512, 512, 148)
# Grid creation
x, y = np.ogrid[:nx, :ny]
# Mask creation
radius = 5
x_center, y_center = (2, 2)
contour = (x - x_center) ** 2 + (y - y_center) ** 2 == radius ** 2
mask_contour = np.zeros((nx, ny, nz))
mask_contour[:, :, 0][contour] = 1
ax = plt.gca()
ax.plot(mask_contour[:, :, 0], color='red')

plt.show()

我使用这个教程https://pyscience.wordpress.com/2014/09/08/dicom-in-python-importing-medical-image-data-into-numpy-with-pydicom-and-vtk/来显示我的DICOM图像。 我想我只是错过了一种绘制数据的方法。我知道我可以使用plt.Circle,但是我想接下来处理的是球体而不是圆。你知道吗

谢谢你的帮助。你知道吗


Tags: 图像importnumpynp绘制pltmaskdicom