Skip to content

Commit

Permalink
BUG: Return type for PyBuffer _GetImageViewFromArray with VectorImage
Browse files Browse the repository at this point in the history
Directly use ImageImageContainer so we can generate a VectorImage.
  • Loading branch information
thewtex committed Apr 15, 2020
1 parent 5b8473a commit cd62423
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
3 changes: 1 addition & 2 deletions Modules/Bridge/NumPy/include/itkPyBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include "itkObject.h"
#include "itkObjectFactory.h"
#include "itkImportImageFilter.h"
#include "itkDefaultConvertPixelTraits.h"


Expand Down Expand Up @@ -65,7 +64,7 @@ class PyBuffer
/** Image dimension. */
static constexpr unsigned int ImageDimension = ImageType::ImageDimension;

using OutputImagePointer = typename Image<PixelType, ImageDimension>::Pointer;
using OutputImagePointer = typename TImage::Pointer;

/**
* Get an Array with the content of the image buffer
Expand Down
23 changes: 12 additions & 11 deletions Modules/Bridge/NumPy/include/itkPyBuffer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "itkPyBuffer.h"

#include "itkImportImageContainer.h"

namespace itk
{

Expand Down Expand Up @@ -153,20 +155,19 @@ PyBuffer<TImage>::_GetImageViewFromArray(PyObject * arr, PyObject * shape, PyObj
SpacingType spacing;
spacing.Fill(1.0);

using ImporterType = ImportImageFilter<PixelType, ImageDimension>;
using InternalPixelType = typename TImage::InternalPixelType;
using ImporterType = ImportImageContainer<SizeValueType, InternalPixelType>;
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);
Expand Down

0 comments on commit cd62423

Please sign in to comment.