简体   繁体   中英

ITK Filter on an array of floats

I want to use ITK to Filter a 3D volume that is in a contiguous float array. I want to apply the Curvature Flow Filter as shown in this example .

I don't know how to interface my float array with ITK and then to get a float array out on the other side. Will it modify the data in place? How does it work?

Here is some code to demonstrate what I am trying to do.

#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 is used for the purpose of representing some array as an image. Look at the examples linked in the documentation.

As CurvatureFlowImageFilter derives from InPlaceImageFilter , and both your input and output pixel type are same (float), it can run in-place. But you still need to request that:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM