flaviu2
(Flaviu)
February 13, 2020, 9:58am
1
I come back here because I am working blind (I cannot compile SimpleITK, this is drive me crazy, because I am running out of time). And until I solve that issue (working on that by days !!! unbelievable) I am trying to write code that import data from VTK into SimpleITK, and I wrote:
sitk::ImportImageFilter importer;
importer.SetSpacing(m_pDICOMReader->GetOutput()->GetSpacing());
importer.SetOrigin(m_pDICOMReader->GetOutput()->GetOrigin());
importer.SetSize(m_pDICOMReader->GetOutput()->GetScalarSize());
sitk::Image img = importer.Execute();
it is ok ? (m_pDICOMReader is vtkDICOMReader). I really need this code functional.
Thank you for your time !
dzenanz
(Dženan Zukić)
February 13, 2020, 1:23pm
2
You are missing the main thing, importer.SetImportPointer()
. I am not sure whether vtkDICOMReader
has direction, but if it does you might want to set that too.
2 Likes
blowekamp
(Bradley Lowekamp)
February 13, 2020, 1:37pm
3
The Doxygen for the SimpleITK ImportImageFilter is here:
https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1ImportImageFilter.html
While ITK’s class used SetImportPointer
the SimpleITK class used SetBuferAs...
where ...
is the pixel component type e.g. SetBufferAsFloat
for Images of float
.
2 Likes
flaviu2
(Flaviu)
February 14, 2020, 10:19am
4
vtkDICOMReader does not have direction feature … but in this case I should setup myself direction ?
dzenanz
(Dženan Zukić)
February 14, 2020, 1:14pm
5
Direction is identity by default, so you don’t need to set it up.
1 Like
flaviu2
(Flaviu)
February 14, 2020, 1:44pm
6
Thank you Dzenan for your time, you are kind !
flaviu2
(Flaviu)
February 14, 2020, 2:39pm
7
Please have patience with me. I come back because I have tried to use this example:
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "SimpleITK.h"
#include <stdlib.h>
#include <iostream>
This file has been truncated. show original
to import data from vtkImageData 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 !
blowekamp
(Bradley Lowekamp)
February 14, 2020, 2:44pm
8
The error indicates that size is invalid. So what is the value of size
in your code?
zivy
(Ziv Yaniv)
February 14, 2020, 2:59pm
10
Hello @flaviu2 ,
In your code the parameter to SetSize
should be the contents of nDim
. In ITK/SimpleITK the size of an image is the number of pixels/voxels per dimension.
2 Likes
flaviu2
(Flaviu)
February 14, 2020, 3:06pm
11
Great ! Seem to go, now I have to try the outcome, for the moment I have no error !!! I hope is ok … Now I stop the work for 24 hours, but I come back here with feedback ! @zivy & @blowekamp & @dzenanz Thank you !!!
Here is my new code that seem to go without errors:
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);
std::vector<unsigned int> size;
size.push_back((unsigned int)nDim[0]);
size.push_back((unsigned int)nDim[1]);
size.push_back((unsigned int)nDim[2]);
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());
}
delete[] in;
1 Like