[Insight-users] ITK to VTK Convertion Error

Abayiz abayiz at yahoo.com
Sat May 28 05:58:00 EDT 2011


Hello Luis, 

Thank you again for your reply. 

The followings are the code that I used to read the dicom folder. As you can see, the loader part is of VTK form, and then have been converted to ITK. The DTILoader function in the first part is correct, I'm sure of it, please don't be confused with that line. I tried to view the result before converting to ITK, and it seems correct. So I doubt the conversion makes the error. 

Here is the code:

******************************************

void DTI::LoadDICOM(char* firstFile, Vav::Data::DTIData *DTI, int type, int numSlices1)

{

    char* fileName = new char[255];

    fileName = firstFile;



    string path(firstFile);

    int slashLocation = path.find_last_of("/");

    DICOMLoader *loader;

    loader = new DICOMLoader( );

    int numSlices = loader -> getSignedLongTag(fileName, DcmTagKey(0x2001, 0x1018));

    int numFrames = loader -> getSignedLongTag(fileName, DcmTagKey(0x0028, 0x0008));

    loader -> DICOMLoader::dicomReader( fileName,2, numFrames, 0, 0, 0 );

    
    this->data_scalar = loader -> getOutput();

 }



Vav::Data::Scalar* DTILoader::GetInitialIntensities()

{

    return this->data_scalar;

}



ContentTree *DTILoader::LoadDataContentDWI(string address, int numDirections)

{

    vector<string> files(numDirections);

    std::string directionName;

    vector<string>::iterator it;

     it = files.begin();

    for(int i=0;i<numDirections; i++)

    {

        std::stringstream out;

        out << i;

        directionName = "Direction" + out.str();

        cout << directionName << endl ;

        files[i]= directionName;

        directionName.clear();

        directionName = "";

    }

    sort(files.begin(), files.end());

    ContentTree* ctree = new ContentTree();

    {

         string seriesUID = "Series1";

        string studyUID = "Study1";

        string patientID= "patient1";

        string description= "description";

        string volumeID = "";

         StudyItem* study = new StudyItem(studyUID, patientID, description);

           ctree->InsertItem(study);

        SerieItem* serie = new SerieItem(seriesUID, studyUID);

        study->AddSubItem(serie);



        for(int i= 0; i < files.size(); i++)

        {

            InstanceItem* instance = new InstanceItem(false, "x", files[i], seriesUID, studyUID, patientID, description);

            serie->AddSubItem(instance);

        }

    }



    return ctree;

}

/// Reading the slices ////////
Vav::Loader::DICOMLoader* fixedImageLoader = new Vav::Loader::DICOMLoader();
    Vav::Data::BaseData*    fixedImageData= new Vav::Data::BaseData();
    ContentTree *fixedImageTree;
    ContentItem* fixedImageItem;

   fixedImageTree=NULL;typedef itk::CastImageFilter< 
                        ImageType,
                        OutputImageType > CastFilterType;
 //  cout << strDirPath.toStdString() << endl;
    fixedImageTree = fixedImageLoader->LoadDataContent(argv[1]);

    fixedImageItem = fixedImageTree->GetFistItem()->GetFirstItem(); // first study first series
   
    /// LOAD DATA
    fixedImageData = fixedImageLoader->LoadData(fixedImageItem);
    vector<int> dimensionsFixed = fixedImageData->GetScalar()->GetDimensions();

    vector<double> SpacingFixed = fixedImageData->GetScalar()->GetSpacing();

    double* bndFixed = fixedImageData->GetScalar()->GetImageData()->GetBounds();

   VTK2ITKConnectorFilterType::Pointer VTK2ITKconnectorFixed = VTKImageToImageType::New();
   VTK2ITKconnectorFixed->SetInput( fixedImageData -> GetScalar() -> GetImageData()); //the input is short here
   VTK2ITKconnectorFixed->GetImporter()->Update();

//flip the read images
typedef itk::FlipImageFilter <ImageType>
          FlipImageFilterType;
 
  FlipImageFilterType::Pointer flipFilterFixed
          = FlipImageFilterType::New ();
  flipFilterFixed->SetInput(VTK2ITKconnectorFixed->GetOutput());
 
  itk::FixedArray<bool, 3> flipAxesFixed;
  flipAxesFixed[0] = false;
  flipAxesFixed[1] = true;
 
  flipFilterFixed->SetFlipAxes(flipAxesFixed);
  flipFilterFixed->Update();
*************************************************

Hope to receive your answer soon. 

With regards,
Abayiz

--- On Thu, 5/26/11, Luis Ibanez <luis.ibanez at kitware.com> wrote:

