[ITK-users] [ITK] Siemens 4d data

Sonia Pozzi sonia.pozzi89 at gmail.com
Sun Jul 30 13:09:56 EDT 2017


Dear Andras and Lambert,

here is the code I’m using. Every one of my time series contains the same slice for different times.

The problem is that it is importing the series one by one and it seems that it is not working in checking out which slice belong to the same time acquisition.
At the end my 4D volume has coordinates [x,y,t,z]. I also tried to switch t- and z-coordinates at the end of my simulation but then I have some problem in the resulting volume (I’m not able to  continuing working on it).
As you know I can’t share MRI data here, but if you are willing I could send you a small part of them to try to figure out together how to read them...
That would help me a lot.

Regards and thank you for your time,

Sonia

          nameGenerator -> SetDirectory( _dicomDirectory );
          ReaderType::Pointer reader = ReaderType::New();

          ShortImageType4D::Pointer image4D = ShortImageType4D::New();
          ShortImageType::Pointer image3D = ShortImageType::New();

          reader->SetImageIO(dicomIO);

          const std::string entry_id = "0018|1090 ";

          nameGenerator->AddSeriesRestriction(entry_id);


          typedef std::vector< std::string >    SeriesIdContainer;
          const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
          SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
          SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();

          typedef std::vector< std::string >   FileNamesContainer;

          // figure out how many time points there are based on number of series 
          unsigned int timepoints = 0;
          while (seriesItr != seriesEnd){
          timepoints++;
          seriesItr++;
          }
          std::cout << "Number of time points  : " << timepoints << std::endl;

          seriesItr = seriesUID.begin();
          std::cout << "Reading first image : " << std::endl;
          std::cout << seriesItr->c_str() << std::endl;

          std::string seriesIdentifier;
          seriesIdentifier = seriesItr->c_str();

          FileNamesContainer fileNames;
          fileNames = nameGenerator->GetFileNames(seriesIdentifier);
          FileNamesContainer::iterator fileiterator = fileNames.begin();


          std::cout<<"sono qui"<<seriesIdentifier<<std::endl;

          reader->SetFileNames(fileNames);

          try
          {
          reader->Update();
          }
          catch (itk::ExceptionObject &ex)
          {
          std::cout << ex << std::endl;
          }



          const ShortImageType::SpacingType& spacing3D = reader->GetOutput()->GetSpacing();
          std::cout << "Spacing 3D = " << spacing3D[0] << ", " << spacing3D[1] << ", " << spacing3D[2] << std::endl;
          const ShortImageType::PointType origin3D = reader->GetOutput()->GetOrigin();
          std::cout << "Origin  3D = " << origin3D[0] << ", " << origin3D[1] << ", " << origin3D[2] << std::endl;
          const ShortImageType::SizeType size3D = reader->GetOutput()->GetBufferedRegion().GetSize();

          ShortImageType4D::SpacingType spacing4D;
          ShortImageType4D::PointType origin4D;
          ShortImageType4D::SizeType size4D;

          for (int i = 0; i < 3; ++i){
          spacing4D[i] = spacing3D[i];
          origin4D[i] = origin3D[i];
          size4D[i] = size3D[i];
          }
 
          spacing4D[3] = 1;
          origin4D[3] = 0;
          size4D[3] = timepoints;

          ShortImageType4D::IndexType start4D;
          start4D.Fill(0);

          ShortImageType4D::RegionType region4D(start4D, size4D);

          std::cout << "Spacing 4D = " << spacing4D[0] << ", " << spacing4D[1] << ", " << spacing4D[2] << ", " << spacing4D[3] << std::endl;
          std::cout << "Size 4D = " << size4D[0] << ", " << size4D[1] << ", " << size4D[2] << ", " << size4D[3] << std::endl;
          image4D->SetRegions(region4D);
          image4D->SetSpacing(spacing4D);
          image4D->SetOrigin(origin4D);
          image4D->Allocate();

          seriesItr = seriesUID.begin();

          typedef itk::ImageRegionConstIterator< ShortImageType >  Iterator3D;
          typedef itk::ImageRegionIterator< ShortImageType4D >  Iterator4D;


          Iterator4D it4(image4D, image4D->GetBufferedRegion());
          it4.GoToBegin();


          unsigned short int idx = 0;
          while (seriesItr != seriesEnd){

          seriesIdentifier = seriesItr->c_str();
          std::cout << "Reading series " << std::endl;
          std::cout << seriesItr->c_str() << std::endl;

          fileNames = nameGenerator->GetFileNames(seriesIdentifier);

          for(unsigned int fni = 0; fni<fileNames.size(); fni++)
          {  std::cout<<"FN "<<fileNames[fni]<<std::endl;

            }


          reader->SetFileNames(fileNames);

          image3D = reader->GetOutput();
          image3D->SetRegions(reader->GetOutput()->GetRequestedRegion());
          image3D->CopyInformation(reader->GetOutput());
          image3D->Allocate();

          std::cout << "reading image volume " << idx << std::endl << std::endl;
          try
          {
          reader->Update();
          }
          catch (itk::ExceptionObject &ex)
          {
          std::cout << ex << std::endl;
          }

   
          Iterator3D it3(image3D, image3D->GetBufferedRegion());
          it3.GoToBegin();

          while (!it3.IsAtEnd())
          {
          it4.Set(it3.Get());
          ++it3;
          ++it4;
          }

          // increment iterator
          seriesItr++; 
          idx++;

          }

