# Add orientation labels (A, P, S, I, R, L) to 2D slice views

**URL:** <https://discourse.slicer.org/t/add-orientation-labels-a-p-s-i-r-l-to-2d-slice-views/31655>\
**Category:** Feature requests\
**Created:** [September 12, 2023, 2:34pm UTC](https://discourse.slicer.org/t/add-orientation-labels-a-p-s-i-r-l-to-2d-slice-views/31655 "2023-09-12T14:34:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![moraleda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/moraleda/32/77356_2.png) [@moraleda](https://discourse.slicer.org/u/moraleda)\
**Post date:** [September 12, 2023, 2:34pm UTC](https://discourse.slicer.org/t/add-orientation-labels-a-p-s-i-r-l-to-2d-slice-views/31655/1 "2023-09-12T14:34:28Z")

</div>

Hello everyone,

I was wondering whether there is a nice way to add the orientation labels into the 2D slice view. In the 3D view, we see these labels (A, P, S, I, R, L) but in the 2D views, we can only use the little marker as orientation.

A naive way to show the orientation labels, that I thought of, would be some fiducials that would be recalculated every time the slice view changes. But that seems a bit complicated computationally.

I looked for “orientation” in the source code, but I did not find any useful code where to start from.

Does anyone have an idea on how to do it or a tip on where to look? Is there a nice way to draw on the slice views? (Something like, I draw in the lower right corner the orientation marker) I guess, that with python scripting one can draw only in “3D” coordinates (meaning, I set the fiducial’s position in the 3D space), so one has to do it in c++ source code?

Inspiration. The 2D view would then look like this. It would have the labels on the corresponding sides:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/4/5419aeaf4bf9bea5133dd430ff6c06e7518e578b.jpeg)

Thank you!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 12, 2023, 5:11pm UTC](https://discourse.slicer.org/t/add-orientation-labels-a-p-s-i-r-l-to-2d-slice-views/31655/2 "2023-09-12T17:11:36Z")

</div>

We don’t have letters on the side of the images right now, but you can enable an orientation marker like axes or a human figure or a cube using the options illustrated below. If that doesn’t suit your needs it would be possible to generalize by looking at how these markers are implemented and add a feature to put the letters on the side.

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/e/2e722d9ba97039cfced4070a7e07305491ef5365.png)

---

<div class="post-metadata">

