OpenGATE / Gate

Official public repository of Gate
http://www.opengatecollaboration.org
GNU Lesser General Public License v3.0
232 stars 261 forks source link

Wrong "Offset" value in dose.mhd output with HFP patient set up #333

Open Golpette opened 4 years ago

Golpette commented 4 years ago

Hi,

I tried simulating a radiotherapy treatment with the patient in head first prone (HFP) position. My CT x,y voxel size is 0.97656 and dose voxels are 2.07469. I convert the dcm CT images to an mhd format as shown and this is the input to my simulation:

ObjectType = Image NDims = 3 BinaryData = True BinaryDataByteOrderMSB = False CompressedData = False TransformMatrix = -1 0 0 0 -1 0 0 0 1 Offset = 250 250 -100 CenterOfRotation = 0 0 0 AnatomicalOrientation = LPI ElementSpacing = 0.97656200000000004 0.97656200000000004 2.5 DimSize = 512 512 164 ElementType = MET_SHORT ElementDataFile = ct.raw

The mhd for the dose output from the gate simulation is this:

ObjectType = Image NDims = 3 BinaryData = True BinaryDataByteOrderMSB = False CompressedData = False TransformMatrix = -1 0 0 0 -1 0 0 0 1 Offset = 251.52600000000001 251.52600000000001 -100 CenterOfRotation = 0 0 0 ElementSpacing = 2.0746877193450928 2.0746877193450928 2.5 DimSize = 241 241 164 AnatomicalOrientation = ??? ElementType = MET_FLOAT ElementDataFile = 3d-pat-Dose.raw

It has calculated the Offset property as 250 + 0.5x0.97656 + 0.5x2.07469. However, with dose voxels larger than the CT voxels the Offset parameter for the dose has to be less than 250 to make the corners of the CT image and dose image align.

It should be 250 + 0.5x0.97656 - 0.5x2.07469 = 249.45

Have I misunderstood how I should be using mhd images for non-standard (non-HFS) patient set-ups or is this a bug?

Golpette commented 4 years ago

I should maybe have said I'm simulating using virtual Gate version 8.2

l545814240 commented 4 years ago

Hello, I am using GATE8.1 for CT simulation. And I found a strange thing when i use the .mhd file as the phantom. I wonder if you have got the same phenomenon. I defined the rotation for the input phantom using the .mdh below:

ObjectType = Image NDims = 3 DimSize = 128 128 32 HeaderSize = 0 TransformMatrix = 1 0 0 0 0.866 -0.5 0 0.5 0.866 Offset = 0 0 0 CenterOfRotation = 0 0 0 ElementType = MET_UCHAR
ElementSize = 0.5 0.5 0.5 ElementByteOrderMSB = False ElementDataFile = phantom.bin

You can see it from TransformMatrix that a rotation of 30 degs along X axis has been done. But i got a strange scene when I view the world: both of the original and rotated phantom exist in the world. And from the projection image , I do see the existence of original phantom(before rotation).

So I wonder if our problems have the same reason.

dsarrut commented 4 years ago

Hello,

for 1) this is center of the pixel that are aligned

for 2), the transformMatrix in the mhd is ignored by Gate (maybe by the visualisation use it however ?)

Sincerely, David

On Fri, May 8, 2020 at 12:13 PM l545814240 notifications@github.com wrote:

Hello, I am using GATE8.1 for CT simulation. And I found a strange thing when i get use the .mhd file as the phantom. I wonder if you have got the same phenomenon. I defined the rotation for the input phantom using the .mdh below:

ObjectType = Image NDims = 3 DimSize = 128 128 32 HeaderSize = 0 TransformMatrix = 1 0 0 0 0.866 -0.5 0 0.5 0.866 Offset = 0 0 0 CenterOfRotation = 0 0 0 ElementType = MET_UCHAR ElementSize = 0.5 0.5 0.5 ElementByteOrderMSB = False ElementDataFile = phantom.bin

