<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span>Hi Greg,</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span>I haven't used the clitk stuff before, so don't know the issue, but if you're comfortable working with Python you can do this easily with the GateTools library currently under development (here: <a id="LPlnk" href="https://github.com/OpenGATE/GateTools">https://github.com/OpenGATE/GateTools</a>).</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span>A method like the one below will work. Give it the path to your mhd image, the structure dicom file and a name for the output image. S</span><span>orry for the bad formatting but my work email won't allow me to attach a .py file as an attachment.</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><span style="display:inline !important;background-color:rgb(255, 255, 255);font-size-adjust:none">(Also note that if your patient is in a non-HFS position, such as head first prone, then this method may actually fail depending on the parameters in the
mhd file. If that's the case, feel free to give me an email and I can send some updated code that should work in all cases).</span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span>----------- CODE -----------</span><span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span>import itk
<div>import pydicom</div>
<div>import gatetools.roi_utils as roiutils</div>
<div><br>
</div>
<div><br>
</div>
<div>HU_AIR = -1000</div>
<div>CONTOUR = "BODY"</div>
<div><br>
</div>
<div><br>
</div>
<div>def set_air_external( img_file, structure_file, output_img_file ):</div>
<div> """Set all HUs outside of BODY/EXTERNAL contour to air HU=-1000</div>
<div> The img_file should be the mhd file</div>
<div> """</div>
<div><br>
</div>
<div> img = itk.imread( img_file )</div>
<div> ds = pydicom.dcmread( structure_file )</div>
<div> </div>
<div> aroi = roiutils.region_of_interest(ds,CONTOUR)</div>
<div> mask = aroi.get_mask(img, corrected=False)</div>
<div> #itk.imwrite(mask, "mask.mhd") </div>
<div><br>
</div>
<div> pix_mask = itk.array_view_from_image(mask)</div>
<div> pix_img = itk.array_view_from_image(img) </div>
<div> </div>
<div> pix_img_flat = pix_img.flatten()</div>
<div> for i,val in enumerate( pix_mask.flatten() ):</div>
<div> if val==0:</div>
<div> pix_img_flat[i] = HU_AIR</div>
<div> pix_img = pix_img_flat.reshape( pix_img.shape )</div>
<div> img_modified = itk.image_view_from_array( pix_img )</div>
<div> </div>
<div> img_modified.CopyInformation(img)</div>
<div><br>
</div>
itk.imwrite(img_modified, output_img_file )<br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-family: Calibri,Arial,Helvetica,sans-serif; font-size: 12pt;">
<br>
</div>
<div id="appendonsend"></div>
<div style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font color="#000000" face="Calibri, sans-serif" style="font-size:11pt"><b>From:</b> Gate-users <gate-users-bounces@lists.opengatecollaboration.org> on behalf of gate-users-request@lists.opengatecollaboration.org <gate-users-request@lists.opengatecollaboration.org><br>
<b>Sent:</b> 23 March 2021 04:03<br>
<b>To:</b> gate-users@lists.opengatecollaboration.org <gate-users@lists.opengatecollaboration.org><br>
<b>Subject:</b> Gate-users Digest, Vol 178, Issue 42</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">Send Gate-users mailing list submissions to<br>
gate-users@lists.opengatecollaboration.org<br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="http://lists.opengatecollaboration.org/mailman/listinfo/gate-users">
http://lists.opengatecollaboration.org/mailman/listinfo/gate-users</a><br>
or, via email, send a message with subject or body 'help' to<br>
gate-users-request@lists.opengatecollaboration.org<br>
<br>
You can reach the person managing the list at<br>
gate-users-owner@lists.opengatecollaboration.org<br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of Gate-users digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
1. Re: use dicom ct in simulations: override HU outside<br>
BODY/External Contour to air (G Tom)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Tue, 23 Mar 2021 00:35:05 -0400<br>
From: G Tom <gregthom992@gmail.com><br>
To: Gate-users <gate-users@lists.opengatecollaboration.org><br>
Subject: Re: [Gate-users] use dicom ct in simulations: override HU<br>
outside BODY/External Contour to air<br>
Message-ID:<br>
<CAFh_-ONBSnsQ3Dm_2wid-cPRdx-3UrGnwVMFjWZO31jgkFUp8A@mail.gmail.com><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
If it helps anyone these are the commands I use:<br>
# Create a mask of the BODY/EXTERNALcontour<br>
clitkDicomRTStruct2Image -i ../RS.Test_Dicom_MC.Str1.dcm -o<br>
patient-mask.mhd -n BODY -j patient.mhd<br>
<br>
# Set outside BODY/EXTERNAL to air"<br>
clitkSetBackground -i patient.mhd -m patient-mask.mhd -p -1000 -o<br>
patient-cleaned.mhd<br>
<br>
Thank you<br>
<br>
GT<br>
<br>
On Thu, Mar 18, 2021 at 12:27 AM G Tom <gregthom992@gmail.com> wrote:<br>
<br>
> Hi,<br>
><br>
> I am trying to use a ct dataset for my simulations. I use vv to convert<br>
> dicom slices to mhd like so<br>
><br>
> clitkDicom2Image -o test.mhd *.dcm<br>
><br>
> This is fine and I get the mhd/raw files but I have the associated<br>
> structures with a BODY/EXTERNAL contour and want to crop/mask the ct so<br>
> that all voxels outside of the External/ BODY contour are set to HU of AIR.<br>
><br>
> Does anyone have a straightforward way to do it ?<br>
><br>
> First I tried creating a mask of the body structure but the result is not<br>
> satisfactory; vv seems to only binarize every other slice. I used the<br>
> command:<br>
><br>
> clitkDicomRTStruct2Image -i RS.Test_Dicom_MC.Str1.dcm -j<br>
> ct/'CT.Test_Dicom_MC.Image 1.dcm' -c -n BODY -o bodymask.mhd<br>
><br>
> [image: image.png]<br>
><br>
><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.opengatecollaboration.org/pipermail/gate-users/attachments/20210323/ac5790fb/attachment.html">http://lists.opengatecollaboration.org/pipermail/gate-users/attachments/20210323/ac5790fb/attachment.html</a>><br>
-------------- next part --------------<br>
A non-text attachment was scrubbed...<br>
Name: image.png<br>
Type: image/png<br>
Size: 90012 bytes<br>
Desc: not available<br>
URL: <<a href="http://lists.opengatecollaboration.org/pipermail/gate-users/attachments/20210323/ac5790fb/attachment.png">http://lists.opengatecollaboration.org/pipermail/gate-users/attachments/20210323/ac5790fb/attachment.png</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
Gate-users mailing list<br>
Gate-users@lists.opengatecollaboration.org<br>
<a href="http://lists.opengatecollaboration.org/mailman/listinfo/gate-users">http://lists.opengatecollaboration.org/mailman/listinfo/gate-users</a><br>
<br>
------------------------------<br>
<br>
End of Gate-users Digest, Vol 178, Issue 42<br>
*******************************************<br>
<br>
<br>
<br>
This message originated from outside of NHSmail. Please do not click links or open attachments unless you recognise the sender and know the content is safe.<br>
</div>
</span></font></div>
<br>
<font face="Courier New" color="Black" size="2"><br>
********************************************************************************************************************<br>
<br>
This message may contain confidential information. If you are not the intended recipient please inform the<br>
sender that you have received the message in error before deleting it.<br>
Please do not disclose, copy or distribute information in this e-mail or take any action in relation to its contents. To do so is strictly prohibited and may be unlawful. Thank you for your co-operation.<br>
<br>
NHSmail is the secure email and directory service available for all NHS staff in England and Scotland. NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and other accredited email services.<br>
<br>
For more information and to find out how you can switch, https://portal.nhs.net/help/joiningnhsmail<br>
<br>
</font>
</body>
</html>