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

2024-05-06 09:22:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下问题。我有一个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类”

我需要注意一些事情吗?在


Tags: numpy过滤器new数组readerwriteritkgetoutput
2条回答

关于itk<;->;Numpy转换的简短博客post。您应该将它与来自这个one的信息结合起来。我认为把scoreMatrixItk写入文件是不必要的。您应该能够执行thresholdFilter.SetInput(scoreMatrixItk),也许在更改创建thresholdFilter时使用的类型。因为您使用的是无符号字符,所以不需要rescaler,除非您想将强度范围从0-50增加到0-255。我不知道为什么你现在出错了。在

除了@Dženan的响应之外,还有一个问题:您没有为scoreMatrixItk指定文件格式。格式根据后缀确定。所以下面这一行:

itk.imwrite(scoreMatrixItk, "scoreMatrixItk.vtk")

可能会阻止您出错。在

相关问题 更多 >