diff --git a/Modules/Bridge/NumPy/include/itkPyBuffer.h b/Modules/Bridge/NumPy/include/itkPyBuffer.h index 3d9df1de655..4481c8f8b09 100644 --- a/Modules/Bridge/NumPy/include/itkPyBuffer.h +++ b/Modules/Bridge/NumPy/include/itkPyBuffer.h @@ -21,7 +21,6 @@ #include "itkObject.h" #include "itkObjectFactory.h" -#include "itkImportImageFilter.h" #include "itkDefaultConvertPixelTraits.h" @@ -65,7 +64,7 @@ class PyBuffer /** Image dimension. */ static constexpr unsigned int ImageDimension = ImageType::ImageDimension; - using OutputImagePointer = typename Image::Pointer; + using OutputImagePointer = typename TImage::Pointer; /** * Get an Array with the content of the image buffer diff --git a/Modules/Bridge/NumPy/include/itkPyBuffer.hxx b/Modules/Bridge/NumPy/include/itkPyBuffer.hxx index dff7e7834f7..c28a369c089 100644 --- a/Modules/Bridge/NumPy/include/itkPyBuffer.hxx +++ b/Modules/Bridge/NumPy/include/itkPyBuffer.hxx @@ -20,6 +20,8 @@ #include "itkPyBuffer.h" +#include "itkImportImageContainer.h" + namespace itk { @@ -153,20 +155,19 @@ PyBuffer::_GetImageViewFromArray(PyObject * arr, PyObject * shape, PyObj SpacingType spacing; spacing.Fill(1.0); - using ImporterType = ImportImageFilter; + using InternalPixelType = typename TImage::InternalPixelType; + using ImporterType = ImportImageContainer; typename ImporterType::Pointer importer = ImporterType::New(); - importer->SetRegion(region); - importer->SetOrigin(origin); - importer->SetSpacing(spacing); - const bool importImageFilterWillOwnTheBuffer = false; - - PixelType * data = (PixelType *)buffer; - + const bool importImageFilterWillOwnTheBuffer = false; + InternalPixelType * data = (InternalPixelType *)buffer; importer->SetImportPointer(data, numberOfPixels, importImageFilterWillOwnTheBuffer); - importer->Update(); - OutputImagePointer output = importer->GetOutput(); - output->DisconnectPipeline(); + OutputImagePointer output = TImage::New(); + output->SetRegions(region); + output->SetOrigin(origin); + output->SetSpacing(spacing); + output->SetPixelContainer(importer); + output->SetNumberOfComponentsPerPixel(numberOfComponents); Py_DECREF(shapeseq); PyBuffer_Release(&pyBuffer);