ITK 对浮点数组的过滤

ITK Filter on an array of floats

我想使用 ITK 过滤连续浮点数组中的 3D 体积。我想应用 this example.

中所示的曲率流过滤器

我不知道如何将我的浮点数组与 ITK 连接起来,然后在另一端得到一个浮点数组。它会修改数据吗?它是如何工作的?

这里有一些代码来演示我正在尝试做的事情。

#include "itkCurvatureFlowImageFilter.h"

int main(int argc, char *argv[])
{
    float *my_array; // I have an array I have generated elsewhere
    // This is a 3D volume in order XYZ with these dimensions along each axis
    size_t num_x = 125;
    size_t num_y = 250;
    size_t num_z = 125;
    size_t num_elements = num_x * num_y * num_z;
    float voxel_size = 8e-3; // 8 mm voxels

    constexpr unsigned int Dimension = 3;

    // convert to an itk image
    // itkimage = ???

    using InputPixelType = float;
    using InputImageType = itk::Image<InputPixelType, Dimension>;

    const int numberOfIterations = 10;
    const InputPixelType timeStep = 0.05;


    using FilterType = itk::CurvatureFlowImageFilter<InputImageType, InputImageType>;
    FilterType::Pointer filter = FilterType::New();
    filter->SetInput(itkimage);
    filter->SetNumberOfIterations(numberOfIterations);
    filter->SetTimeStep(timeStep);

    // now I want to put the filter result back in th array
    filter->GetOutput();
    // Is the data modified in place? How can I get a regular float array out??

    return EXIT_SUCCESS;
}

itk::ImportImageFilter 用于将某个数组表示为图像的目的。查看文档中链接的示例。

由于 CurvatureFlowImageFilter 派生自 InPlaceImageFilter,并且您的输入和输出像素类型相同(浮动),它可以就地 运行。但您仍然需要请求:

itkimage = import...;
...
filter->SetInput(itkimage );
// set other parameters
filter->SetInPlace(true);
filter->Update();
itkimage = filter->GetOutput();