> On 29 Jul 2017, at 20:58, Andras Lasso <lasso at queensu.ca> wrote:
> 
> Finding out what DICOM fields to use for grouping frames is a complex topic. There is no universally accepted standard, the field(s) to use depend on scanner manufacturer, imaging modality, and imaging protocol.
>  
> You can have a look at the 4D image importer logic in 3D Slicer (what DICOM fields are considered, what heuristics are used for automatically detecting special cases, etc):
> https://github.com/fedorov/MultiVolumeImporter/blob/master/MultiVolumeImporterPlugin.py <https://github.com/fedorov/MultiVolumeImporter/blob/master/MultiVolumeImporterPlugin.py>
>  
> You may also consider using 3D Slicer for loading DICOM data and saving as a 4D nrrd file that you can then easily load into ITK. If you have any questions related to this then post it on https://discourse.slicer.org <https://discourse.slicer.org/>.
>  
> Andras
>   <>
> From: Community [mailto:community-bounces at itk.org] On Behalf Of Lambert Zijp
> Sent: Saturday, July 29, 2017 1:38 PM
> To: Sonia Pozzi <sonia.pozzi89 at gmail.com>
> Cc: Insight-users <insight-users at itk.org>
> Subject: Re: [ITK] [ITK-users] Siemens 4d data
>  
> Hi Sonia,
>  
> Apparently SeriesInstanceUID does not help; sounds familiar. Maybe FrameNumber, SeriesNumber or AcquisitionNumber? If not, sorting slices on slice coordinate and AcquisitionTime could be done as a last resort. If you post two slices with the same coordinate but belonging to different volumes, I will take  look at it.
>  
> Greetings, Lambert
>  
> On Sat, Jul 29, 2017 at 12:26 AM, Sonia Pozzi <sonia.pozzi89 at gmail.com <mailto:sonia.pozzi89 at gmail.com>> wrote:
> Hello,
> 
> I have a set of Siemens series. In each series there is the same slice for different times.
> I would like to be able to reconstruct in itk each single volume (a complete volume for every time step).
> It is a couple of week that I’m trying how to do that…
> I understood that I should use some tag, but I’m not sure about which and my code is not working.
> 
> Could you be so kind to give me a suggestion here?
> 
> My regards,
> 
> Sonia
> _____________________________________
> Powered by www.kitware.com <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com&data=02%7C01%7Classo%40queensu.ca%7Cb3ff832c055844c3723708d4d6a8952e%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636369466924361221&sdata=reUnVLyhbeksZSU3vfoYkbLsWGY00wLNMS8x06VkMW0%3D&reserved=0>
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fopensource%2Fopensource.html&data=02%7C01%7Classo%40queensu.ca%7Cb3ff832c055844c3723708d4d6a8952e%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636369466924361221&sdata=rktVpsgRtuqvnhg1mwUXcYWEnHpZvD4OVUJXYgfmfUE%3D&reserved=0>
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.kitware.com%2Fproducts%2Fprotraining.php&data=02%7C01%7Classo%40queensu.ca%7Cb3ff832c055844c3723708d4d6a8952e%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636369466924361221&sdata=NPImYVLXkps1zXFWNaMTXI1%2BlG3%2FrVljLn%2F8uvc9WxA%3D&reserved=0>
> 
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.itk.org%2FWiki%2FITK_FAQ&data=02%7C01%7Classo%40queensu.ca%7Cb3ff832c055844c3723708d4d6a8952e%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636369466924361221&sdata=TOa5cYIKt5uJHlNffUAGiVE%2FxoLeQ42gIVd3PtBJqS4%3D&reserved=0>
> 
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpublic.kitware.com%2Fmailman%2Flistinfo%2Finsight-users&data=02%7C01%7Classo%40queensu.ca%7Cb3ff832c055844c3723708d4d6a8952e%7Cd61ecb3b38b142d582c4efb2838b925c%7C1%7C0%7C636369466924361221&sdata=uZ%2F6Ap%2BSbMzWJ4WU8Bu11x4Oui8T8NNQn8vzevtAC6M%3D&reserved=0>
>  
> _____________________________________
> 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.php
> 
> 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://public.kitware.com/mailman/listinfo/insight-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20170730/1e7e57ec/attachment.html>


More information about the Insight-users mailing list