[Insight-users] Using ExtraImageFilter via WrapITK
David Chen
dchen at mail.nih.gov
Mon Jul 25 13:23:13 EDT 2011
I've written a python script that takes in a volume and tries to extract a Y slice using the ExtractImageFilter via WrapITK. It keeps giving me a region error and I cannot figure out why.
Can anyone take a look at my script and its output and tell me what I'm doing wrong?
Here's the script:
> #!/usr/bin/env python
>
> import itk
> from sys import argv
>
> imageType = itk.Image[itk.UC, 3]
> readerType = itk.ImageFileReader[imageType]
> reader = readerType.New()
> reader.SetFileName( argv[1] )
>
> size = itk.size(reader)
> print "\nInput image size: ", size
>
> reader.UpdateOutputInformation()
> reader.UpdateLargestPossibleRegion()
> coronal = reader.GetOutput().GetLargestPossibleRegion()
>
> ycut = size.GetElement(1)/2
> coronal.SetIndex(1, ycut)
> coronal.SetSize(1, 0);
>
> extract = itk.ExtractImageFilter[itk.Image.UC3, itk.Image.UC2].New()
> extract.SetInput(reader.GetOutput())
>
>
> extract.SetDirectionCollapseToIdentity()
> extract.SetExtractionRegion(coronal)
> extract.UpdateOutputInformation()
>
> print "\nExtract's input image: ", extract.GetOutput()
> print "\nThe ExtractImageFilter: ", extract
> print "\nExtract's region: ", extract.GetExtractionRegion()
> print "\nSize of the extract's output: ", itk.size(extract.GetOutput())
>
> print "\nReader's region: ", reader.GetOutput().GetLargestPossibleRegion()
>
> print "\n"
>
> extract.Update()
> itk.write(extract.GetOutput(), "extract.png")
And here is its output:
> puget => ./itkextract.py ../Public/teapot.vtk
> Warning: Unknown parameter 'std::string' in template 'itk::MetaDataObject'
>
> Input image size: itkSize3 ([256, 256, 256])
>
> Extract's input image: Image (0x108d3f010)
> RTTI typeinfo: itk::Image<unsigned char, 2u>
> Reference Count: 2
> Modified Time: 203
> Debug: Off
> Observers:
> none
> Source: (0x108db78c0)
> Source output index: 0
> Release Data: Off
> Data Released: False
> Global Release Data: Off
> PipelineMTime: 200
> UpdateMTime: 0
> RealTimeStamp: 0 seconds
> LargestPossibleRegion:
> Dimension: 2
> Index: [0, 0]
> Size: [256, 256]
> BufferedRegion:
> Dimension: 2
> Index: [0, 0]
> Size: [0, 0]
> RequestedRegion:
> Dimension: 2
> Index: [0, 0]
> Size: [0, 0]
> Spacing: [1, 1.3095]
> Origin: [0, 0]
> Direction:
> 1 0
> 0 1
>
> IndexToPointMatrix:
> 1 0
> 0 1.3095
>
> PointToIndexMatrix:
> 1 0
> 0 0.76365
>
> PixelContainer:
> ImportImageContainer (0x10cc2bbc0)
> RTTI typeinfo: itk::ImportImageContainer<unsigned long, unsigned char>
> Reference Count: 1
> Modified Time: 190
> Debug: Off
> Observers:
> none
> Pointer: 0
> Container manages memory: true
> Size: 0
> Capacity: 0
>
>
> The ExtractImageFilter: ExtractImageFilter (0x108db78c0)
> RTTI typeinfo: itk::ExtractImageFilter<itk::Image<unsigned char, 3u>, itk::Image<unsigned char, 2u> >
> Reference Count: 1
> Modified Time: 200
> Debug: Off
> Observers:
> none
> Number Of Required Inputs: 1
> Number Of Required Outputs: 1
> Number Of Threads: 24
> ReleaseDataFlag: Off
> ReleaseDataBeforeUpdateFlag: Off
> Input 0: (0x108d1a090)
> Output 0: (0x108d3f010)
> AbortGenerateData: Off
> Progress: 0
> Multithreader:
> RTTI typeinfo: itk::MultiThreader
> Reference Count: 1
> Modified Time: 188
> Debug: Off
> Observers:
> none
> Thread Count: 24
> Global Maximum Number Of Threads: 128
> Global Default Number Of Threads: 24
> ExtractionRegion: ImageRegion (0x108db79c0)
> Dimension: 3
> Index: [0, 128, 0]
> Size: [256, 0, 256]
>
> OutputImageRegion: ImageRegion (0x108db79f8)
> Dimension: 2
> Index: [0, 0]
> Size: [256, 256]
>
> DirectionCollaspeStrategy: 1
>
>
> Extract's region: itkImageRegion3([0, 128, 0], [256, 0, 256])
>
> Size of the extract's output: itkSize2 ([256, 256])
>
> Reader's region: itkImageRegion3([0, 128, 0], [256, 0, 256])
>
>
> Traceback (most recent call last):
> File "./itkextract.py", line 39, in <module>
> extract.Update()
> RuntimeError: /nfs/Users/dave/pkg/sitk-build/ITK/Modules/Core/Common/src/itkDataObject.cxx:387:
> Requested region is (at least partially) outside the largest possible region.
Thank you for any help.
Dave
David T. Chen, PhD [Lockheed Martin contractor]
mailto:dchen at mail.nih.gov http://erie.nlm.nih.gov/~dave
phone:301.435.3264 iphone:301.524.3174
Office of High Performance Computing and Communications
National Library of Medicine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110725/8d11e3bc/attachment.htm>
More information about the Insight-users
mailing list