[Gate-users] Run GATETOOLS from Python script

Nils Krah nils.krah at creatis.insa-lyon.fr
Thu Jan 30 15:10:25 CET 2020


Hi Daniela,
within a python script, you need to call the python function image_convert. It takes as input an ITK image.
So, say you have a series of dicom files representing a 3D image and you want to convert it to float, you could do:

import os
import fnmatch
import itk
import gatetools as gt

# get file in current folder and filter out those ending on .dcm
dicomfiles = fnmatch.filter(os.listdir('./'), '*.dcm’)
# read them in and get them as ITK image
itk_image = gt.read_dicom(dicomfiles)
# pass the ITK image to the convert function and specify to which type you want to convert
converted_image = gt.image_convert(itk_image, pixeltype=‘float’)
# you get again an ITK image and yu can continue manipulating it as you wish.
# You may dump it with:
itk.imwrite(converted_image, ‘converted_image.mhd’)

(I haven’t tested this bit of code, but it should work.)

Technical remark for python newcomers:
When writing gt. preceding the function name, you are referring to the namespace of the imported module. The module’s name gatetools has been aliased to gt for brevity. That is not mandatory, but often practical.

Hope that helps.

Best,
Nils
On 30 Jan 2020 at 12:56 +0100, Botnariuc, Daniela <daniela.botnariuc.19 at ucl.ac.uk>, wrote:
> Dear GATE users,
>
> I have been using the gatetools (thank you for this great contribution!) from the command line but I would like to run them from a python script. I am not as familiar with python as I should be to understand the code in detail. I tried to transform the bash scripts that run the tools from the command line to python files but I am having problems with the type of input/output the functions require.
>
> For example, for the gt_image_convert, how should I write my input (path to the dicom folder) and output in python to run the function?
> I thought it would be something like: (but I am missing something)
>
> gt_image_convert('/home/gate/Documents/dicom_folder','output.mhd','float')
>
> Thank you. I look forward to hearing from you.
> Kind regards,
> Daniela
>
> _______________________________________________
> Gate-users mailing list
> Gate-users at lists.opengatecollaboration.org
> http://lists.opengatecollaboration.org/mailman/listinfo/gate-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opengatecollaboration.org/pipermail/gate-users/attachments/20200130/9ca46cf6/attachment.html>


More information about the Gate-users mailing list