[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:39:09 EST 2016


Ok, I was trying to avoid having to build it ;) padding to a 2^n is probably going to work ok now that your advice has solved my problem.


I was implementing a fft-high-pass filter because it works really well in ImageJ for the particular issues we have ..  but is better done in proper 3d and I know ITK could do it

-- Is there a simple equivalent module as the 'FFT bandpass' in ImageJ but for 2/3(4?)  d ? Creating the filter function is another annoyance for which I have a solution but it's not very general. 


(PS> I did get  it to work if I manually set the values to a known amount  ... as in the commented line of the code #padextratup=(125,125,100) )



-----Original Message-----
From: Lowekamp, Bradley (NIH/NLM/LHC) [C] [mailto:blowekamp at mail.nih.gov] 
Sent: Monday, November 28, 2016 2:30 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?

Hi,

You are correct that it does not guarantee that image fits the requirements of the underlying FFT algorithm. But it is an an example of how it could be manually done. If you want to automatically do the FFT convolution there is the FFT convolution filter.

SimpleITK will use what ever FFT library ITK is configured with. When you compile the SimpleITK Superbuild with ITK_USE_FFTWD and ITK_USE_FFTWF defined true on the command line it will build ITK with FFTW and thereby SimpleITK will use FFTW.

HTH,
Brad

[1] https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1FFTConvolutionImageFilter.html

> On Nov 28, 2016, at 9:18 AM, Robert.Atwood at diamond.ac.uk wrote:
> 
> Further question ... 
> 
>> Here is an example for manual padding for FFTs:
>> https://github.com/SimpleITK/SimpleITK/blob/master/Examples/Python/FF
>> TConvolution.py
> 
> # pad the image
> img = sitk.MirrorPad( img, [128] *2, [128]*2 ) size = img.GetSize();
> 
> 
> I don't understand what this line does. I expect it would increase the size of the array by adding 128 on the top and bottom. This does not guarantee that the final size is within the restriction of powers of 2,3, and 5 required by the fft module, does it? Or do I not follow what MirrorPad is doing with the input vectors?
> 
> Or can I get rid of this restriction some other way... 
> 
>  --- Is it possible to configure sitk to  use fftw (or pyfftw)  instead?
> 
> 
> Thanks! 
> Robert
> 
> 
> 
> 
> 
> 
> 
> -----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