<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Dear Nils,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Thank you very much for the quick reply, I really appreciate it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">I tried to run the code you suggested but I still get an error.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">According to the code, the ‘dicomfiles’ variable is an array which lists all the files in the folder: [‘dicom1.dcm’, ‘dicom2.dcm’,
‘dicom3.dcm’, ….] - it actually lists the files in a random order.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">When I run the code, I get the following error:
<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:36.0pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">no such file or directory: ‘dicom 17.dcm' (being ‘dicom17.dcm’ the first file appearing in my list)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">I appreciate any help with this issue.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Thank you<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Daniela
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Nils Krah <nils.krah@creatis.insa-lyon.fr>
<br>
<b>Sent:</b> 30 January 2020 14:10<br>
<b>To:</b> gate-users@lists.opengatecollaboration.org; Botnariuc, Daniela <daniela.botnariuc.19@ucl.ac.uk><br>
<b>Subject:</b> Re: [Gate-users] Run GATETOOLS from Python script<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div name="messageBodySection">
<div>
<p class="MsoNormal">Hi Daniela, <o:p></o:p></p>
<div>
<p class="MsoNormal">within a python script, you need to call the python function image_convert. It takes as input an ITK image. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">So, say you have a series of dicom files representing a 3D image and you want to convert it to float, you could do: <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">import os<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">import fnmatch<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">import itk<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">import gatetools as gt<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"># get file in current folder and filter out those ending on .dcm<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">dicomfiles = fnmatch.filter(os.listdir('./'), '*.dcm’)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"># read them in and get them as ITK image<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">itk_image = gt.read_dicom(dicomfiles)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"># pass the ITK image to the convert function and specify to which type you want to convert<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">converted_image = gt.image_convert(itk_image, pixeltype=‘float’)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"># you get again an ITK image and yu can continue manipulating it as you wish.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"># You may dump it with:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">itk.imwrite(converted_image, ‘converted_image.mhd’)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">(I haven’t tested this bit of code, but it should work.)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Technical remark for python newcomers: <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">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. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Hope that helps. <o:p></o:p></p>
</div>
</div>
</div>
<div name="messageSignatureSection">
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Best,<br>
Nils<o:p></o:p></p>
</div>
</div>
<div name="messageReplySection">
<p class="MsoNormal">On 30 Jan 2020 at 12:56 +0100, Botnariuc, Daniela <<a href="mailto:daniela.botnariuc.19@ucl.ac.uk">daniela.botnariuc.19@ucl.ac.uk</a>>, wrote:<br>
<br>
<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #1ABC9C 1.0pt;padding:0cm 0cm 0cm 8.0pt;margin-left:3.75pt;margin-top:3.75pt;margin-right:3.75pt;margin-bottom:3.75pt">
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Dear GATE users,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">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?<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I thought it would be something like: (but I am missing something)<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">gt_image_convert('/home/gate/Documents/dicom_folder','output.mhd','float')<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Thank you. I look forward to hearing from you.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Kind regards,<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Daniela<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<p class="MsoNormal">_______________________________________________<br>
Gate-users mailing list<br>
<a href="mailto:Gate-users@lists.opengatecollaboration.org">Gate-users@lists.opengatecollaboration.org</a><br>
<a href="http://lists.opengatecollaboration.org/mailman/listinfo/gate-users">http://lists.opengatecollaboration.org/mailman/listinfo/gate-users</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</body>
</html>