[Insight-users] size of image

robert tamburo robert.tamburo at gmail.com
Sat May 28 10:36:21 EDT 2011


image->GetLargestPossibleRegion().GetSize();   which is in your code:

  InputImageType::RegionType inputRegion =
           reader->GetOutput()->GetLargestPossibleRegion();

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



On Sat, May 28, 2011 at 10:30 AM, john smith <mkitkinsightuser at gmail.com>wrote:

> Hello,
>
> I am using ITK for my project and I have wrote the following code.Could
> somebody tell me how can I get the size of my image?
>
> Thanks in advance
>
>  typedef unsigned char        InputPixelType;
>   typedef unsigned char        OutputPixelType;
>
>   typedef itk::Image< InputPixelType,  3 >    InputImageType;
>   typedef itk::Image< OutputPixelType, 2 >    OutputImageType;
>
>    typedef itk::ImageFileReader< InputImageType  >  ReaderType;
>   typedef itk::ImageFileWriter< OutputImageType >  WriterType;
>
>   ReaderType::Pointer reader = ReaderType::New();
>   WriterType::Pointer writer = WriterType::New();
>
>   reader->SetFileName( fileName.toStdString()  );
>   writer->SetFileName( "2D.png" );
>
>
>   typedef itk::ExtractImageFilter< InputImageType, OutputImageType >
> FilterType;
>   FilterType::Pointer filter = FilterType::New();
>
>     reader->Update();
>   InputImageType::RegionType inputRegion =
>            reader->GetOutput()->GetLargestPossibleRegion();
>
>   InputImageType::SizeType size = inputRegion.GetSize();
>   size[2] = 0;
>
>   InputImageType::IndexType start = inputRegion.GetIndex();
>   const unsigned int sliceNumber = 89;
>    start[2] = sliceNumber;
>
>   InputImageType::RegionType desiredRegion;
>   desiredRegion.SetSize( size );
>   desiredRegion.SetIndex( start );
>
>   filter->SetExtractionRegion( desiredRegion );
>
>   filter->SetInput( reader->GetOutput() );
>   writer->SetInput( filter->GetOutput() );
>
>       try
>     {
>     writer->Update();
>     }
>     catch( itk::ExceptionObject & err )
>     {
>     std::cerr << "ExceptionObject caught !" << std::endl;
>     std::cerr << err << std::endl;
>     }
>
> _____________________________________
> 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.html
>
> 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/20110528/b31629ec/attachment.htm>


More information about the Insight-users mailing list