[Insight-users] how to change 2D ITK-images to 3D Image Volume

shiwei swingsw89 at 163.com
Fri Sep 27 23:59:17 EDT 2013


Hi,
Thank you for your help with the Filter,still, I run into some other problems.
My source file is below:


typedef itk::Image< unsigned char,  2 >   InputImageType;
typedef itk::Image< double, 2 >   ImageType2D;
typedef itk::Image< double, 3 >   ImageType3D;
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::JoinSeriesImageFilter<ImageType2D, ImageType3D> JoinSeriesImageFilterType;
typedef itk::CastImageFilter<InputImageType,ImageType2D>  ImageTypecast; 
  int main()
{


 ReaderType::Pointer reader = ReaderType::New();
 ImageTypecast::Pointer toReal = ImageTypecast::New();
 JoinSeriesImageFilterType::Pointer joinFilter = JoinSeriesImageFilterType::New();
 joinFilter->SetOrigin(0.0);
          joinFilter->SetSpacing(1.0);
 int slice;
char* Src="D:\\ITK_test\\joinseriesfilter\\bin\\liimage";
char* Des="D:\\ITK_test\\joinseriesfilter\\bin\\testfigure1";
char* Ipo="_cor.tif";
char* Ipr="GFP_";
char* filename = new char[100];
char* writenname=new char[100];
for(slice=3584;slice<3586;++slice)
{
filename[0] = '\0';
sprintf_s(filename,100,"%s\\%s%05d%s",Src,Ipr,slice,Ipo);
reader->SetFileName(filename);
try
{
reader->Update();
}
catch ( itk::ExceptionObject &err)
{
std::cout << "ExceptionObject caught !" << std::endl; 
std::cout << err << std::endl; 
return -1;
} 
toReal->SetInput( reader->GetOutput() );
toReal->Update();
std::cout<<toReal->GetOutput()->GetBufferedRegion()<<'\t';//test whether we can get input
joinFilter->SetInput(slice,toReal->GetOutput());
}
 try
{
joinFilter->Update();//when Update we 
}
 catch( itk::InvalidRequestedRegionError & err )
{
std::cout << err << std::endl;
}
return 0;
}




IT's quite simple code ,however ,when I debug it I run into a problem like this,


I don' know how this error came out ? Thank you!


shiwei








At 2013-09-26 23:40:38,"Bradley Lowekamp" <blowekamp at mail.nih.gov> wrote:
Hello,


What is the error you are getting? Is it runtime or compilation time?


Here is the internal execute method from SimpleITK, I hope it's straight forward enough for an example:


template <class TImageType>
Image JoinSeriesImageFilter::ExecuteInternal ( const std::vector<Image> &images )
{
  // Define the input and output image types
  typedef TImageType     InputImageType;
        
  //Define output image type
  typedef typename InputImageType::template Rebind<typename InputImageType::PixelType, InputImageType::ImageDimension+1>::Type OutputImageType;


  typedef itk::JoinSeriesImageFilter<InputImageType,  OutputImageType> FilterType;
  // Set up the ITK filter
  typename FilterType::Pointer filter = FilterType::New();


  for ( unsigned int i = 0; i < images.size(); ++i )
    {
    // Get the pointer to the ITK image contained in image1
    typename InputImageType::ConstPointer image = this->CastImageToITK<InputImageType>( images[i] );


    filter->SetInput( i, image );
    }


  filter->SetOrigin ( this->m_Origin );
  filter->SetSpacing ( this->m_Spacing );


  if (this->GetDebug())
     {
     std::cout << "Executing ITK filter:" << std::endl;
     std::cout << filter;
     }


  // Run the ITK filter and return the output as a SimpleITK image
  filter->Update();


  typename FilterType::OutputImageType *itkOutImage = filter->GetOutput();
  this->FixNonZeroIndex( itkOutImage );
  return Image( itkOutImage );
 }




Good luck,
Brad


On Sep 26, 2013, at 11:03 AM, shiwei <swingsw89 at 163.com> wrote:


Hi!
   I stil have a problem when using the "iitkJoinImageFilter".
  Here is the thing:
   typedef itk::Image< double, 2 >   ImageType2D;  // defying the Readertype,they are 2D slices
   typedef itk::Image< double,3 >    ImageType3D; // the 3D volume which I want to get from the JoinImageFilter


  As I read a series of 2D slices with a "for" loop,then after processing them , I use JoinImageFilter to get a 3D output, then I had a problem:


 typedef itk::JoinImageFilter<ImageType2D, ImageType3D> JoinImageFilterType;
 JoinImageFilterType::Pointer joinFilter = JoinImageFilterType::New();


  for(int slice=0;slice<10,slice++)
{
         .........read the 2D slice...........
         ..........processing............
        ...........2D output Image......
    joinFilter->SetInput(slice,outputImage);
}
 joinFilter->update;


But after I did this ,vs comes out an error says itk can't convert from 2D to 3D,  If it's convienient can you show me an example like this with the "iitkJoinImageFilter"? To show me how to make this right? Thank you! Also,if I want to test whether I get a proper 3D volume,what shall I do then? 


         






At 2013-09-25 14:23:27,shiwei <swingsw89 at 163.com> wrote:

Thank you very much! Brad!


                                         shiwei






At 2013-09-25 00:00:50,"Bradley Lowekamp" <blowekamp at mail.nih.gov> wrote:

Hello,


To join a series of 2D image into a 3D volume you can you the JoinImageFilter:
http://www.itk.org/Insight/Doxygen/html/classitk_1_1JoinImageFilter.html


The extract a 2D image from a 3D volume you can use the ExtractImageFilter:
http://www.itk.org/Doxygen/html/classitk_1_1ExtractImageFilter.html


To extract a 3D volume from a 3D volume there are a few filter:
http://www.itk.org/Doxygen/html/classitk_1_1ExtractImageFilter.html
http://www.itk.org/Doxygen/html/classitk_1_1RegionOfInterestImageFilter.html
http://www.itk.org/Doxygen/html/classitk_1_1CropImageFilter.html


Hope that helps,
Brad


On Sep 24, 2013, at 11:14 AM, shiwei <swingsw89 at 163.com> wrote:


Hi,all~
As I first read a 3D Image Volume slice by slice,then after processing each slice I need to change them to a 3D volume for further processing, However, I can't use itk::ImageSeriesReader for my pixeltype now is double and it takes to much time to write out the 2D image first.
       I wonder if there is a class to help me read the 2D slices directly to 3D volume just in the memory.Also, I still eager to know whether there is a class can direclty extract a part of 3D volume from a bigger one.Beacuse IF there is no way to deal with that ,I will have to change all the 2D images to 2D Array then combine them to 3D Array which I think may take a lot of time.
       Do you have any way to figure this out? Thank you all !


_____________________________________
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://www.itk.org/mailman/listinfo/insight-users










-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130928/1f3950bc/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1.jpg
Type: image/jpeg
Size: 36103 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130928/1f3950bc/attachment.jpg>


More information about the Insight-users mailing list