You can see it from TransformMatrix that a rotation of 30 degs along X axis has been done. But i got the a strange scene when I view the world: both of the original and rotated phantom exist in the world. And from the projection image , I do see the existence of original phantom(before rotation).

So I wonder if our problems have the same reason.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/OpenGATE/Gate/issues/333#issuecomment-625745326, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADRI7HXJYL4S7NUE6EKHVDRQPLOHANCNFSM4MVOGHDQ .

-- David Sarrut, Phd Directeur de recherche CNRS CREATIS, UMR CNRS 5220, Inserm U1206 Centre de lutte contre le cancer Léon Bérard 28 rue Laënnec, 69373 Lyon cedex 08 Tel : 04 78 78 51 51 / 06 74 72 05 42 http://www.creatis.insa-lyon.fr/~dsarrut


"2 + 2 = 5, for extremely large values of 2"


Golpette commented 4 years ago

Hi,

Thanks for the response but I don't think this is the case. The Offset does specify the position of the centre of the voxel, but the dose.mhd output from the simulation is supposed to have an Offset calculated so as to match the input image, as stated in the manual here:

In this case, the origin of the dose distribution will be set such that it corresponds to the attached image (easy superimposition display).

If I have a head-first supine (HFS) patient with input image:

ObjectType = Image NDims = 3 BinaryData = True BinaryDataByteOrderMSB = False CompressedData = False TransformMatrix = 1 0 0 0 1 0 0 0 1 Offset = -250 -250 -137.5 CenterOfRotation = 0 0 0 AnatomicalOrientation = RAI ElementSpacing = 0.97656200000000004 0.97656200000000004 2.5 DimSize = 512 512 92 ElementType = MET_SHORT ElementDataFile = ct_air.raw

then it produces a dose image with mhd:

ObjectType = Image NDims = 3 BinaryData = True BinaryDataByteOrderMSB = False CompressedData = False TransformMatrix = 0.99999999999847677 0 -1.7454088287759716e-06 0 1 0 1.7454088287759716e-06 0 0.99999999999847677 Offset = -249.41999999999999 -249.41999999999999 -137.5 CenterOfRotation = 0 0 0 ElementSpacing = 2.1367509365081787 2.1367509365081787 2.5 DimSize = 234 234 92 AnatomicalOrientation = ??? ElementType = MET_FLOAT ElementDataFile = 3d-pat-Dose.raw

So for example, -250 -0.5x0.97656 + 0.5x2.13675 = -249.4199. Hence Gate has correctly calculated the new Offset so that the corners of the 2 images align and I can do something like "vv ct.mhd --fusion dose.mhd" for easy superimposition.

This is not the case for the head-first prone (HFP) example I originally posted. In that example, Gate has calculated the Offset incorrectly due to the patient's orientation being different (i.e. the TransformMatrix / AnatomicalOrientation). Fusing the 2 images in this case misaligns the dose and CT image and would make a user think they had made an error in their simulation.

dsarrut commented 4 years ago

you are right, sorry I overlooked. Indeed the AnatomicalOrientation is not used by Gate.

Try to rotate/flip the image before ; maybe gt_affine_transform in https://github.com/OpenGATE/GateTools may help ?

You can also try to dig :

https://github.com/OpenGATE/Gate/blob/develop/source/digits_hits/src/GateVImageActor.cc and

https://github.com/OpenGATE/Gate/blob/develop/source/general/include/GateImageT.icc#L158

David

On Mon, May 11, 2020 at 1:42 PM Steve notifications@github.com wrote:

Hi,

Thanks for the response but I don't think this is the case. The Offset does specify the position of the centre of the voxel, but the dose.mhd output from the simulation is supposed to have an Offset calculated so as to match the input image, as stated in the manual here http://url:

In this case, the origin of the dose distribution will be set such that it corresponds to the attached image (easy superimposition display).

If I have a head-first supine (HFS) patient with input image:

