AW: [Insight-users] How to get one 2d image from 3d volume data?

Luis Ibanez luis . ibanez at kitware . com
Mon, 08 Dec 2003 11:26:45 -0500


Hi Jiang,


Here are four things that may be wrong with your code:


1) You put all the ITK pipeline inside a C function.

    How are you passing the input image ?
    Is this a global pointer  ?
    This is the first suspicious act in the code...


2) If you got an exception, PLEASE post the error
    message that is printed as result of the
    exception. That will help us to figure out
    what may be wrong with your code.

3) You are assigning

   DesiredPiece = filter->GetOutput();

   If you are accessing the image pointer "DesiredPiece"
   before calling

     filter->Update();

   the content of DesiredPiece will not be valid.

4) Please print out the variable "inputRegion" as soon
    as you get it from InputImage->GetLargestPossibleRegion()

    It may be possible that his region is not what you
    expect. (depending on how you acquired InputImage).

    By the same token, please print out the value of
    "desiredRegion" before you pass it to the Extract
    filter.



Please let us know what you find,



Thanks



   Luis


------------------
jiang wrote:

> Hi Luis,
> I copy the core code from Insight/Examples/IO/ImageReadExtractWrite.cxx to
> my application. However it doesn't work.
> The following is my code:
> void GetDesiredPiece()
> {
>   typedef signed short                    PixelType;
>   typedef itk::Image<PixelType, 2>        ImageType;
>   typedef itk::Image<PixelType, 3>		  ImageNDType;
> 
>   // Software Guide : BeginCodeSnippet
>   typedef itk::ExtractImageFilter< ImageNDType, ImageType > FilterType;
>   FilterType::Pointer filter = FilterType::New();
>   // Software Guide : EndCodeSnippet
> 
>   ImageNDType::RegionType inputRegion =
>            InputImage->GetLargestPossibleRegion();//InputImage is a
> ImageNDType Pointer
> 
>   ImageNDType::SizeType size = inputRegion.GetSize();
>   size[2] = 0;
> 
>   ImageNDType::IndexType start = inputRegion.GetIndex();
>   const unsigned int sliceNumber = 4;//The InputImage has more than 4 slices
>   start[2] = sliceNumber;
> 
>   ImageNDType::RegionType desiredRegion;
>   desiredRegion.SetSize(  size  );
>   desiredRegion.SetIndex( start );
> 
>   filter->SetExtractionRegion( desiredRegion );
> 
>   filter->SetInput( InputImage );
> 
>   DesiredPiece=filter->GetOutput();//DesiredPiece is a ImageType Pointer
> 
>   typedef itk::ImageFileWriter< ImageType >  WriterType;
>   WriterType::Pointer writer = WriterType::New();
>   writer->SetFileName( "extractPiece" );
>   writer->SetInput( filter->GetOutput() );
>   try
>     {
>     writer->Update();
>     }
>   catch( itk::ExceptionObject & err )
>     {
>     std::cout << "ExceptionObject caught !" << std::endl;
>     std::cout << err << std::endl;
> //    return -1;
>     }
> 
> }
> 
> When I run it, the DesiredPiece is always empty. And I try to write the
> output. It causes the Exception.
> Are there something wrong in my code?
> 
> Thank you very much!
> 
> 
> Chunyan
> 
> -----Ursprungliche Nachricht-----
> Von: Luis Ibanez [mailto:luis . ibanez at kitware . com]
> Gesendet: Freitag, 5. Dezember 2003 16:41
> An: jiang
> Cc: ITK
> Betreff: Re: [Insight-users] How to get one 2d image from 3d volume
> data?
> 
> 
> Hi Chunyan,
> 
> Please look at the itk::ExtractImageFilter
> http://www . itk . org/Insight/Doxygen/html/classitk_1_1ExtractImageFilter . html
> 
> an example on how to use this filter is available at
> 
> Insight/Examples/IO/
>                 ImageReadExtractWrite.cxx
> 
> You can actually use this demo application as a command
> line tool for extracting slices from a volume.
> 
> In your case, you are probably more interested in
> copy/pasting the core code from the example into your
> application.
> 
> 
> Regards,
> 
> 
>     Luis
> 
> 
> -----------------------------------------------
> jiang wrote:
> 
> 
>>Dear ITK-users,
>>I read a series of 2d image files to form a 3d volume. Now I want to get
> 
> one
> 
>>slice of those images from the volume pointer. How should I do?
>>The type of volume is:
>>  typedef itk::Image<PixelType, 3>		  ImageNDType;
>>  ImageNDType::Pointer volume;
>>
>>The 2d image type is:
>>  typedef itk::Image<PixelType, 2>        ImageType;
>>  ImageType::Pointer OnePiece.
>>
>>
>>Thank you very much!
>>
>>
>>Chunyan
>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users at itk . org
>>http://www . itk . org/mailman/listinfo/insight-users
>>
> 
> 
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>