[Gate-users] use dicom ct in simulations: override HU outside BODY/External Contour to air (G Tom)

COURT, Steven (UNIVERSITY COLLEGE LONDON HOSPITALS NHS FOUNDATION TRUST) steven.court at nhs.net
Tue Mar 23 10:40:08 CET 2021


Hi Greg,

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: https://github.com/OpenGATE/GateTools).

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. Sorry for the bad formatting but my work email won't allow me to attach a .py file as an attachment.

(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).

----------- CODE -----------

import itk
import pydicom
import gatetools.roi_utils as roiutils


HU_AIR = -1000
CONTOUR = "BODY"


def set_air_external( img_file, structure_file, output_img_file ):
    """Set all HUs outside of BODY/EXTERNAL contour to air HU=-1000
    The img_file should be the mhd file
    """

    img = itk.imread( img_file )
    ds = pydicom.dcmread( structure_file )

    aroi = roiutils.region_of_interest(ds,CONTOUR)
    mask = aroi.get_mask(img, corrected=False)
    #itk.imwrite(mask, "mask.mhd")

    pix_mask = itk.array_view_from_image(mask)
    pix_img = itk.array_view_from_image(img)

    pix_img_flat = pix_img.flatten()
    for i,val in enumerate( pix_mask.flatten() ):
        if val==0:
            pix_img_flat[i] = HU_AIR
    pix_img = pix_img_flat.reshape( pix_img.shape )
    img_modified = itk.image_view_from_array( pix_img )

    img_modified.CopyInformation(img)

    itk.imwrite(img_modified, output_img_file )









________________________________
From: Gate-users <gate-users-bounces at lists.opengatecollaboration.org> on behalf of gate-users-request at lists.opengatecollaboration.org <gate-users-request at lists.opengatecollaboration.org>
Sent: 23 March 2021 04:03
To: gate-users at lists.opengatecollaboration.org <gate-users at lists.opengatecollaboration.org>
Subject: Gate-users Digest, Vol 178, Issue 42

Send Gate-users mailing list submissions to
        gate-users at lists.opengatecollaboration.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.opengatecollaboration.org/mailman/listinfo/gate-users
or, via email, send a message with subject or body 'help' to
        gate-users-request at lists.opengatecollaboration.org

You can reach the person managing the list at
        gate-users-owner at lists.opengatecollaboration.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Gate-users digest..."


Today's Topics:

   1. Re: use dicom ct in simulations: override HU outside
      BODY/External Contour to air (G Tom)


----------------------------------------------------------------------

Message: 1
Date: Tue, 23 Mar 2021 00:35:05 -0400
From: G Tom <gregthom992 at gmail.com>
To: Gate-users <gate-users at lists.opengatecollaboration.org>
Subject: Re: [Gate-users] use dicom ct in simulations: override HU
        outside BODY/External Contour to air
Message-ID:
        <CAFh_-ONBSnsQ3Dm_2wid-cPRdx-3UrGnwVMFjWZO31jgkFUp8A at mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

If it helps anyone these are the commands I use:
# Create a mask of the  BODY/EXTERNALcontour
clitkDicomRTStruct2Image -i ../RS.Test_Dicom_MC.Str1.dcm -o
patient-mask.mhd -n BODY -j patient.mhd

# Set outside BODY/EXTERNAL to air"
clitkSetBackground -i patient.mhd -m patient-mask.mhd -p -1000 -o
patient-cleaned.mhd

Thank you

GT

On Thu, Mar 18, 2021 at 12:27 AM G Tom <gregthom992 at gmail.com> wrote:

> Hi,
>
> I am trying to use a ct dataset for my simulations. I use vv to convert
> dicom slices to mhd like so
>
> clitkDicom2Image -o test.mhd *.dcm
>
> This is fine and I get the mhd/raw files but I have the associated
> structures with a BODY/EXTERNAL contour and want to crop/mask the ct so
> that all voxels outside of the External/ BODY contour are set to HU of AIR.
>
> Does anyone have a straightforward way to do it ?
>
> First I tried creating a mask of the body structure but the result is not
> satisfactory; vv seems to only binarize every other slice. I used the
> command:
>
> clitkDicomRTStruct2Image -i RS.Test_Dicom_MC.Str1.dcm -j
> ct/'CT.Test_Dicom_MC.Image 1.dcm' -c -n BODY -o bodymask.mhd
>
> [image: image.png]
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opengatecollaboration.org/pipermail/gate-users/attachments/20210323/ac5790fb/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 90012 bytes
Desc: not available
URL: <http://lists.opengatecollaboration.org/pipermail/gate-users/attachments/20210323/ac5790fb/attachment.png>

------------------------------

Subject: Digest Footer

_______________________________________________
Gate-users mailing list
Gate-users at lists.opengatecollaboration.org
http://lists.opengatecollaboration.org/mailman/listinfo/gate-users

------------------------------

End of Gate-users Digest, Vol 178, Issue 42
*******************************************



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.


********************************************************************************************************************

This message may contain confidential information. If you are not the intended recipient please inform the
sender that you have received the message in error before deleting it.
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.

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.

For more information and to find out how you can switch, https://portal.nhs.net/help/joiningnhsmail

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opengatecollaboration.org/pipermail/gate-users/attachments/20210323/364ff66a/attachment.html>


More information about the Gate-users mailing list