[Insight-users] 2D Slice to 3D Volume

Dário Oliveira dariodisk at gmail.com
Wed Oct 3 21:33:25 EDT 2007


Luis,

I couldn't manage to make this code work properly. So, I created two
functions (SetSlice and GetSlice) which implements that using pixels
iterators. Now it works just fine.

I'm copying the code here, in case someone has the same problem. Anyway,
thanks!
**
*

typedef* itk::Image<*unsigned* *char*, 3> *BinImageType*;

*typedef* itk::Image<*unsigned* *char*, 2> BinImage2DType;

BinImageType::Pointer *setSlice*(BinImageType::Pointer volume,
BinImage2DType::Pointer slice, *short* i)

{

BinImageType::RegionType inputRegion = volume->GetLargestPossibleRegion();

BinImageType::IndexType start = inputRegion.GetIndex();

//const unsigned int sliceNumber = atoi( argv[3] );

start[2] = i;

BinImageType::SizeType size = inputRegion.GetSize();

//int numSlices = size[2];

size[2] = 0;

*typedef* itk::ImageRegionIterator< BinImageType > Iterator3D;

*typedef* itk::ImageRegionConstIterator< BinImage2DType > Iterator2D;

Iterator3D it3( volume, volume->GetBufferedRegion() );

it3.GoToBegin();

Image2DType::RegionType region;

region = slice->GetBufferedRegion();

Iterator2D it2( slice, region );

it2.GoToBegin();

it3.SetIndex(start);

*while*( !it2.IsAtEnd() )

{

it3.Set( it2.Get() );

++it2;

++it3;

}

*return* volume;

}

BinImage2DType::Pointer *getSlice*(BinImageType::Pointer image, *short* i)

{

*typedef* itk::ExtractImageFilter< BinImageType, BinImage2DType > FilterType
;

FilterType::Pointer filter = FilterType::New();

//std::cout << "Entrou1" << std::endl;;

image->Update();

filter->SetInput(image);

BinImageType::RegionType inputRegion = image->GetLargestPossibleRegion();

BinImageType::SizeType size = inputRegion.GetSize();

//int numSlices = size[2];

size[2] = 0;

//std::cout << "Entrou2" << std::endl;;

BinImageType::IndexType start = inputRegion.GetIndex();

//const unsigned int sliceNumber = atoi( argv[3] );

BinImageType::RegionType desiredRegion;

desiredRegion.SetSize( size );

start[2] = i;

desiredRegion.SetIndex( start );

filter->SetExtractionRegion( desiredRegion );

filter->*Update*();

*return* filter->GetOutput();

}

Thank you.

Dário.