ObjectType = Image NDims = 3 BinaryData = True BinaryDataByteOrderMSB = False CompressedData = False TransformMatrix = 1 0 0 0 1 0 0 0 1 Offset = -250 -250 -137.5 CenterOfRotation = 0 0 0 AnatomicalOrientation = RAI ElementSpacing = 0.97656200000000004 0.97656200000000004 2.5 DimSize = 512 512 92 ElementType = MET_SHORT ElementDataFile = ct_air.raw

then it produces a dose image with mhd:

ObjectType = Image NDims = 3 BinaryData = True BinaryDataByteOrderMSB = False CompressedData = False TransformMatrix = 0.99999999999847677 0 -1.7454088287759716e-06 0 1 0 1.7454088287759716e-06 0 0.99999999999847677 Offset = -249.41999999999999 -249.41999999999999 -137.5 CenterOfRotation = 0 0 0 ElementSpacing = 2.1367509365081787 2.1367509365081787 2.5 DimSize = 234 234 92 AnatomicalOrientation = ??? ElementType = MET_FLOAT ElementDataFile = 3d-pat-Dose.raw

So for example, -250 -0.50.97656 + 0.52.13675 = -249.4199. Hence Gate has correctly calculated the new Offset so that the corners of the 2 images align and I can do something like "vv ct.mhd --fusion dose.mhd" for easy superimposition.

This is not the case for the head-first prone (HFP) example I originally posted. In that example, Gate has calculated the Offset incorrectly due to the patient's orientation being different (i.e. the TransformMatrix / AnatomicalOrientation). Fusing the 2 images in this case misaligns the dose and CT image and would make a user think they had made an error in their simulation.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OpenGATE/Gate/issues/333#issuecomment-626650963, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADRI7DLIAWSBHDUI4AYNWLRQ7QCBANCNFSM4MVOGHDQ .

-- David Sarrut, Phd Directeur de recherche CNRS CREATIS, UMR CNRS 5220, Inserm U1206 Centre de lutte contre le cancer Léon Bérard 28 rue Laënnec, 69373 Lyon cedex 08 Tel : 04 78 78 51 51 / 06 74 72 05 42 http://www.creatis.insa-lyon.fr/~dsarrut


"2 + 2 = 5, for extremely large values of 2"


Golpette commented 4 years ago

Thanks, I will look at the code when I get a chance and hopefully be able to contribute something.

For now I am just simply getting my code to print out the true Offset and I manually alter the dose.mhd after. It's just that for new users like myself, this is confusing and it took me many hours to figure out why my dosimetry was wrong - hopefully others can see this issue and avoid it.

SimonRit commented 4 years ago

I am not following you @Golpette. Do you think that the anatomical orientation should change something in the geometry of the image? Or do you mean that the anatomical orientation should be copied in the dose image? I agree with the second option, not with the first.

Golpette commented 4 years ago

Hopefully to be clearer: I think that the non-HFS setup has confused Gate's calculation of the Offset in the dose image generated by the simulation.

In the HFS case we have:

TransformMatrix = 1 0 0 0 1 0 0 0 1 Offset = -250 -250 -137.5

and Gate correctly calculates the dose Offset as -250 - 0.5x(IMG voxel size) + 0.5x(DOSE voxel size). See my reply above for the full details.

However, now look at my original post. With the HFP case, I convert the dicom images to an mhd+raw pair (and I checked that this is the case using both my code and GateTools as well) to get:

TransformMatrix = -1 0 0 0 -1 0 0 0 1 Offset = 250 250 -100

So if I use this mhd/raw image directly in my simulation, the Offset of the dose image should be 250 + 0.5x(IMG voxel size) - 0.5x(DOSE voxel size) if we want to align the image corners. This is not the case (see the x-Offset of 251.526 in the original post).

I hope that is clear.

SimonRit commented 4 years ago

Yes I think this is clearer. I'm not sure what the problem, maybe this code is not correct.