我遇到以下问题。我有一个充满 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/