[ITK-users] [ITK] ITK PyBuffer get physical point coordinates

D'Isidoro Fabio fisidoro at ethz.ch
Tue May 2 11:20:48 EDT 2017


Hi Francois,

It works with your commands, the difference being the use of:

itk.GetArrayFromImage(source)

in your version, instead of:

itk.PyBuffer[ImageType].GetArrayFromImage(source)

in my version.

May you explain me the difference, and why using PyBuffer does not work for this case?

Also, when using VectorImage I get the error “No module named 'ITKQuadEdgeMeshPython'”. This is the only module that failed in my ITK Python build. Is this a known bug or it was just for my build?

Thank you!

Fabio.
From: Francois Budin [mailto:francois.budin at kitware.com]
Sent: Freitag, 28. April 2017 23:12
To: D'Isidoro Fabio <fisidoro at ethz.ch>
Cc: Lowekamp, Bradley (NIH/NLM/LHC) [C] <blowekamp at mail.nih.gov>; insight-users at itk.org
Subject: Re: [ITK-users] [ITK] ITK PyBuffer get physical point coordinates

Hello Fabio,
I was able to use this filter in Python. Here is the commands I typed:
In [14]: ImageType=itk.Image[itk.Vector[itk.F,2],2]

In [15]: source=itk.PhysicalPointImageSource[ImageType].New()

In [16]: source.SetSize([5,5])

In [17]: source.SetOrigin([0,0])

In [18]: source.SetSpacing([.5,.5])

In [19]: source.Update()

In [20]: itk.GetArrayFromImage(source)
Out[20]:
itkndarray([[[ 0. ,  0. ],
        [ 0.5,  0. ],
        [ 1. ,  0. ],
        [ 1.5,  0. ],
        [ 2. ,  0. ]],

       [[ 0. ,  0.5],
        [ 0.5,  0.5],
        [ 1. ,  0.5],
        [ 1.5,  0.5],
        [ 2. ,  0.5]],

       [[ 0. ,  1. ],
        [ 0.5,  1. ],
        [ 1. ,  1. ],
        [ 1.5,  1. ],
        [ 2. ,  1. ]],

       [[ 0. ,  1.5],
        [ 0.5,  1.5],
        [ 1. ,  1.5],
        [ 1.5,  1.5],
        [ 2. ,  1.5]],

       [[ 0. ,  2. ],
        [ 0.5,  2. ],
        [ 1. ,  2. ],
        [ 1.5,  2. ],
        [ 2. ,  2. ]]], dtype=float32)
It also worked with VectorImages:

In [22]: ImageType=itk.VectorImage[itk.F,2]

In [23]: source=itk.PhysicalPointImageSource[ImageType].New()

In [24]: source.SetOrigin([0,0])

In [25]: source.SetSize([5,5])

In [26]: source.SetSpacing([.5,.5])

In [27]: source.Update()

In [28]: itk.GetArrayFromImage(source)

To answer your questions:
1) This filter is only wrapped over image of vectors and vector images. You can have the list of types that are available in Python with itk.PhysicalPointImageSource.GetTypes()
2) You may have a version of ITK Python for which VectorImage is not wrapped for PyBuffer. You can try to update your ITK Python [1]
Hope this helps,
Francois

[1] https://github.com/InsightSoftwareConsortium/ITKPythonPackage

On Fri, Apr 28, 2017 at 12:05 PM, D'Isidoro Fabio <fisidoro at ethz.ch<mailto:fisidoro at ethz.ch>> wrote:
Thank you for your reply.


1)     I have tried as a first step the following:

DRRPhy = itk.PhysicalPointImageSource[itk.Image[itk.Point[itk.F, Dimension], Dimension]].New()

But I get the error:

KeyError: "itkTemplate : No template (<class 'itkPointPython.itkPointF3'>, 3) for the itk::Image class"

So I guess I can’t generate an image with itk.Points as PixelType. Therefore I chose to use a VectorImage as ImageType in Input to the PhysicalPointImageSource.

sourceImage = itk.PhysicalPointImageSource[itk.VectorImage[itk.F, Dimension]].New()
sourceImage.SetSize(size)
sourceImage.SetSpacing(spacing)
sourceImage.SetOrigin(origin)
#DRRPhy.SetIndex(start) it does not work, how to set the start index?
DRRPhy.SetDirection(direction)


2)     However, using PyBuffer to get a numpy array form that does not work:

sourceImageArray = itk. PyBuffer[ImageType].GetArrayFromImage(sourceImage)

I get the error:

AttributeError: 'itkPhysicalPointImageSourceVIF3' object has no attribute 'GetLargestPossibleRegion'


Am I doing the right thing in point 1) ?
How could I solve point 2) ?

Thank you !

Fabio.

From: Lowekamp, Bradley (NIH/NLM/LHC) [C] [mailto:blowekamp at mail.nih.gov<mailto:blowekamp at mail.nih.gov>]
Sent: Donnerstag, 27. April 2017 23:16
To: D'Isidoro Fabio <fisidoro at ethz.ch<mailto:fisidoro at ethz.ch>>
Cc: insight-users at itk.org<mailto:insight-users at itk.org>
Subject: Re: [ITK] [ITK-users] ITK PyBuffer get physical point coordinates

Hi!

You can generate an image of the physical locations of each pixel with the PhysicalPointImageSource filter:
https://itk.org/Doxygen/html/classitk_1_1PhysicalPointImageSource.html

Very recently added is the SetReferenceImage, which can be use to copy the meta data from one image to the parameters of this filter. If your version is not super recent then you can manually set the Size, Spacing, Origin, Direction and StartIndex.

After you generate the point image you should be able to convert to with the same method.

HTH,
Brad


On Apr 27, 2017, at 4:58 PM, D'Isidoro Fabio <fisidoro at ethz.ch<mailto:fisidoro at ethz.ch>> wrote:

Hallo,

I know it’s possible to get a numpy array of an itk image with:

itk.PyBuffer[ImageType].GetArrayFromImage(Image)

Is it by any chance also possible to obtain a (flattended) numpy array of the physical coordinates of the image pixels too?

Thank you!

_____________________________________
Powered by www.kitware.com<http://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:
http://public.kitware.com/mailman/listinfo/insight-users
_______________________________________________
Community mailing list
Community at itk.org<mailto:Community at itk.org>
http://public.kitware.com/mailman/listinfo/community


_____________________________________
Powered by www.kitware.com<http://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:
http://public.kitware.com/mailman/listinfo/insight-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20170502/c89413bf/attachment.html>


More information about the Insight-users mailing list