[ITK-users] simpleitk + python + vector type in sitk.mirrorpad args?

Robert.Atwood at diamond.ac.uk Robert.Atwood at diamond.ac.uk
Mon Nov 28 09:11:13 EST 2016


Thanks! 

D'oh!  , I somehow thought you had to use np.int## , I missed that it was possible to use just  'int' ! (after trying np.uint32, np.uint16 ... ) 

 



-----Original Message-----
From: Lowekamp, Bradley (NIH/NLM/LHC) [C] [mailto:blowekamp at mail.nih.gov] 
Sent: Monday, November 28, 2016 2:08 PM
To: Atwood, Robert (DLSLtd,RAL,SCI)
Cc: insight-users at itk.org
Subject: Re: [ITK-users] simpleitk + python + vector type in sitk.mirrorpad args?

Hello,

It looks like there is rightfully so no implicit conversion from numpy.int32 to “unsigned int” for value in tuples.


The following worked for me:

 padim=sitk.MirrorPad(medim,padextra.astype(int),padtop.astype(int))

and so does the following:

padim=sitk.MirrorPad(medim,padextra.astype(np.int),padtop.astype(np.int))

Here is an example for manual padding for FFTs:
https://github.com/SimpleITK/SimpleITK/blob/master/Examples/Python/FFTConvolution.py


HTH,
Brad

> On Nov 28, 2016, at 8:46 AM, Robert.Atwood at diamond.ac.uk wrote:
> 
> Hi,
> I just can't get this to work, I've tried any permutation I can think of. 
> I want to pad an array up to a calculated value on all dimensions. The calculation is easy to do in vectors with numpy , but whatever I try to do the mirrorpad function will not accept the data type. 
> 
> 
> Fsize is the array size and padsize is the  desired size in all 
> dimensions. The calculation produces initially a floating point number The line in comment # works, but I can't find a simple way to get the calculated output into a type that the function accepts.
> So my question :
> 
>  1. is there a more integrated  way to make the image fit the requirements of the FFT filter, because that's what all this is in aid of.
>  2. if this is the best way to do it, how do I make the function accept the dimension vector??
> 
> 
> Thanks! 
> 
> The error is as follows: 
> 
> _____________________________
> 
> Traceback (most recent call last):
>  File "/home/kny48981/progs/segment_sitk/trysitkmask.py", line 92, in <module>
>    padim=sitk.MirrorPad(medim,padextratup,padtoptup)
>  File "/home/kny48981/.local/lib/python2.7/site-packages/SimpleITK/SimpleITK.py", line 35916, in MirrorPad
>    return _SimpleITK.MirrorPad(*args, **kwargs)
> TypeError: in method 'MirrorPad', argument 2 of type 'std::vector< unsigned int,std::allocator< unsigned int > > const &'
> 
> _____________________
> 
> 
> Complete reproducer with dummy image: (full output below)
> 
> 
> reproducer.py
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
> import SimpleITK as sitk
> import numpy as np
> 
> 
> 
> medim=sitk.Image(120,122,135,sitk.sitkFloat32)
> 
> fsize=np.array(medim.GetSize())
> fctr=fsize/2.0
> 
> padsize=(256,256,256)
> 
> padextra=(((padsize-fsize)/2.0)).astype(np.int32)
> 
> print "fsize=",fsize
> print "padsize=",padsize
> print"padextra=", padextra
> print type(padextra)
> padfix = padsize - fsize - padextra - padextra print "padfix",padfix 
> padtop=(padextra + padfix).astype(np.int32)
> 
> 
> padextratup=tuple(padextra)
> padtoptup=tuple(padtop)
> 
> #padextratup=(125,125,100)
> 
> print type(padtoptup)
> print padtoptup
> print type(padtoptup[0])
> print type(padtoptup[1])
> print type(padtoptup[2])
> 
> print type(padextratup)
> print padextratup
> print type(padextratup[0])
> print type(padextratup[1])
> print type(padextratup[2])
> 
> 
> padim=sitk.MirrorPad(medim,padextratup,padtoptup)
> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> Output: 
> 
> python ./reproducer.py
> fsize= [120 122 135]
> padsize= (256, 256, 256)
> padextra= [68 67 60]
> <type 'numpy.ndarray'>
> padfix [0 0 1]
> <type 'tuple'>
> (68, 67, 61)
> <type 'numpy.int32'>
> <type 'numpy.int32'>
> <type 'numpy.int32'>
> <type 'tuple'>
> (68, 67, 60)
> <type 'numpy.int32'>
> <type 'numpy.int32'>
> <type 'numpy.int32'>
> Traceback (most recent call last):
>  File "./reproducer.py", line 42, in <module>
>    padim=sitk.MirrorPad(medim,padextratup,padtoptup)
>  File "/home/kny48981/.local/lib/python2.7/site-packages/SimpleITK/SimpleITK.py", line 35916, in MirrorPad
>    return _SimpleITK.MirrorPad(*args, **kwargs)
> TypeError: in method 'MirrorPad', argument 2 of type 'std::vector< unsigned int,std::allocator< unsigned int > > const &'
> [kny48981 at i12-ws011 testseg_sitk]$
> __________________________________
> 
> 
> --
> 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
> 
> _____________________________________
> 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:
> http://public.kitware.com/mailman/listinfo/insight-users


-- 
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


More information about the Insight-users mailing list