OpenGATE / opengate

Gate 10 (beta)
http://www.opengatecollaboration.org
GNU Lesser General Public License v3.0
44 stars 39 forks source link

Implement a MaterialManager #282

Open nkrah opened 10 months ago

nkrah commented 10 months ago

Implement a MaterialManager that handles the functionality which is currently provided by helper functions. Probably, also CT to material conversions etc should go there. Not urgent.

jizhang02 commented 10 months ago

Hi, Actually, I don't know how the values are converted. In my case, I have a question, I used XCAT to generate a phantom, one is an activity map (like pet data), and the other one is an attenuation map (like ct data), in attenuation file, the value is density, not the hu value, if I put these two files in GATE simulation to calculate dose map, can the attenuation map automatically convert to a general ct-like matrix? thanks.

nkrah commented 10 months ago

Hey, thanks for posting. If I understand correctly your question is whether you can create an image volume based on an image that contains density rather than CT numbers or HU, right?

The answer to that question is yes. We have just updated the user guide on geometry, so you might want to take a look.

Image volumes in Gate 10 are defined by providing the input image as well as a mapping from the voxel values to materials. The mapping is provided via the parameter voxel_materials. It is up to you as a user to define and provide this mapping because it depends on your type of image and how you model your input. In your case of an image which contains (mass) densities, you need to set the value intervals accordingly, so something around 1 g/cm3 should be water, something around 0.001 g/cm3 should be air, and so forth. Gate will then assign materials to the voxels according to these intervals.

Let me know if that helps you.

PS: We might implement more functionality in the future to convert between common types of image value types (mass density, attenuation, HU, electron density) based on lookup table modeling documented in the literature. I opened this issue as a reminder for this.

jizhang02 commented 10 months ago

Thank you for your reply. It's very helpful! I will have a look.

jizhang02 commented 10 months ago

Hi, Actually, I don't know how the values are converted. In my case, I have a question, I used XCAT to generate a phantom, one is an activity map (like pet data), and the other one is an attenuation map (like ct data), in attenuation file, the value is density, not the hu value, if I put these two files in GATE simulation to calculate dose map, can the attenuation map automatically convert to a general ct-like matrix? thanks.

Hi, Sorry, I come again. I'm not sure about one thing. For instance, I have an attenuation map and an activity map that are simulated in XCAT. If I don't do the reconstruction for these two files, can I use them directly in the GATE 10? Here is my part of the dose map simulation code:

'''
Geometry
'''
# world
world = sim.world
world.size = [200 * cm, 200 * cm, 200 * cm]
world.material = "G4_AIR"
# ct patient
patient = sim.add_volume('Image', 'patient') 
id = str(int(sys.argv[1]))
filename = str(id)+'.mhd'
print(f"CT {filename} is added as phantom")
patient.image = current_path / 'data' / '52pre_mhd'/ 'CT' / filename
ct_info = gate.read_image_info(str(patient.image))
print(f"CT image origin and size and spacing: ", ct_info.origin, ct_info.size, ct_info.spacing)

#print(patient.image.info)
patient.mother = 'world' # connect the geometry to a system
f1 = str(current_path/'data'/"Schneider2000MaterialsTable.txt")
f2 = str(current_path/'data'/"Schneider2000DensitiesTable.txt")
tol = 0.05 * gcm3
patient.voxel_materials, materials = gate.HounsfieldUnit_to_material(tol, f1, f2)
filename = str(sys.argv[1])+'_patient_label.mhd'
patient.dump_label_image = current_path / 'output' / filename

If I load the attenuation map as ct file, does that mean this sentence is not needed? patient.voxel_materials, materials = gate.HounsfieldUnit_to_material(tol, f1, f2)

Thank you! Have a nice day! Jing

nkrah commented 10 months ago

Hi Jing, Gate does not do any reconstruction, i.e. from projection images to volumetric images. You have to provide a volumetric (reconstructed) CT image as input. If the line

patient.image = current_path / 'data' / '52pre_mhd'/ 'CT' / filename

points to such a reconstructed image, you are fine.

The second question is what kind of values this image contains and how you convert them to materials in Gate. The helper function HounsfieldUnit_to_material which you use in this line:

patient.voxel_materials, materials = gate.HounsfieldUnit_to_material(tol, f1, f2)

assumes that your CT image is in Hounsfield units and converts it to human-like materials as explained in the paper Schneider et al 2000 (PMID 10701515). So if you want to use this helper function, make sure your CT image is in Hounsfield Units. If it contains attenuation coefficients, please convert the values to Hounsfield Unit before using the image as input to Gate.

Since we restructured the Gate package, the helper function is in a subpackage and can be called via:

import opengate as gate
gate.geometry,.materials.HounsfieldUnit_to_material( .... )

Make sure you have the latest beta version of Gate installed (if you installed via pip) or pull from the GitHub to update your local code in case you are using a developer install. Can you please type opengate_info in a terminal and check what version of opengate are you using?

jizhang02 commented 10 months ago

Hi,

Thank you for your reply. My goal is to simulate dose map using CT and PET. In this case, I may need to convert the attenuation coefficient values to the Hounsfield Unit. Actually, the version I used is the last year which is 0.7.1, where I use to do the MC simulation. image

But I have installed another version, which is 10.0b3 image

Thank you! Jing

nkrah commented 10 months ago

I see. You should update your installation of gate then. We are currently at beta 6 and there have been many significant changes in the mean time.