我有兴趣尝试使用SimpleITK来解决我的成像问题.你能告诉我文件和培训材料在哪里吗?
我知道有一个函数scipy.ndimage.zoom可以调整 3D 体积的大小\重新采样,但那是针对 numpy.array 的,而且它的速度非常慢。因此,我用ResampleImageFilterfromSimpleITK代替。我认为基于 C++ simpleitk 工作得更快。
但是使用 simpleitk 重新采样有一个小缺陷。ResampleImageFilter适用于SimpleITK.Image,但不适用于numpy.array,因此进行进一步操作非常不方便。还有其他方法可以对 3D 体积进行重新采样吗?
编辑
为什么我有这个担忧是因为我想利用 SimpleITK 重采样的快速速度,同时我想保持代码干净。例如,我需要对一个卷进行二进制阈值,然后对整个事物进行重新采样。所以这就是我的解决方案
binthresh = sitk.BinaryThresholdImageFilter()
... #setting up params for the binthresh
img = binarythresh.Execute(img)
resample = sitk.ResampleImageFilter()
... #setting up params for the resample
img = resample.Execute(img)
arr = sitk.GetArrayFromImage(img)
... # numpy operations on the arr
Run Code Online (Sandbox Code Playgroud)
但事实上,使用 numpy 进行二进制阈值的逻辑索引要简单得多,这将使我的代码更加紧凑。
总而言之,我想充分利用 SimpleITK 重采样,但有些操作可以通过 numpy 更好地完成,然后我的代码与 SimpleITK 和 numpy 都有点交织在一起。我认为这不是一件好事。
编辑注意:这个问题最初的措辞是
如何在 Linux 中将 SimpleITK.Show() 链接到 imageJ?
通过将 SimpleITK 1.0.0 升级到 1.0.1,我能够从 SimpleITK.Show() 启动 ImageJ。但是,ImageJ 无法打开“sample_mri.hdr”。ImageJ 生成以下错误消息。
文件格式不支持,请阅读器
插件不可用,或者未找到。
根/本地/linux/ImageJ/open(“/temp/TempFile-7131-2.nii”);
root/local/linux/ImageJ/rename("/temp/TempFile-7131-2.nii");
我已经为 ImageJ 安装了适当的插件来读取 hdr/img (分析格式)。我可以通过转到 file>open 直接从 ImageJ 打开“sample_mri.hdr”
调试消息:
sitk.Show(img, 'sample image', debugOn=True)
Run Code Online (Sandbox Code Playgroud)
FindApplication 搜索路径:[ ./Fiji.app、/cis/home/vwang/bin/Fiji.app、~/bin/Fiji.app、/opt/Fiji.app、/usr/local/Fiji.app ]
结果:
FindApplication 搜索路径:[ ./Fiji.app、/cis/home/vwang/bin/Fiji.app、~/bin/Fiji.app、/opt/Fiji.app、/usr/local/Fiji.app ]
结果:
FindApplication 搜索路径:[ ./ImageJ、/cis/home/vwang/bin/ImageJ、~/bin/ImageJ、/opt/ImageJ、/usr/local/ImageJ ]
结果:
FindApplication 搜索路径:[ ./, /cis/home/vwang/bin/, ~/bin/, /opt/, /usr/local/ ]
结果:/usr/local/bin/ImageJ
显示命令: '/usr/local/bin/ImageJ' '-e' 'open("/tmp/sample-4434-0.nii"); 重命名(“样本”);'
插件:
如何在 Linux 中将 SimpleITK.Show() 链接到 imageJ?
我已经下载了ImageJ,可以直接运行ImageJ来查看图像。过去曾提出并回答过类似的问题(Can not "link"SimpleITK::Show() with FIJI),但解决方案适用于 …
我有一套 3D 卷,我正在阅读 SimpleITK
import SimpleITK as sitk
for filename in filenames:
image = sitk.ReadImage(filename)
Run Code Online (Sandbox Code Playgroud)
每个卷都有不同的大小、间距、原点和方向。此代码为不同的图像生成不同的值:
print(image.GetSize())
print(image.GetOrigin())
print(image.GetSpacing())
print(image.GetDirection())
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何将图像转换为具有相同的大小和间距,以便它们在转换为numpy数组时都具有相同的分辨率和大小。就像是:
import SimpleITK as sitk
for filename in filenames:
image = sitk.ReadImage(filename)
image = transform(image, fixed_size, fixed_spacing)
array = sitk.GetArrayFromImage(image)
Run Code Online (Sandbox Code Playgroud) 我有一些 DICOM 图像。我想使用 重新调整它们IntensityWindowingImageFilter,但首先,我需要知道最大和最小强度的初始值。
现在,我正在构建 WPF UI,我想要一些滑块来允许用户为此操作交互输入参数。但是,为了获得最佳的用户体验,我需要限制滑块的比例以具有最大和最小图像强度的最大值和最小值。在 ITK 中,我可以使用MinimumMaximumImageCalculator,但我似乎无法在 SimpleITK 中找到它。
当然,我可以简单地使用Image.GetBufferAsXXX()并简单地迭代每个像素来找到这些值,但我几乎可以肯定这不是正确的方法。
通过方向,我的意思是例如从患者的头部到底部或从他的底部到头部.我到目前为止看到的CHEST CT扫描表明,Instance Number 1切片通常是从身体上部向下的第一个切片,但我不知道这是否是标准的一部分或者我应该有其他一些标签检查确定.
我正在使用 SimpleITK 来读取 MetaImage 数据。
有时我只需要访问元数据(它存储在一个 key=value .mhd 文件中),但我发现这样做的唯一方法是调用ReadImage它,因为它将整个数组加载到内存中时非常慢。
import SimpleITK as sitk
mhd = sitk.ReadImage(filename)
origin = mhd.GetOrigin()
spacing = mhd.GetSpacing()
direction = mhd.GetDirection()
Run Code Online (Sandbox Code Playgroud)
有没有办法在不加载完整图像的情况下访问原点间距和方向?
我最近开始使用 SimpleITK 进行图像配准。对于我当前的项目,我需要配准 X 射线图像和 CT 图像,然后在 X 射线图像上跟踪的 ROI 掩模上应用逆矩阵。
我得到了这一行的逆矩阵:
inverse_transform = final_transform.GetInverse()
Run Code Online (Sandbox Code Playgroud)
如何将变换应用于 ROI 蒙版?
python registration image-processing transformation-matrix simpleitk
我使用此代码将 dicom 图像系列读入 python
series_IDs = sitk.ImageSeriesReader.GetGDCMSeriesIDs(data_directory)
series_file_names = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(data_directory, series_IDs[0])
series_reader = sitk.ImageSeriesReader()
series_reader.SetFileNames(series_file_names)
series_reader.LoadPrivateTagsOn()
image3D=series_reader.Execute()
size = image3D.GetSize()
Run Code Online (Sandbox Code Playgroud)
目前,其定位如下:
我需要将方向更改为以下方向:
python中是否有任何命令可以改变SimpleITK图像的方向?
我想从使用以下代码获得的二维二进制图像中提取标签:
image2DThresh = sitk.Threshold(image2D, lower=stats.GetMinimum(), upper=127.500)
cca = sitk.ConnectedComponentImageFilter()
cca_image = cca.Execute(2D_Slice)
# Get the shape statistics of the labels using
labelStats = sitk.LabelShapeStatisticsImageFilter()
Run Code Online (Sandbox Code Playgroud)
基本思想是在主图像中找到标签的平均强度、ROI面积和最小/最大索引。我想要做的是使用阈值过滤器对图像进行二值化,然后在其上运行 CCA 以获取所有标签。然后我使用LabelShapeStatisticsImageFilter()获取每个标签的物理属性(当然标签0除外)并检查标签是否满足条件。问题是我无法在标签所在的主图像中获得平均强度。这就是为什么我建议使用LabelIntensityStatisticsFilter,但是对于 python 2.7,SimpleITK 0.10 不可用。
我有一个 32x32x3(高、宽、深)图像,我试图在 sitk 中围绕 z 轴旋转 45 度。然而,看起来我要旋转的 z/深度轴是一个角度。我如何才能旋转图像,以便如果我查看图像的一个切片,我会看到该切片从中心旋转了 45 度?
下面是我的代码,代码下面是图像(第一个是原始图像,第二个是尝试旋转失败)。此外,这些是公共图像,而不是机密数据。
def resample(image, transform):
"""
This function resamples (updates) an image using a specified transform
:param image: The sitk image we are trying to transform
:param transform: An sitk transform (ex. resizing, rotation, etc.
:return: The transformed sitk image
"""
reference_image = image
interpolator = sitk.sitkBSpline
default_value = 0
return sitk.Resample(image, reference_image, transform,
interpolator, default_value)
def get_center(img):
"""
This function returns the physical center point of a 3d sitk …Run Code Online (Sandbox Code Playgroud) 我试图通过使用来限制保留的 DICOM 标签
for key in keys:
if key.upper() not in {'0028|0010','0028|0011'}:
image_slice.EraseMetaData(key)
Run Code Online (Sandbox Code Playgroud)
在 Python 3.6 中,其中 image_slice 的类型为 SimpleITK.SimpleITK.Image
然后我用
image_slice.GetMetaDataKeys()
Run Code Online (Sandbox Code Playgroud)
查看剩余的标签,它们是我选择的标签。然后我保存图像
writer.SetFileName(outputDir+os.path.basename(sliceFileNames[i]))
writer.Execute(image_slice)
Run Code Online (Sandbox Code Playgroud)
其中 outputDir 是输出目录名称, os.path.basename(sliceFileNames[i]) 是 DICOM 图像名称。但是,当我使用 Weasis 或 MIPAV 打开图像时,我注意到标签比 image_slice 中的多得多。例如,有
(0002,0001) [OB] FileMetaInformationVersion: binary data
(0002,0002) [UI] MediaStorageSOPClassUID:
(0002,0003) [UI] MediaStorageSOPInstanceUID:
(0008,0020) [DA] StudyDate: (which is given the date that the file was created)
Run Code Online (Sandbox Code Playgroud)
我想知道这些附加标签是如何以及在哪里添加的。