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

Bradley Lowekamp blowekamp at mail.nih.gov
Thu Sep 26 11:40:38 EDT 2013


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/20130926/1b06d37b/attachment.htm>


More information about the Insight-users mailing list