[Insight-users] Problems to read a vtk file using SimpleITK+Python
Ariel Hernán Curiale
curiale at gmail.com
Tue Aug 6 11:00:56 EDT 2013
Hi,
I create a simple example to show you the problem that I'm getting when I'm trying to read a vtk file. I'm using the last release of SimpleITK (SimpleITK-0.6.1) and python.
In this example, I create, write and read a simple image.
Here is the code:
-------------------------
import SimpleITK as sitk
import scipy as sc
dim = (100, 100)
origin = (0, 0)
spacing = (0.834496, 0.8223519)
img = sc.zeros(dim)
img[20:40, 20:40] = 1
img_sitk = sitk.GetImageFromArray(img)
img_sitk.SetOrigin(origin)
img_sitk.SetSpacing(spacing)
print img_sitk
sitk.Show(img_sitk)
sitk.WriteImage(img_sitk,"img.vtk")
im = sitk.ReadImage("img.vtk")
reader = sitk.ImageFileReader()
reader.SetFileName("img.vtk")
im2 = reader.Execute()
--------
The img_sitk seems to be created properly:
----
Image (0x7f9a95ff8550)
RTTI typeinfo: itk::Image<double, 2u>
Reference Count: 1
Modified Time: 3295
Debug: Off
Observers:
none
Source: (none)
Source output name: (none)
Release Data: Off
Data Released: False
Global Release Data: Off
PipelineMTime: 0
UpdateMTime: 0
RealTimeStamp: 0 seconds
LargestPossibleRegion:
Dimension: 2
Index: [0, 0]
Size: [100, 100]
BufferedRegion:
Dimension: 2
Index: [0, 0]
Size: [100, 100]
RequestedRegion:
Dimension: 2
Index: [0, 0]
Size: [100, 100]
Spacing: [0.834496, 0.822352]
Origin: [0, 0]
Direction:
1 0
0 1
IndexToPointMatrix:
0.834496 0
0 0.822352
PointToIndexMatrix:
1.19833 0
0 1.21602
Inverse Direction:
1 0
0 1
PixelContainer:
ImportImageContainer (0x7f9a960309b0)
RTTI typeinfo: itk::ImportImageContainer<unsigned long, double>
Reference Count: 1
Modified Time: 2866
Debug: Off
Observers:
none
Pointer: 0x7f9a95352200
Container manages memory: true
Size: 10000
Capacity: 10000
But when I try to read the image using sitk.ReadImage or sitk.ImageFileReader I'm getting this error:
----
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SimpleITK-0.6.1_g1387a-py2.7-macosx-10.7-x86_64.egg/SimpleITK.py", line 4371, in Execute
return _SimpleITK.ImageFileReader_Execute(self)
RuntimeError: Exception thrown in SimpleITK ImageFileReader_Execute: /Users/ariel/Applications/InsightToolkit-4.4.0/Modules/Core/Common/include/itkImageBase.hxx:189:
itk::ERROR: Image(0x7f9a95d9d640): A spacing of 0 is not allowed: Spacing is [1, 0]
----
It seems to be a bug but, I don't know if I'm doing something wrong.
Cheers,
__________________________________
| Ariel Hernán Curiale Ph.D Student
| ETSI Telecomunicación
| Universidad de Valladolid
| Campus Miguel Delibes
| 47011 Valladolid, Spain
| Phone: 983-423000 ext. 5590
| Web: www.curiale.com.ar
|_________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20130806/b0ca8cad/attachment.htm>
More information about the Insight-users
mailing list