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

jiang jiang at TI . Uni-Trier . DE
Mon, 8 Dec 2003 17:12:44 +0100


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
>