我有以下问题。我有一个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:No template[>;]用于itk::ImageFileWriter类”
我需要注意一些事情吗?在
关于itk<;->;Numpy转换的简短博客post。您应该将它与来自这个one的信息结合起来。我认为把scoreMatrixItk写入文件是不必要的。您应该能够执行
thresholdFilter.SetInput(scoreMatrixItk)
,也许在更改创建thresholdFilter
时使用的类型。因为您使用的是无符号字符,所以不需要rescaler
,除非您想将强度范围从0-50增加到0-255。我不知道为什么你现在出错了。在除了@Dženan的响应之外,还有一个问题:您没有为
scoreMatrixItk
指定文件格式。格式根据后缀确定。所以下面这一行:可能会阻止您出错。在
相关问题 更多 >
编程相关推荐