[Insight-users] Writing 2D slice back to 3D image

Luis Ibanez luis . ibanez at kitware . com
Mon, 15 Dec 2003 23:47:13 -0500


Hi Radhika,

The reason why your previous program didn't work
correctly for copying the 2D slice back into the
3D volume is that you reused the "desiredRegion".

You use this region for defining the slice you want
to extract using the itk::ExtractImageFilter.
In this first use, the desired region must have
the third component of its size set to zero in
order to indicate to the filter that you Dwant a
reduction in dimensionality, from 3D to 2D.

When you reuse this region for the iterator, you
should set the third component size to = 1, instead
of keeping it to 0, as used for the ExtractImageFilter.

As far as the iterator are concerned, a region  with
one of its dimension sizes= 0 is an empty region,
this flags right away the "IsAtEnd()" condition.
The solution in your program is to set size[2] = 1;
just before declaring the iterator for the 3D image


something like:


   ImageType::RegionType inputRegion =
     readervolume->GetOutput()->GetLargestPossibleRegion();
   ImageType::SizeType size = inputRegion.GetSize();
   size[2] = 0;
   ImageType::IndexType start = inputRegion.GetIndex();
   ImageType::RegionType desiredRegion;
   desiredRegion.SetSize(  size  );

     start[2] = s;
     desiredRegion.SetIndex( start );
     extracter2D->SetExtractionRegion( desiredRegion );
     extracter2D->SetInput(readervolume->GetOutput());
     extracter2D->Update();
     ImageType2D::Pointer gs = extracter2D->GetOutput();


     size[2] = 1;                     // <<<<< ADD THIS
     desiredRegion.SetSize(  size  ); // <<<<< ADD THIS

     ImageType2D::RegionType newRegion=gs->GetLargestPossibleRegion();
     ImageType2D::SizeType size2D;
     ImageType2D::IndexType index2D;
     size2D[0] = size[0];
     size2D[1] = size[1];
     index2D[0] = 0;
     index2D[1] = 0;
     ConstIteratorType2D it2D( gs, newRegion );
     inputRegion.SetSize(size);
     inputRegion.SetIndex(start);
     IteratorType it3D( binimg3D, desiredRegion );
     it3D.GoToBegin();
     it2D.GoToBegin();
     while (!it3D.IsAtEnd() && !it2D.IsAtEnd())
       {
       it3D.Set(it2D.Get());
       ++it3D;
       ++it2D;
       }


Regards,


    Luis



--------------------------------
Radhika Sivaramakrishna wrote:

> Hi Luis,
> 
> Just to let you know that I was able to successfully modify the slice 
> iterator example in the Software guide to extract 2D slice and put back 
> in 3D
> 
> image. But just out of curiosity, I would still like to see why the 
> previous program I posted did not yield the correct result.
> 
> Radhika
> 
>  
> 
> -----------------------------------------------------
> 
> Confidentiality Notice.
> 
> This email message is for the sole use of the intended recipient(s) and 
> may contain confidential and privileged information. Any unauthorized 
> review, use, disclosure or distribution is prohibited. If you are not 
> the intended recipient, please contact the sender by reply email and 
> destroy all copies of the original message. If you are the intended 
> recipient, please be advised that the content of this message is subject 
> to access, review and disclosure by the sender's Email System Administrator.
>