将数据库中的所有图像重新采样为相同的体素大小

时间:2016-07-05 03:28:20

标签: python matlab image-processing dicom

我有3个大小为512x512x133, 512x512x155 and 512x512x277的dicom堆栈。我想重新采样所有堆栈以生成大小512x512x277, 512x512x277 and 512x512x277。怎么做?

我知道我可以使用切片厚度和像素间距进行重采样。但是在每种情况下都不能确保相同数量的切片。

2 个答案:

答案 0 :(得分:0)

您可以使用scipy.ndimage.interpolate.zoom,为每个轴指定缩放系数数组,如下所示:

# example for first image
zoomArray = desiredshape.astype(float) / original.shape
zoomed = scipy.ndimage.interpolate.zoom(original, zoomArray)

更新:

如果这太慢了,你可以尝试以某种方式从你的"图像立方体"的垂直切片创建单独的图像,用一些高速图像库处理它们(有些人喜欢ImageMagick,那里&# 39; s也是PIL,opencv等),并将它们再次堆叠在一起。这样,您可以拍摄尺寸为512x133的512张图像并将其调整为512x277,然后再次堆叠到512x512x277,这是您最终所需的尺寸。而且,这种分离将允许并行化。人们认为要考虑的是:这只有在横轴(您将切割2D图像的轴)不会调整大小时才有效!

答案 1 :(得分:0)

您可以在 Resample transform 中使用 TorchIO

import torchio as tio
small, medium, large = dicom_dirs  # the folders of your three DICOMs
reference = tio.ScalarImage(large)
resample = tio.Resample(reference)
small_resampled = resample(small)
medium_resampled = resample(medium)

三个图像现在具有相同的形状,512 x 512 x 277。

免责声明:我是 TorchIO 的主要开发者。