> From: Luis Ibanez <luis.ibanez at kitware.com>
> Subject: Re: [Insight-users] ITK to VTK Convertion Error
> To: "Abayiz" <abayiz at yahoo.com>
> Cc: "itk" <Insight-users at itk.org>
> Date: Thursday, May 26, 2011, 12:36 PM
> Hi Abayiz,
> 
> Thanks for sharing your images.
> 
> Can you please describe how you are using the class
> 
>                
>   itkGDCMSeriesFileNames
> 
> to produce the files names for these DICOM slices ?
> 
> It will be very useful to that the code snippet where
> you set up the SeriesFileNames, and pass the input
> to the ImageSeriesReader.
> 
> 
> It looks like something is wrong in that setup...
> 
> 
>     Thanks
> 
> 
>          Luis
> 
> 
> 
> ---------------------------------------------------------------------------
> On Tue, May 24, 2011 at 6:38 AM, Abayiz <abayiz at yahoo.com>
> wrote:
> > Hi Luis,
> >
> > Thank you again for your reply.
> >
> > The slices seem to be in a random order after
> conversion. But, not exactly random, since after each and
> every randomly ordered ten slices, the eleventh slice is
> seem to be in a correct manner. For instance, the correct
> first slice goes to the eleventh slice after conversion, the
> correct second slice goes to 22th,etc, between which other
> random slices are placed.
> >
> > I actually added some images of this problem in my
> previous email yesterday, but not sent successfully due to
> the attachment size limit.
> >
> > Hope this could be helpful to get your suggestions
> again. Thank you.
> >
> > Best,
> > Abayiz
> >
> > --- On Sun, 5/22/11, Luis Ibanez <luis.ibanez at kitware.com>
> wrote:
> >
> >> From: Luis Ibanez <luis.ibanez at kitware.com>
> >> Subject: Re: [Insight-users] ITK to VTK Convertion
> Error
> >> To: "Abayiz" <abayiz at yahoo.com>
> >> Cc: insight-users at itk.org
> >> Date: Sunday, May 22, 2011, 5:46 PM
> >> Hi Abayiz,
> >>
> >> What *exactly* is different about the slices
> >> sequence when you convert from VTK to ITK ?
> >>
> >> Are they in random order ?
> >>
> >> Are they up-side down ?
> >> if so, is this along Z ? Y ?
> >>
> >>
> >> Please be more specific.
> >> or provide a screenshot.
> >>
> >>     Thanks
> >>
> >>
> >>            Luis
> >>
> >>
> >> -------------------------------------------
> >> On Sun, May 22, 2011 at 11:27 AM, Abayiz <abayiz at yahoo.com>
> >> wrote:
> >> > Hi Luis,
> >> >
> >> > Thank you very much for your answer.
> >> >
> >> > The problem is, if I use VTK to load dicom,
> and view
> >> it also using VTK, everything is fine. But after I
> converted
> >> it to ITK, then the sequence problem comes.
>  after
> >> conversion from VTK to ITK, the dicom slices are
> totally not
> >> in the correct sequence. Any suggestions?
> >> >
> >> > Thanks again.
> >> >
> >> > Abayiz
> >> >
> >> > --- On Sat, 5/21/11, Luis Ibanez <luis.ibanez at kitware.com>
> >> wrote:
> >> >
> >> >> From: Luis Ibanez <luis.ibanez at kitware.com>
> >> >> Subject: Re: [Insight-users] ITK to VTK
> Convertion
> >> Error
> >> >> To: "Abayiz" <abayiz at yahoo.com>
> >> >> Cc: insight-users at itk.org
> >> >> Date: Saturday, May 21, 2011, 1:08 PM
> >> >> Hi Abayiz,
> >> >>
> >> >>
> >> >> Can you describe the distortion ?
> >> >>
> >> >> Maybe post a screenshot ?
> >> >>
> >> >> Note that VTK images do not have
> >> >> a explicit representation of
> Orientation,
> >> >> so the information about the DICOM
> >> >> direction matrix gets lost when you use
> >> >> VTK for reading the DICOM images.
> >> >>
> >> >> You may find better to use the ITK GDCM
> >> >> reader in order to load the DICOM
> images.
> >> >>
> >> >>
> >> >>      Luis
> >> >>
> >> >>
> >> >> ---------------------------
> >> >> On Fri, May 20, 2011 at 10:03 AM, Abayiz
> <abayiz at yahoo.com>
> >> >> wrote:
> >> >> > Hello all,
> >> >> >
> >> >> > I am using a vtk-based dicom loader
> to load
> >> dicom
> >> >> series, and then use ITK to perform
> registration.
> >> But I
> >> >> found that when I try to convert from VTK
> to ITK,
> >> it is not
> >> >> working correctly, i.e., the dicom file
> orders
> >> are
> >> >> distorted, not the same as before
> conversion.
> >> >> >
> >> >> > I doubt itkVTKImagetoImageFilter is
> not
> >> working quite
> >> >> well with dicom files, since the same
> files can be
> >> read
> >> >> quite well using only itk-based loader.
> Am I
> >> right? How can
> >> >> I work this out?
> >> >> >
> >> >> > Many thanks in advance!
> >> >> >
> >> >> > Abayiz
> >> >> >
> _____________________________________
> >> >> > Powered by www.kitware.com
> >> >> >
> >> >> > Visit other Kitware open-source
> projects at
> >> >> > http://www.kitware.com/opensource/opensource.html
> >> >> >
> >> >> > Kitware offers ITK Training Courses,
> for
> >> more
> >> >> information visit:
> >> >> > http://www.kitware.com/products/protraining.html
> >> >> >
> >> >> > Please keep messages on-topic and
> check the
> >> ITK FAQ
> >> >> at:
> >> >> > http://www.itk.org/Wiki/ITK_FAQ
> >> >> >
> >> >> > Follow this link to
> subscribe/unsubscribe:
> >> >> > http://www.itk.org/mailman/listinfo/insight-users
> >> >> >
> >> >>
> >> >
> >> >
> >>
> >
> 


More information about the Insight-users mailing list