**Author:** ![moraleda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/moraleda/32/77356_2.png) [@moraleda](https://discourse.slicer.org/u/moraleda)\
**Post date:** [September 18, 2023, 12:45pm UTC](https://discourse.slicer.org/t/add-orientation-labels-a-p-s-i-r-l-to-2d-slice-views/31655/3 "2023-09-18T12:45:28Z")

</div>

Thanks @pieper, I know about the orientation marker. I looked at the source code, but wondering if for my purposes is not better to use the source code for the “3D view cube” (the pink cube in the image I posted). However, I cannot find where it is defined. Could you help me to find the right word to search the source code?

Thanks!

---

<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:** [September 18, 2023, 1:22pm UTC](https://discourse.slicer.org/t/add-orientation-labels-a-p-s-i-r-l-to-2d-slice-views/31655/4 "2023-09-18T13:22:52Z")

</div>

The purple cube is designed for 3D views. It is much easier to display direction codes in 2D views. The only complication is that there are lots more corner and side annotations that we want to show in slice views, so we need to make sure that all the information fits. We have an issue that tracks this task, it would be great if you could work on it:

> <https://github.com/Slicer/Slicer/issues/7184>
>
> \## Is your feature request related to a problem? Please describe.
> 
> Since its i…nception started in 2014, the support for rendering slice annotations has been very useful.
> 
> It is ultimately done in the \`SliceAnnotations\`\[^1\] class instantiated based on the workflow described below.
> 
> Once the \`SliceAnnotations\` is instantiated, it is then responsible to add observation on slice logics (see \`addSliceViewObserver()\`\[^6\]) by systematically checking if new slice viewer have been instantiated within the function \`updateViewAnnotations()\`\[^7\] it self called when any of the slice logic is modified.
> 
> \*\*Problem:\*\* As outlined below by @lassoan, the current design is not extensible & flexible as it requires to hard-code module specific behavior into a single script. It for example, prevent extension from registering new annotation that should take precedence.
> 
> \[^6\]: https://github.com/Slicer/Slicer/blob/8c92a12d6acecde092439981af70b1a27b6d2cf1/Modules/Scripted/DataProbe/DataProbeLib/SliceViewAnnotations.py#L346-L357
> \[^7\]: https://github.com/Slicer/Slicer/blob/8c92a12d6acecde092439981af70b1a27b6d2cf1/Modules/Scripted/DataProbe/DataProbeLib/SliceViewAnnotations.py#L363-L380
> 
> \## Describe the solution you'd like
> 
> \* Re-implemented in C++
> \* Organize the content to display in \`vtkMRMLTextNode\` nodes with associated displayable manager
> \* Allow customization of displayed fields
> \* Support displaying
> \* Slice position
> \* Anatomical direction codes
> \* Image display parameters (window, level, slice thickness, etc)
> \* Patient/study/series metadata
> 
> \## Describe alternatives you've considered
> 
> NA
> 
> \## Additional context
> 
> \### Related posts & issues
> 
> \* https://discourse.slicer.org/t/how-to-show-orientation-marker-label-left-right-anterior-posterior/20231
> \* https://github.com/Slicer/Slicer/issues/4854
> 
> \### Excerpt copied from the prior comments and emails
> 
> \_Originally shared by @lassoan over email on August 19th, 2023\_
> 
> \> We want to display a lot of things around image sides and corners:
> \> - Patient/study/series metadata (with much more flexibility than now) 
> \> - Anatomical direction codes (L, R, A, P, LA, LPI,... similarly to slice offset sliders) 
> \> - Image display parameters (window, level, slice thickness, etc)
> \> - Slice position, maybe some data probe content
> \> - Any text node content (that would allow a flexible way for modules to display custom content; which corner, color, etc. could be specified in display node)
> \> 
> \> The current design is very limited, inflexible, non-extensible in any way. The implementation is also very fragile, low quality.
> \> 
> \> The best would be to reimplement it in C++, using MRML nodes to store data, displayable manager to render, etc.
> \> 
> \> Maybe all the corner text could be specified using HTML-like description using placeholders, for example:
> \> 
> \> \`\`\`html
> \> \<b\>\<PatientName/\> \<PatientAge/\> \<PatientSex format="short" /\>\</b\>\<br\>
> \> \<StudyDate/\>\<br\>
> \> \<WindowWidthLevel/\>\<br\>
> \> \<TextNode id="vtkMRMLTextNode1" color="red" /\>
> \> \`\`\`
> 
> \_Originally posted by @lassoan in https://github.com/Slicer/Slicer/issues/7176#issuecomment-1684865471\_
> 
> \> Slice view annotations is a mess. It was a quick prototype that got integrated to have this important feature in Slicer, but the design is really fragile and limited. We would need to rebuild it from scratch, using proper MRML-based design and flexibility and extensibility in mind, as overlay on image corners is very important space for displaying information.
> 
> \_Originally posted by @pieper in https://github.com/Slicer/Slicer/issues/7176#issuecomment-1685033306\_
> 
> \> Many viewers also use these as UI controls/widgets too (e.g. control reslice rotation or window/level tools by clicking on the corresponding corner annotation can be logical and 
> 
> \### Workflow: Instantiation of \`DataProbeLib.SliceAnnotations\`
> 
> 1. \`DataProbe\` module constructor, \`slicer.app.startupCompleted()\` is connected to \`DataProbe.DataProbe.addView()\`\[^2\]
> 3. \`DataProbe.DataProbe.addView()\` instantiates\[^3\] \`DataProbeInfoWidget.DataProbeInfoWidget\`\[^4\] class 
> 4. In \`DataProbeInfoWidget\` constructor, the function \`DataProbeInfoWidget.\_createSmall()\` which intern instantiates \`DataProbeLib.SliceAnnotations()\`\[^5\]
> 
> \[^1\]: https://github.com/Slicer/Slicer/blob/main/Modules/Scripted/DataProbe/DataProbeLib/SliceViewAnnotations.py
> \[^2\]: https://github.com/Slicer/Slicer/blob/8c92a12d6acecde092439981af70b1a27b6d2cf1/Modules/Scripted/DataProbe/DataProbe.py#L40-L41
> \[^3\]: https://github.com/Slicer/Slicer/blob/8c92a12d6acecde092439981af70b1a27b6d2cf1/Modules/Scripted/DataProbe/DataProbe.py#L59-L60
> \[^4\]: https://github.com/Slicer/Slicer/blob/8c92a12d6acecde092439981af70b1a27b6d2cf1/Modules/Scripted/DataProbe/DataProbe.py#L68-L106
> \[^5\]: https://github.com/Slicer/Slicer/blob/8c92a12d6acecde092439981af70b1a27b6d2cf1/Modules/Scripted/DataProbe/DataProbe.py#L401-L406

Note that direction codes are not always just simple axis directions (L, R, A, P, I, S) but in case of oblique slices they can be a combination of 2 or 3 directions (LP, AR, LPI, SLP, …). You can see these direction codes next to the slice selector slider after you rotated slice views.

---

<div class="post-metadata">

**Author:** ![moraleda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/moraleda/32/77356_2.png) [@moraleda](https://discourse.slicer.org/u/moraleda)\
**Post date:** [September 19, 2023, 7:46am UTC](https://discourse.slicer.org/t/add-orientation-labels-a-p-s-i-r-l-to-2d-slice-views/31655/5 "2023-09-19T07:46:06Z")

</div>

Is there a reason why not just “rotate” the L,R,A,P,I,S labels around the slice? For me it seems complicated to display the combination of the of the directions.  
I have seen this “rotation” in another software that is widely used by clinicians.

“Rotation” would be like in this image:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/4/84ed503c71549d8aacbe47238443168eb6bfc2a4.png)

---

<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:** [September 19, 2023, 11:13am UTC](https://discourse.slicer.org/t/add-orientation-labels-a-p-s-i-r-l-to-2d-slice-views/31655/6 "2023-09-19T11:13:26Z")

</div>

In most cases direction codes displayed on the sides or rotated should work similarly well. Even very experienced radiologist have a lot of trouble interpreting oblique images, so most of the time the images would be aligned with anatomical axes or slightly rotated along one axis. Direction codes should be fairly straightforward to interpret either displayed at image sides or rotated around. Directions are only needed for the clinicians to distinguish sides of symmetric structures anyway, as they are getting the general sense of orientation by recognizing patient anatomy in the images.

However, when you display oblique slices, labeling direction becomes much harder, because neither slice intersection lines nor any axes that lie within the slice plane will concide with any of the anatomical axis directions.

For example, what direction codes would you draw an these image slices and where?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/f/dfb583183855ae8f25bd6f0cf166f9cdd1f78dd2.jpeg)

Rotating the labels can reduce the direction codes from 3-letter-code to 2, or from 2-letter-code to just 1 in some special cases, which I agree could be somewhat useful, as it could potentially make some directions easier to interpret. However, it would raise several new problems:

- In general, you would not be able to show single-letter codes anywhere anyway. You could choose to show only the dominant direction (i.e., the first letter of the direction code), but that may be misleading.
- It would make the already difficult corner text annotation layout problem even harder to solve: where would you show those labels to avoid overlap with corner annotations?
- Users could have trouble finding those direction codes, because they move around.
- Direction labels may be mistaken for other image annotations if the labels do not appear in a standard location.
- Orientation codes are displayed at image sides in most if not all other radiology software. Users would have harder time getting used to the labels showing up in different location.

Considering that rotating the labels around would not make the directions much easier to interpret in complex cases and it would raise several new problems, overall it seems better to display labels in standard locations (at center of image sides).

---

<div class="post-metadata">

**Author:** ![moraleda](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/moraleda/32/77356_2.png) [@moraleda](https://discourse.slicer.org/u/moraleda)\
**Post date:** [November 2, 2023, 3:30pm UTC](https://discourse.slicer.org/t/add-orientation-labels-a-p-s-i-r-l-to-2d-slice-views/31655/7 "2023-11-02T15:30:05Z")

</div>

I got back to the problem after a while, considering what you said. I thought of a solution (probably not general) utilizing `vtk.CornerAnnotations` to write on the sides of the viewers. I need to write only to the edge centers, as my views are always perpendicular to each other.

(However, it could be later extended to show the letters after reorienting your views such that one view would be horizontal and we would write at the right edge.)

During this, I found out, that one is not able to write to lower right corner. When you run

```auto
view.cornerAnnotation().SetText(vtk.vtkCornerAnnotation.LowerRight,'note')

```

the `note` is visible for a moment, and then disapears again. Is it because the place is reserved for the orientation marker?

Another question I have is how do you get the orientation programatically?  
In the image below, I have just hardcoded `LIA` into the code. I cannot find the right command to get this orientation.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/e/7e980c6ef77d49ee6a959b763e20ec9cdaab8218.jpeg)

Thank you!

---

<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:** [November 2, 2023, 3:40pm UTC](https://discourse.slicer.org/t/add-orientation-labels-a-p-s-i-r-l-to-2d-slice-views/31655/8 "2023-11-02T15:40:29Z")

</div>

Corner annotations are alredy used by DataProbe module. All corners are already used for displaying some content. Only the centers remain available for direction codes, and actually that is the position where you want to display the codes anyway.

Note that VTK corner annotations very limited. It can only do a small fraction of what we need (see [here](https://github.com/Slicer/Slicer/issues/7184) for some details), so if you implement direction code display using corner annotations, it’ll probably have to remain just prototype/test code and needs to be redesigned before it can be integrated into Slicer core.
