I’m sorry if I’m abit thick, but this doesn’t work.
This is the distributed SimpleITK – updated yesterday , in the Python 2.7 version on Linux
SimpleITK Version: 1.1.0 (ITK 4.13)
Compiled: Mar 26 2018 15:04:35
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 and in general it could be a 4-d (time-series) image as input too so I beleive ExtractImageFilter is the right choice? I have done it in C++ with ITK 3.xx before but now I’ve been converted to Python + Simple .
Bare minimum program that doesnt work as I expect. Creates a small image and then extract a sub-image that is even smaller. Also tried with startign index not equal to zero, i.e. (5,5,5) or (1,2,3) with the same result.
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. See below for some more code.
I tried a bit harder and used the object-oriented interface, and compare 2d and 3d, and try to set the collapse strategy as well, though I never had to set it before, (despite the documentation saying it cannot be run without setting it)
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