# Trajectory calculation for stereotaxic frames

**URL:** <https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963>\
**Category:** Support\
**Created:** [October 9, 2020, 8:18pm UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963 "2020-10-09T20:18:29Z")\
**Posts on this page:** 17\
**Page:** 4

<div class="post-metadata">

**Author:** ![JBeninca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jbeninca/32/10039_2.png) [@JBeninca](https://discourse.slicer.org/u/JBeninca)\
**Post date:** [August 9, 2022, 6:13pm UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/62 "2022-08-09T18:13:31Z")

</div>

I will do the work. i need some time, a couple of weeks. I´m a neurosurgeon with a lot of work

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [August 10, 2022, 1:43am UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/63 "2022-08-10T01:43:55Z")

</div>

dear @JBeninca:  
for my respect.  
it’s rare to see a neurosurgeon can coding slicer in china , my work is to integrate all usefull and convenient slicer plugin into a package for neurosurgeon,your work is very valuable for me to keep tracing,thank you very much.

---

<div class="post-metadata">

**Author:** ![Greydon\_Gilmore](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/greydon_gilmore/32/6863_2.png) [@Greydon\_Gilmore](https://discourse.slicer.org/u/Greydon_Gilmore)\
**Post date:** [August 23, 2022, 2:38am UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/64 "2022-08-23T02:38:39Z")

</div>

@jay1987 looking at your frame CT, it looks like your Y-axis is flipped (something I never considered in my implementation).

@JBeninca no need to rewrite code for the Leksell. You can see my implementation here: [trajectoryGuideModules/frameDetect.py at main · greydongilmore/trajectoryGuideModules · GitHub](https://github.com/greydongilmore/trajectoryGuideModules/blob/main/frameDetect/frameDetect.py). The specific class I wrote for detecting the N-localizers is here: [trajectoryGuideModules/helpers.py at 9c6f99226c4f42e01d88e26badd4b48b79aa0884 · greydongilmore/trajectoryGuideModules · GitHub](https://github.com/greydongilmore/trajectoryGuideModules/blob/9c6f99226c4f42e01d88e26badd4b48b79aa0884/helpers/helpers.py#L365).

I’m happy to help out in any way.

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [August 23, 2022, 2:44am UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/65 "2022-08-23T02:44:43Z")

</div>

thank you very much @Greydon_Gilmore

---

<div class="post-metadata">

**Author:** ![Greydon\_Gilmore](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/greydon_gilmore/32/6863_2.png) [@Greydon\_Gilmore](https://discourse.slicer.org/u/Greydon_Gilmore)\
**Post date:** [August 23, 2022, 3:07am UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/66 "2022-08-23T03:07:09Z")

</div>

accounting for the flip in the Y-axis I am able to obtain the following segmentation from your CT:

 ![Figure_1](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/8/283cd67e9ce19d29b44f111090599fbd393a4eeb.jpeg)

You’ll notice some drop-out near the bottom of the N-localizer due to weak localizer signal. However, you do not need all points to calculate Frame coordinates so this won’t affect accuracy. The other thing I’ve noticed is that your frame CT is not centered (the x,y,z axes should be centered on 100). Did you apply a transform to the image prior to sharing?

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [August 23, 2022, 3:10am UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/67 "2022-08-23T03:10:24Z")

</div>

that’s correct ! @Greydon_Gilmore  
could you please integrate these piece of code in your trajectoryGuideModules?that’s very useful!!

---

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [August 23, 2022, 11:51am UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/68 "2022-08-23T11:51:33Z")

</div>

A best way for Leksell frame. You can use Fiducial Registration module to register the CT data with the prepared points .

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [August 23, 2022, 11:55am UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/69 "2022-08-23T11:55:51Z")

</div>

yes,it’s work!  
but i need to find the x,y,z position and three angles relative to the leksell frame .

---

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [August 23, 2022, 12:24pm UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/70 "2022-08-23T12:24:00Z")

</div>

It is easy，when you adjust the XYZ frame and RAS to be parallel, it can be obtained by simple calculation. Regarding the angle, it can be obtained by the arctangent function.  
 ![1661257411293](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/5/45e6998c0243a4cfe7b40ccfee770efe9ca5ea87.png)

---

<div class="post-metadata">

**Author:** ![jay1987](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jay1987/32/16183_2.png) [@jay1987](https://discourse.slicer.org/u/jay1987)\
**Post date:** [August 23, 2022, 12:28pm UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/71 "2022-08-23T12:28:40Z")

</div>

I understand what you mean,but i dont have a leksell headframe , i can’t judge the result what i caculate , the recent value i get is about 5 degree off to the correct result what i send to my doctor friend to evaluate

---

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [August 23, 2022, 12:32pm UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/72 "2022-08-23T12:32:31Z")

</div>

Do you have the module, maybe I can provide you with the CT data or I can help you test it.

---

<div class="post-metadata">

**Author:** ![JBeninca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jbeninca/32/10039_2.png) [@JBeninca](https://discourse.slicer.org/u/JBeninca)\
**Post date:** [August 25, 2022, 2:16pm UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/73 "2022-08-25T14:16:21Z")

</div>

Yes , please @jay1987, if you can send one or more leksell framed - patient CT scan data , I ´ll will be thankfull

---

<div class="post-metadata">

**Author:** ![jfdoarias](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jfdoarias/32/7538_2.png) [@jfdoarias](https://discourse.slicer.org/u/jfdoarias)\
**Post date:** [November 21, 2022, 12:57am UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/75 "2022-11-21T00:57:42Z")

</div>

this is a tc with leksell arc: [WeTransfer - Send Large Files & Share Photos Online - Up to 2GB Free](https://we.tl/t-xlITWNB3xw)

---

<div class="post-metadata">

**Author:** ![vzapata10](https://avatars.discourse-cdn.com/v4/letter/v/c5a1d2/32.png) [@vzapata10](https://discourse.slicer.org/u/vzapata10)\
**Post date:** [June 12, 2024, 3:42pm UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/76 "2024-06-12T15:42:37Z")

</div>

Hi Greydon @Greydon_Gilmore,

Thanks for the implementation of trajectoryGuide! It seems great. I have some segmentations of basal ganglia structures that I’m visualizing over the MRI in slicer (they are all co-registered to the T1 space). I want to overlay the MER and implantation notes about the start and end of the STN; those measurements are based on the stereotactic frame’s coordinate system (we use a Leksell frame). I was looking at the website of trajectoryGuide and I think I could accomplish this using your tool.

I already installed all the requirements and upload my data on BIDS format. However, when I run the second step “02: Frame detection” I get the following error in Slicer’s Python console:

“Traceback (most recent call last):  
File “C:/Users/zapatav/Desktop/Toolboxes/Slicer/trajectoryGuide/frameDetect/frameDetect.py”, line 685, in onFrameDetectButton  
self.logic.runFrameDetection(self.ui.frameFidVolumeCBox.currentNode(), self.frame\_settings, self.\_parameterNode.GetParameter(‘derivFolder’))  
File “C:/Users/zapatav/Desktop/Toolboxes/Slicer/trajectoryGuide/frameDetect/frameDetect.py”, line 1165, in runFrameDetection  
self.frameDetectInstance = frameDetection(frameFidVolume, derivFolder, frame\_settings)  
File “C:\Users\zapatav\Desktop\Toolboxes\Slicer\trajectoryGuide\helpers\helpers.py”, line 383, in **init**  
self.frame\_detect()  
File “C:\Users\zapatav\Desktop\Toolboxes\Slicer\trajectoryGuide\helpers\helpers.py”, line 1068, in frame\_detect  
combined=self.NLocalizersSort(component, self.frame\_settings[‘n\_components’], 2)  
File “C:\Users\zapatav\Desktop\Toolboxes\Slicer\trajectoryGuide\helpers\helpers.py”, line 780, in NLocalizersSort  
min\_threshold=gaps[0][0]  
IndexError: list index out of range”

I wanted to ask you if you have seen this before and know how could I fix it, or if is there any forum specifically for trajectoryGuide that I can look at?

Any help would be much appreciated!  
Thanks,

Valentina

---

<div class="post-metadata">

**Author:** ![Greydon\_Gilmore](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/greydon_gilmore/32/6863_2.png) [@Greydon\_Gilmore](https://discourse.slicer.org/u/Greydon_Gilmore)\
**Post date:** [June 19, 2024, 11:42pm UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/77 "2024-06-19T23:42:47Z")

</div>

Sending you a PM to try and solve this problem.

Greydon

---

<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 22, 2024, 5:18am UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/78 "2024-06-22T05:18:58Z")

</div>

It would be great if you could keep the discussion public (there could be a lot to learn). If it is not possible then please suammarize in the end what the issue was and how you solved it.

---

<div class="post-metadata">

**Author:** ![Daniel\_Leeb](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/daniel_leeb/32/77338_2.png) [@Daniel\_Leeb](https://discourse.slicer.org/u/Daniel_Leeb)\
**Post date:** [July 17, 2024, 8:47am UTC](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963/79 "2024-07-17T08:47:44Z")

</div>

Hey @Greydon_Gilmore!

I also stumbled across your extension after searching for some tool to detect the Leksell frame. It seems very well implemented and also well documented, but unfortunately I can’t figure out some mistake of mine. I would really appreciate it if you can help me out here.  
So I tested it with the dataset provided in the extension first and everything went well.  
After I changed my CT scan of a head with a Leksell frame from DICOM to BIDS format (following the tutorial you linked in your documentation), I tried to detect the frame again but without success.

The mouse courser is stuck at the hourglass symbol and the following error message is printed:

“Traceback (most recent call last):  
File “C:/Users/Praktikant/Documents/OwnSlicerExtensions/trajectoryGuideModules-main/frameDetect/frameDetect.py”, line 936, in onFrameDetectButton  
self.logic.runFrameDetection(self.ui.frameFidVolumeCBox.currentNode(), self.frame\_settings, self.\_parameterNode.GetParameter(‘derivFolder’))  
File “C:/Users/Praktikant/Documents/OwnSlicerExtensions/trajectoryGuideModules-main/frameDetect/frameDetect.py”, line 1416, in runFrameDetection  
self.frameDetectInstance = frameDetection(frameFidVolume, derivFolder, frame\_settings)  
File “C:\Users\Praktikant\Documents\OwnSlicerExtensions\trajectoryGuideModules-main\helpers\helpers.py”, line 383, in **init**  
self.frame\_detect()  
File “C:\Users\Praktikant\Documents\OwnSlicerExtensions\trajectoryGuideModules-main\helpers\helpers.py”, line 1066, in frame\_detect  
component=np.vstack(component)  
File “C:\Users\Praktikant\AppData\Local\slicer.org\Slicer 5.6.2\lib\Python\Lib\site-packages\numpy\core\shape\_base.py”, line 289, in vstack  
return \_nx.concatenate(arrs, 0, dtype=dtype, casting=casting)  
ValueError: need at least one array to concatenate”

What I understand out of this error is that no fiducials of the N-shaped frame get detected.  
Also interesting is that the frame is indeed moved to the center of RAS without me having to confirm the fiducials first, but the program is still stuck.

In case you want to test it yourself with my dataset, here is the link to it:  
[https://drive.google.com/drive/folders/1Wseu8hA481GXpzp6l6GjhS4tudUd9WOo?usp=drive\_link](https://drive.google.com/drive/folders/1Wseu8hA481GXpzp6l6GjhS4tudUd9WOo?usp=drive_link)

I would really appreciate your help, because I would like to use your extension for a project of mine. 🙂

Thanks,  
Daniel

[Previous page](https://discourse.slicer.org/t/trajectory-calculation-for-stereotaxic-frames/13963.md?page=3)
