Python:在 ITK 中使用 3 维 numpy 数组

标签 python arrays numpy scipy itk

我遇到以下问题。我有一个充满 float 的 3D numpy 数组,称为 ScoreMatrix。现在我想在其上使用 Itk 过滤器,例如阈值过滤器。一般情况下可以吗?我尝试将 numpy 数组转换为 itk 图像,然后对其进行处理。还有其他方法吗?:

    scoreMatrixItk = itk.GetImageViewFromArray(scoreMatrix)

    itk.imwrite(scoreMatrixItk, "scoreMatrixItk")
    PixelType = itk.UC
    Dimension = 3

    ImageType = itk.Image[PixelType, Dimension]

    reader = itk.ImageFileReader[ImageType].New()
    reader.SetFileName('scoreMatrixItk')

    thresholdFilter = itk.OtsuMultipleThresholdsImageFilter[
            ImageType,
            ImageType].New()
    thresholdFilter.SetInput(reader.GetOutput())

    thresholdFilter.SetNumberOfHistogramBins(3)
    thresholdFilter.SetNumberOfThresholds(2)
    thresholdFilter.SetLabelOffset(4)

    rescaler = itk.RescaleIntensityImageFilter[ImageType, ImageType].New()
    rescaler.SetInput(thresholdFilter.GetOutput())
    rescaler.SetOutputMinimum(0)
    rescaler.SetOutputMaximum(255)

    writer = itk.ImageFileWriter[ImageType].New()
    writer.SetFileName('outputImage.tiff')
    writer.SetInput(rescaler.GetOutput())

    writer.Update()

但我收到错误:KeyError:“itkTemplate:没有 itk::ImageFileWriter 类的模板 [>]”

我需要注意一些事情吗?

最佳答案

简短的博客post关于 itk<->Numpy 转换。您应该将其与此 one 中的信息结合起来。 。我认为将 ScoreMatrixItk 写入文件是不必要的。在更改创建 thresholdFilter 时使用的类型之后,您应该能够执行 thresholdFilter.SetInput(scoreMatrixItk)。由于您使用的是 unsigned char,因此不需要 rescaler 除非您想增加强度范围,例如0-50 变为 0-255。我不知道为什么您目前会收到错误。

关于Python:在 ITK 中使用 3 维 numpy 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48543002/

相关文章:

javascript - JS : Convert text into object array

c - 如何改变char指针的值?

python - 运行 Holoview 和弦图示例时出错

python - 上下文管理器严格适用于生成器吗?

具有两个键和多个值的文件中的 Python 字典

python - NumPy 中的元素数组最大值函数(两个以上的数组)

python - 计算每个 pandas.DataFrame 列的 numpy.std?

python - 使用 xarray 绘图时如何互换 x 轴和 y 轴?

javascript - 按最大值获取数组索引?

python - 具有正弦波纹的 n 阶多项式的曲线拟合