18 #ifndef sitkImageConvert_h
19 #define sitkImageConvert_h
25 template<
typename T,
unsigned int NVectorDimension >
class Vector;
34 template<
typename TPixelType,
unsigned int ImageDimension >
39 typedef itk::Image< itk::Vector< TPixelType, ImageDimension >, ImageDimension> ImageType;
45 sitkExceptionMacro(
"Expected number of elements in vector image to be the same as the dimension!");
49 typename ImageType::PixelType* buffer =
reinterpret_cast<typename ImageType::PixelType*
>( img->
GetPixelContainer()->GetBufferPointer() );
53 transferOwnership=
false;
56 typename ImageType::Pointer out = ImageType::New();
58 out->CopyInformation( img );
62 out->GetPixelContainer()->SetImportPointer(buffer, numberOfElements, transferOwnership );
70 template<
class TPixelType,
unsigned int NImageDimension,
unsigned int NLength >
78 typename VectorImageType::InternalPixelType* buffer =
reinterpret_cast<typename VectorImageType::InternalPixelType*
>( img->GetPixelContainer()->GetBufferPointer() );
83 numberOfElements *= NImageDimension;
86 if (!img->GetPixelContainer()->GetContainerManageMemory())
88 transferOwnership=
false;
92 typename VectorImageType::Pointer out = VectorImageType::New();
95 out->GetPixelContainer()->SetImportPointer(buffer, numberOfElements, transferOwnership );
96 img->GetPixelContainer()->SetContainerManageMemory(!transferOwnership);
97 out->CopyInformation( img );
98 out->SetRegions( img->GetBufferedRegion() );
104 template<
class TPixelType,
unsigned int NImageDimension >
109 return GetVectorImageFromImage<TPixelType,NImageDimension,NImageDimension>(img, transferOwnership);
115 #endif // sitkImageConvert_h
SizeValueType GetNumberOfPixels() const
unsigned int GetNumberOfComponentsPerPixel() const override
SITKCommon_HIDDEN itk::VectorImage< TPixelType, NImageDimension >::Pointer GetVectorImageFromImage(itk::Image< itk::Vector< TPixelType, NLength >, NImageDimension > *img, bool transferOwnership=false)
#define sitkExceptionMacro(x)
virtual const RegionType & GetBufferedRegion() const
SITKCommon_HIDDEN itk::Image< itk::Vector< TPixelType, ImageDimension >, ImageDimension >::Pointer GetImageFromVectorImage(itk::VectorImage< TPixelType, ImageDimension > *img, bool transferOwnership=false)
A utility method to help convert between itk image types efficiently.
PixelContainer * GetPixelContainer()
#define SITKCommon_HIDDEN