2007/9/13, Luis Ibanez <luis.ibanez at kitware.com>:
>
>
> Hi Dario,
>
> I'm confused about your last email.
>
> You said:
>
> > When I see the filterP->getOutput() the result is exactly the same as
> > the filterP Input and Destination (which are the same image). And the
> > processing in the slice certainly change the image.
>
>
> Do you mean that now the filter works for you ?
> or is still not pasting the slice in the destination location ?
>
>
>    Please let us know,
>
>
>
>       Thanks
>
>
>          Luis
>
>
>
> ---------------------
> Dário Oliveira wrote:
> > Luis,
> >
> > Just after I sent the email, I managed to run it with no errors, but I
> > can't have the right resulting image anyway. Here is the code:
> >
> > *typedef* itk::CastImageFilter < 2D ImageType, 3DImageType >
> FilterTypeCA;
> > FilterTypeCA::Pointer filterCast = FilterTypeCA::New();
> >
> > *typedef* itk::PasteImageFilter< 3D ImageType, 3DImageType, 3DImageType
> >  > FilterTypeP;
> > FilterTypeP::Pointer filterP = FilterTypeP::New();
> >
> > 3DImageType::RegionType outputRegion =
> image->GetLargestPossibleRegion();
> > 3DImageType::SizeType size2 = outputRegion.GetSize();
> > 3DImageType::IndexType start = outputRegion.GetIndex();
> > size2[2] = 1;
> > outputRegion.SetSize ( size2 );
> >
> > filterP->
> >
> > SetDestinationImage(image);
> > filterP->SetInput(image);
> >
> > *for* (*int* i=0; i<numSlices; i++)
> > {
> >  {some processing using the ith slice}
> >  start[2] = i;
> >  filter2D->* Update*();
> >  filterCast-> SetInput(filter2D->GetOutput());
> >  filterCast->* Update*();
> >   outputRegion.SetIndex( start );
> >  outputRegion = filterCast->GetOutput()->GetRequestedRegion();
> >  filterP->SetSourceImage(filterCast-> GetOutput ());
> >  filterP->SetDestinationIndex(start);
> >  filterP->SetSourceRegion (outputRegion);
> >  filterP->*Update *();
> > }
> >
> > When I see the filterP->getOutput() the result is exactly the same as
> > the filterP Input and Destination (which are the same image). And the
> > processing in the slice certainly change the image.
> >
> > Thank you again,
> >
> > Dário Oliveira.
> >
> > 2007/9/8, Dário Oliveira <dariodisk at gmail.com
> > <mailto:dariodisk at gmail.com>>:
> >
> >     Hi Luis,
> >
> >     thank you for your reply.
> >
> >     Yes, I'm using the PasteImageFilter and I've tried two different
> >     approaches:
> >
> >     1. To define the filter with an 2D image as source and a 3D image as
> >     the other input, just like that:
> >     *
> >     typedef* itk::PasteImageFilter< 3DImageType , 2DImageType,
> >     3DImageType > FilterTypeP ;
> >     FilterTypeP::Pointer filterP = FilterTypeP ::New();
> >
> >     filterP->
> >
> >     SetDestinationImage(image3D);
> >     filterP->SetInput(image3D);
> >
> >     *for* (*int* i=0; i<numSlices; i++)
> >     {
> >      {some processing using the ith slice}
> >      filterP->SetSourceImage(filter2D->GetOutput());
> >      filterP-> SetDestinationIndex(start);
> >      filterP->SetSourceRegion(filter2D->
> >     GetOutput()->GetLargestPossibleRegion());
> >      filterP->*Update*();
> >     }
> >     In that approach I got a compile error.
> >
> >     2. So I changed my approach using a cast image filter, like that:
> >
> >     *typedef* itk::CastImageFilter < 2D ImageType, 3DImageType >
> >     FilterTypeCA;
> >     FilterTypeCA::Pointer filterCast = FilterTypeCA::New();
> >
> >     *typedef* itk::PasteImageFilter< 3D ImageType, 3DImageType,
> >     3DImageType > FilterTypeP;
> >     FilterTypeP::Pointer filterP = FilterTypeP::New();
> >
> >     3DImageType::RegionType outputRegion =
> >     image->GetLargestPossibleRegion();
> >     3DImageType::SizeType size2 = outputRegion.GetSize();
> >     3DImageType::IndexType start = outputRegion.GetIndex();
> >     size2[2] = 1;
> >     outputRegion.SetSize ( size2 );
> >
> >     filterP->
> >
> >     SetDestinationImage(image);
> >     filterP->SetInput(image);
> >
> >     *for* (*int* i=0; i<numSlices; i++)
> >     {
> >      {some processing using the ith slice}
> >      start[2] = i;
> >      filter2D->*Update*();
> >      filterCast-> SetInput(filter2D->GetOutput());
> >      filterCast->* Update*();
> >      outputRegion = filterCast->GetOutput()->GetLargestPossibleRegion();
> >       outputRegion.SetIndex( start );
> >      filterP->SetSourceImage(filterCast->GetOutput ());
> >      filterP->SetDestinationIndex(start);
> >      filterP->SetSourceRegion (outputRegion);
> >      filterP->*Update*();
> >     }
> >
> >     In this case I got a runtime error in "filterP->*Update*();"
> >
> >     I've just started to work with ITK, so I'm probably making
> >     some silly mistake.
> >
> >     Thank you!
> >
> >     Dário Olivera.
> >
> >     2007/9/8, Luis Ibanez <luis.ibanez at kitware.com
> >     <mailto:luis.ibanez at kitware.com>>:
> >
> >
> >
> >         Hi Dario,
> >
> >         1) Are you using the "PasteImageFilter" ?
> >
> http://www.itk.org/Insight/Doxygen/html/classitk_1_1PasteImageFilter.html
> >
> >
> >         2) When you say that "it doesn't seem to work" ?
> >            Do you mean that
> >
> >            a) It doesn't compile ?
> >            b) It doesn't link ?
> >            c) It produces a segmentation fault at run time ?
> >            d) It throws an exception at run time ?
> >            e) It produces an image that when you visualize
> >               doesn't have the content that you expect ?
> >
> >
> >         3) Could you post to the list the minimal example of your code ?
> >
> >
> >
> >            Thanks
> >
> >
> >               Luis
> >
> >
> >
> >         -----------------------
> >         Dário Oliveira wrote:
> >>  Hi friends,
> >>
> >>  I'm having trouble to paste (actually replace) a processed 2D
> >         slice into
> >>  its original volume. I've read some previous itk-users email
> >         in the
> >>  mailing list, but I still couldn't manage to suceed. Is there
> >         any simple
> >>  way to perfom this task?
> >>
> >>  I'm trying to cast the processed 2D image to a 3D one, and get
> >         its 3D
> >>  region to paste into the original 3D volume, but it doesn't
> >         seem to work.
> >>
> >>  Any help will be very apreciated,
> >>
> >>  Regards
> >>  --
> >>  Dário Oliveira
> >>
> >>
> >>
> >
> ------------------------------------------------------------------------
> >
> >>
> >>  _______________________________________________
> >>  Insight-users mailing list
> >>  Insight-users at itk.org <mailto:Insight-users at itk.org>
> >>  http://www.itk.org/mailman/listinfo/insight-users
> >
> >
> >
> >
> >     --
> >     Dário Oliveira
> >
> >
> >
> >
> > --
> > Dário Oliveira
>



-- 
Dário Oliveira
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20071003/9fc71fd3/attachment-0001.htm


More information about the Insight-users mailing list