# Transfer from VTK to SimpleITK

**URL:** https://discourse.itk.org/t/transfer-from-vtk-to-simpleitk/2717
**Category:** Beginner Questions
**Tags:** simpleitk
**Created:** [February 13, 2020, 9:58am UTC](https://discourse.itk.org/t/transfer-from-vtk-to-simpleitk/2717 "2020-02-13T09:58:08Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![flaviu2](https://discourse.itk.org/letter_avatar_proxy/v4/letter/f/74df32/32.png) [@flaviu2](https://discourse.itk.org/u/flaviu2)
#### Post date: [February 14, 2020, 2:39pm UTC](https://discourse.itk.org/t/transfer-from-vtk-to-simpleitk/2717/7 "2020-02-14T14:39:03Z")

</div>

Please have patience with me. I come back because I have tried to use this example:

> <https://github.com/SimpleITK/SimpleITK/blob/master/Examples/BufferImportExport.cxx>

to import data from [vtkImageData](https://vtk.org/doc/nightly/html/classvtkImageData.html) into sitk::Image through sitk::ImportImageFilter.

Here is the code:

```
sitk::ImportImageFilter importer;

int* nDim = m_pDICOMReader->GetOutput()->GetDimensions();
TRACE(">>>>%d|%d|%d\n", nDim[0], nDim[1], nDim[2]);
uint8_t* in = new uint8_t[nDim[0] * nDim[1] * nDim[2]];

double* dSpacing = m_pDICOMReader->GetOutput()->GetSpacing();
std::vector<double> spacing;
spacing.push_back(dSpacing[0]);
spacing.push_back(dSpacing[1]);
spacing.push_back(dSpacing[2]);
importer.SetSpacing(spacing);
double* dOrigin = m_pDICOMReader->GetOutput()->GetOrigin();
std::vector<double> origin;
origin.push_back(dOrigin[0]);
origin.push_back(dOrigin[1]);
origin.push_back(dOrigin[2]);
importer.SetOrigin(origin);
int nSize = m_pDICOMReader->GetOutput()->GetScalarSize();
std::vector<unsigned int> size;
size.push_back(nSize);
importer.SetSize(size);
importer.SetBufferAsUInt8(in);

try
{
	sitk::Image img = importer.Execute();
}
catch (sitk::GenericException& error)
{
	::SendMessage(theApp.m_pMainWnd->GetSafeHwnd(), WM_SETMESSAGESTRING, 0, (LPARAM)error.GetDescription());
}

```

but I got the following error:

**sitk::ERROR: The length of size is invalid! Only image of dimension 2 or 3 are supported**

What I have done wrong ? I really need this conversion in order to keep working ! Thank you for any help !

---

_[View the full topic](https://discourse.itk.org/t/transfer-from-vtk-to-simpleitk/2717)._
