# Ultrasound slice is not aligned with reconstructed volume

**URL:** <https://discourse.slicer.org/t/ultrasound-slice-is-not-aligned-with-reconstructed-volume/7247>\
**Category:** Support\
**Tags:** surgical-navigation\
**Created:** [June 19, 2019, 4:27pm UTC](https://discourse.slicer.org/t/ultrasound-slice-is-not-aligned-with-reconstructed-volume/7247 "2019-06-19T16:27:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vgonzalezd](https://avatars.discourse-cdn.com/v4/letter/v/b782af/32.png) [@vgonzalezd](https://discourse.slicer.org/u/vgonzalezd)\
**Post date:** [June 19, 2019, 4:27pm UTC](https://discourse.slicer.org/t/ultrasound-slice-is-not-aligned-with-reconstructed-volume/7247/1 "2019-06-19T16:27:22Z")

</div>

Hello,  
I have 3 questions:

1. **Does anyone have an idea why my ultrasound images don’t match over my reconstructed volume?**  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/1/e1af833bb2f23f015fb771c2204a300ac313d252.png)  
I create my volume with PLUS, and the ImageToProbeTransform is included in the imageToReferenceTransform defined on the “prueba2.mha” file.

PlusApp-2.6.0.20190221-Win64\bin\VolumeReconstructor.exe --config-file=" prueba2-VolRec.xml" --image-to-reference-transform=ImageToReference --source-seq-file=" prueba2.mha" --output-volume-file=" prueba2Volume.mha"  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/e/4e226ca9f712f685a15d930cf4fdedcf1c332f00.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/7/c799f4003833450876b1a9a2aefc212ff0c164c6.png)

1. **How I do to reconstruct my volume specifying the axes orientation:**  
Axes are inclined, I would like to Have the red view on the same orientation that the first ultrasound image.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/c/8cd2d05c392e4a0ad6baf3d9f4d8a5208ca5f4ab.jpeg)

Because I would like to _extract SLICES_ from the compounding volume of ultrasound images and MASKS from the compounding volume of contours images.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/a/4a03642d8a624e10de0b40724465bc4e6f8a8441.jpeg)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/e/ce85bd35e6039023dc4ba50c76a4225963267900.png)

If I’m not mistaken, the reconstructed volume is saved as slices throw an axis. do not?  
If the reconstruction is done with the correct position and orientation of the axes, to recover the SLICES I should only read the mha format, similar to how it is done with a DICOM to obtain images. NOT?

