[ITK-users] simpleitk Python ExtractImageFilter -- basic usage

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ITK-users] simpleitk Python ExtractImageFilter -- basic usage

Robert.Atwood@diamond.ac.uk
I'm sorry if I'm abit thick, but this doesn't work.
I tried to read documents and old mailing list entries, but I don't find an answer, just in the past someone with a similar problem wound up using CropImageFilter instead.


Can someone clarify why this doesn't work? I'd specifically LIKE to maintain the origin of the region as the origin of the original image.


  1 import SimpleITK as sitk
  2
  3
  4 rawimg = sitk.Image(50,60,70,sitk.sitkFloat32)
  5 newim=sitk.Extract(rawimg,(20,30,40),(0,0,0))



Traceback (most recent call last):
  File "./tryextract.py", line 12, in <module>
    newim=sitk.Extract(rawimg,(20,30,40),(0,0,0))
  File "/home/kny48981/.local/lib/python2.7/site-packages/SimpleITK/SimpleITK.py", line 27140, in Extract
    return _SimpleITK.Extract(*args, **kwargs)
RuntimeError: Exception thrown in SimpleITK Extract: /tmp/SimpleITK-build/ITK-prefix/include/ITK-4.13/itkExtractImageFilter.hxx:99:
itk::ERROR: ExtractImageFilter(0x7f7eb17d8e80): Extraction Region not consistent with output image
[kny48981@i12-ws011 pycircles]$ python ./tryextract.py  /dls/i12/data/2018/cm19662-3/tmp/bubble/onebub.tif -o /scratch/SSD/robert/onebub
Traceback (most recent call last):
  File "./tryextract.py", line 5, in <module>
    newim=sitk.Extract(rawimg,(20,30,40),(0,0,0))
  File "/home/kny48981/.local/lib/python2.7/site-packages/SimpleITK/SimpleITK.py", line 27140, in Extract
    return _SimpleITK.Extract(*args, **kwargs)
RuntimeError: Exception thrown in SimpleITK Extract: /tmp/SimpleITK-build/ITK-prefix/include/ITK-4.13/itkExtractImageFilter.hxx:99:
itk::ERROR: ExtractImageFilter(0x7f8287a9e020): Extraction Region not consistent with output image


But the output image should be getting created (returned)  by the filter?So how can it not be consistent???
 Or what's going on?
Especially since it worked fine in a previous program with 2d data.



I tried a bit harder and used the object interface, and compare 2d and 3d, and try to set the collapse strategy..

And it works in 2d but not in 3d, I really can't see why.

  1 import SimpleITK as sitk
  2
  3 rawimg2d = sitk.Image(50,60,sitk.sitkFloat32)
  4 print rawimg2d.GetDimension()
  5 extractor2d=sitk.ExtractImageFilter()
  6 extractor2d.SetSize((20,30))
  7 extractor2d.SetIndex((5,6))
  8 extractor2d.SetDirectionCollapseToStrategy(extractor2d.DIRECTIONCOLLAPSETOIDENTITY)
  9 print "strategy, ",extractor2d.GetDirectionCollapseToStrategy()
 10 newimg2d=extractor2d.Execute(rawimg2d)
 11
 12 print "Finished 2d extractor"
 13
 14 rawimg3d = sitk.Image(50,60,70,sitk.sitkFloat32)
 15 print rawimg3d.GetDimension()
 16 extractor3d=sitk.ExtractImageFilter()
 17 extractor3d.SetSize((20,30,40))
 18 extractor3d.SetIndex((5,6,7))
 19 extractor3d.SetDirectionCollapseToStrategy(extractor3d.DIRECTIONCOLLAPSETOIDENTITY)
 20 print "strategy, ",extractor3d.GetDirectionCollapseToStrategy()
 21 newimg3d=extractor3d.Execute(rawimg3d)
 22 print "Finished 3d extractor"
 23


python ./tryextract.py  /

2
strategy,  1
Finished 2d extractor
3
strategy,  1
Traceback (most recent call last):
  File "./tryextract.py", line 21, in <module>
    newimg3d=extractor3d.Execute(rawimg3d)
  File "/home/kny48981/.local/lib/python2.7/site-packages/SimpleITK/SimpleITK.py", line 27115, in Execute
    return _SimpleITK.ExtractImageFilter_Execute(self, *args)
RuntimeError: Exception thrown in SimpleITK ExtractImageFilter_Execute: /tmp/SimpleITK-build/ITK-prefix/include/ITK-4.13/itkExtractImageFilter.hxx:99:
itk::ERROR: ExtractImageFilter(0x7fbf77727bc0): Extraction Region not consistent with output image



--
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd.
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom

The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
________________________________
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.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
https://itk.org/mailman/listinfo/insight-users