<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
Hello,<br>
<br>
is there a way to read an vector image
(itk::Image<itk::Vector<float,3>,3>) with the python
wrapper and to convert it easily to a numpy array ?<br>
<br>
I tried using PyBuffer but it does not seem to work and I get the
following error:<br>
<br>
vectorType=itk.Vector[itk.F,3]<br>
fieldType=itk.Image[vectorType,3]<br>
readerType=itk.ImageFileReader[fieldType,3]<br>
reader=readerType.New()<br>
reader.SetFileName("file")<br>
reader.Update()<br>
image=reader.GetOutput()<br>
buf = itk.PyBuffer[imageType].GetArrayFromImage(image)<br>
<i><br>
</i><i>Traceback (most recent call last):</i><i><br>
</i><i> File "<stdin>", line 1, in <module></i><i><br>
</i><i>NameError: name 'imageType' is not defined</i><i><br>
</i><i>>>> buf =
itk.PyBuffer[fieldType].GetArrayFromImage(image)</i><i><br>
</i><i>Traceback (most recent call last):</i><i><br>
</i><i> File "<stdin>", line 1, in <module></i><i><br>
</i><i> File
"/home/mrohe/Librairies/ITK-4.9.0_wrap/build/Wrapping/Generators/Python/itkTemplate.py",
line 252, in __getitem__</i><i><br>
</i><i> (str(parameters), self.__name__))</i><i><br>
</i><i>KeyError: "itkTemplate : No template [<class
'itkImagePython.itkImageVF33'>] for the itk::PyBuffer class"</i><br>
<br>
<br>
What I do is to cast manually the image to the numpy array (see
below) with for loops (since I did not find any iterator on the
python wrapper). It works but is really slow and inefficient. There
must be a better way no ?<br>
<br>
for sx in range(sizeX):<br>
for sy in range(sizeY):<br>
for sz in range(sizeZ):<br>
vector=image.GetPixel([sx,sy,sz])<br>
data[sx,sy,sz,0]=vector[0]<br>
data[sx,sy,sz,1]=vector[1]<br>
data[sx,sy,sz,2]=vector[2]<br>
</body>
</html>