1. **How I can plot the ultrasound probe like in this video** :  
[https://www.youtube.com/watch?v=2Oc\_tCu\_uzs](https://www.youtube.com/watch?v=2Oc_tCu_uzs)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/d/8df6b07492eaa2fffe42a35e4c4217a5bb10c515.png)

I thanks you so much for your help  
Vanessa GONZALEZ

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 19, 2019, 4:54pm UTC](https://discourse.slicer.org/t/ultrasound-slice-is-not-aligned-with-reconstructed-volume/7247/2 "2019-06-19T16:54:16Z")

</div>

Probably there is an RAS/LPS coordinate system difference. Configuration files are optimized for real-time reconstruction, when image is reconstructed in RAS coordinate system and sent to Slicer using OpenIGTLink.

If you reconstruct a volume using the VolumeReconstructor application then it reconstruct the image in RAS coordinate system and saves the image into a file. If you load an image file into Slicer then it is assumed to be in LPS coordinate system. To fix this inconsistency, either change the Plus configuration file to reconstruct in LPS coordinate system or apply this transformation matrix to the reconstructed image after you load it into Slicer:

```
-1 0 0 0
0 -1 0 0
0 0 1 0
0 0 0 1

```

> [@vgonzalezd](#):
>
> How I do to reconstruct my volume specifying the axes orientation:

You specify the coordinate system you want to reconstruct in by the `image-to-reference-transform` parameter.

> [@vgonzalezd](#):
>
> How I can plot the ultrasound probe like in this video

You can find link to step-by-step instructions in the video comment. The .mrb scene file is included in Plus installation package.

---

<div class="post-metadata">

**Author:** ![vgonzalezd](https://avatars.discourse-cdn.com/v4/letter/v/b782af/32.png) [@vgonzalezd](https://discourse.slicer.org/u/vgonzalezd)\
**Post date:** [July 1, 2019, 4:05pm UTC](https://discourse.slicer.org/t/ultrasound-slice-is-not-aligned-with-reconstructed-volume/7247/3 "2019-07-01T16:05:21Z")

</div>

Thank you Andras for your help, I tried to solve the problems in different ways before publish some stupid thing:

1. I tried the matrix transformation solution to pass from RAS to LPS system, it worked really well. I tried also to: “ **change the Plus configuration file to reconstruct in LPS coordinate system** ”. But I thing, I am changing the wrong file.  
I suppose the plus configuration file, is the xml that I give as parameter of reconstruction. I define the transformation ReferenceToReference2. And I reconstruct the volume, but it does not to nothing.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/b/0bd65fd5110082890dce6d2f424b3a58c2302095.png)

2. I changed ImageToReferenceTransformations in the .mha file, one by one, and it worked!!! Thanks for the idea.  
I couldn’t make work reconstruction changing the parameter “ `image-to-reference-transform=" **ReferenceToReference3** ”, Plus volumeReconstruction says:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/9/f97b35c017a775db9e4f89c0459581bb7726df5f.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/c/eccb742790b1b5e12fd413adc7ff57e80d387d0a.png)

3. I did not explain well. I did the step by step of the video, but I don’t find the way to print the probe.stl on realtime over my tracked images, I don’t need to simulate images, I have them already. If it is possible, could someone redirect me to the documentation, please? I’am sorry.

4. _“NEW ISSUE”: Images from my MHA file are charged as LIFO:_  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/4/b4bef3938a9e85579257bb9bc0371975546d2eb0.png)  
I extract the first image from my mha file, and I plot it with pyplot and they are good. Tracking Transforms matrices are created, taking as reference, the up-left corner.  
When I upload the images from my mha file in slicer I’m pretty sure they are charged as LIFO, so the bottom-rigth corner becomes the top-left corner.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/d/1dc6bc00c8b518a0b29335ecf90e04d6e32aa3b7.png)  
I do not just need to flip it in the slicer-view (I did it), because in the 3dspaceview they are not flipped soo tracking and reconstruction is not well done.  
4.a I try changing the .mha parameter AnatomicalOrientation = RAI to RAS, TO LPS, etc. It didn’t work.  
I don’t want to save the images in the .mha as LIFO to be readed well, but if it is the only option I will do it.

Thank you and nice day.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 1, 2019, 6:08pm UTC](https://discourse.slicer.org/t/ultrasound-slice-is-not-aligned-with-reconstructed-volume/7247/4 "2019-07-01T18:08:04Z")

</div>

> [@vgonzalezd](#):
>
> I couldn’t make work reconstruction changing the parameter “ `image-to-reference-transform=" **ReferenceToReference3** ”, Plus volumeReconstruction says:

The error message “Unable to allocate … elements of size …” means that you have run out of memory. You need to decrease the image resolution (increase output voxel spacing) or reduce the region of interest sweeped by the probe. Since Plus computed that you would need 434GB of memory, it may indicate that not just the spacing is off but the region of interest is too big, potentially because of errors in how the coordinate systems are defined.

> [@vgonzalezd](#):
>
> I did not explain well. I did the step by step of the video, but I don’t find the way to print the probe.stl on realtime over my tracked images, I don’t need to simulate images

Regardless you use real or simulated image source, you can use the exact same Slicer scene for visualization.

> [@vgonzalezd](#):
>
> NEW ISSUE”: Images from my MHA file are charged as LIFO:

Make sure to set the [PortUsImageOrientation](http://perk-software.cs.queensu.ca/plus/doc/nightly/user/DeviceMicrosoftMediaFoundation.html) tag correctly. See specification [here](http://perk-software.cs.queensu.ca/plus/doc/nightly/user/UltrasoundImageOrientation.html). If you don’t know what orientation your device provides images in then you can find the correct port US image orientation value by trial and error. Note that if you change the image orientation (or resolution, etc.) then you need to recompute ImageToProbe calibration matrix.

---

<div class="post-metadata">

**Author:** ![vgonzalezd](https://avatars.discourse-cdn.com/v4/letter/v/b782af/32.png) [@vgonzalezd](https://discourse.slicer.org/u/vgonzalezd)\
**Post date:** [August 9, 2019, 1:01pm UTC](https://discourse.slicer.org/t/ultrasound-slice-is-not-aligned-with-reconstructed-volume/7247/5 "2019-08-09T13:01:20Z")

</div>

First of all, thank you Andras for your answer and help.  
**I want to “Transfert images and tracking data from other software to slicer”.**  
I tried to reconstruct the volume with **data of tracking** and **images** obtained with other software. So I am building by myself the “.mha” file, because I am sure slicer is what I am looking for, but the reference systems are making me crazy.

**Problem with the reference axes LPS, RAS, IJK and MF- UF**  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/a/8a6b61557960f925caa104d862b620f4598cbf78.png)

If PLUS algorithm works in **RAS** system, why it asks for an ‘UltrasoundImageOrientation = **MF**'? If I do not add this line on the mha file, it says during reconstruction with PLUS:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/c/6c8533801bb28558b2bf275a6eb8bb11a6df8ff3.png)

1. So the question is: In the .mha file, should I see my image from the MF origin? Should I change trackingMatrices to my referenceSystem Mf? In this case I need to re-calculate calibration matrix also?, Not because it is just a relocation of the reference system, does not?

Can I do it multiplying just: MatrixTracker\*”MatrixReposition”\*Image?

With MatrixReposition=[[-1,0,0, **width/2**],[0,1,0,0],[0,0,1,0],[0,0,0,1]]?

1. When I have any **TransformMatrix** in the .xml file: where it is applied? In MF or in RAS origin?

If I suppose that in PLUS the algorithm charge the image in RAS, so I have to write inversed each image in .mha file? And, with origin the bottom-Right, I applied ImageToIjkTransform=[[-1,0,0,width],[0,-1,0,height],[0,0,-1,0],[0,0,0,1]] to change the origin.

MatrixTracker\*” ImageToIjkTransform”\*Image?

But I obtain images not ovelaped:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/d/4d2da12824853840506fb20ec0e46d9543b83e0f.png)

I tryed different configurations of Transforms and the best result that I have is with matrix ImageToIjkTransform=[[1,0,0,-width],[0,-1,0,-height],[0,0,1,0],[0,0,0,1]]. But it has no sense.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/a/9a0ce643a4b320d2a94976f88b536941febca07e.png)

I thank you your help.

---

<div class="post-metadata">

**Author:** ![Prashant\_Pandey](https://avatars.discourse-cdn.com/v4/letter/p/c0e974/32.png) [@Prashant\_Pandey](https://discourse.slicer.org/u/Prashant_Pandey)\
**Post date:** [August 13, 2019, 8:01pm UTC](https://discourse.slicer.org/t/ultrasound-slice-is-not-aligned-with-reconstructed-volume/7247/6 "2019-08-13T20:01:43Z")

</div>

> [@lassoan](#):
>
> To fix this inconsistency, either change the Plus configuration file to reconstruct in LPS coordinate system or apply this transformation matrix to the reconstructed image after you load it into Slicer:
> 
> ```auto
> -1 0 0 0
> 0 -1 0 0
> 0 0 -1 0
> 0 0 0 1
> 
> ```

Hi Andras,

I think the transform in Slicer for RAS to LPS would instead be

```auto
-1 0 0 0
0 -1 0 0
0 0 1 0
 0 0 0 1

```

Could you describe how to change the PLUS reconfig file to reconstruct in LPS instead of RAS? Just by including the above transform or is there an .xml property you can set?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 15, 2019, 3:21pm UTC](https://discourse.slicer.org/t/ultrasound-slice-is-not-aligned-with-reconstructed-volume/7247/7 "2019-08-15T15:21:04Z")

</div>

Yes, sorry, it was a typo (fixed it now), indeed, RAS\<-\>LPS conversion is done with a diag(-1,-1,1,1) matrix.

Plus can reconstruct a volume in any coordinate system you specify as the “To” coordinate system in `ImageToReference` transform (for example, if you specify `ImageToReference="ImageToTracker"` then the image will be reconstructed in `Tracker` coordinate system).
