# Fill Slice Views without Changing Image Spacing

**URL:** <https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382>\
**Category:** Support\
**Created:** [September 11, 2019, 2:45pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382 "2019-09-11T14:45:35Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Lesage](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jonathan_lesage/32/4693_2.png) [@Jonathan\_Lesage](https://discourse.slicer.org/u/Jonathan_Lesage)\
**Post date:** [September 11, 2019, 2:45pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/1 "2019-09-11T14:45:35Z")

</div>

Hi,

I am using slicer to look at nondestructive testing data where volumes are typically sampled much more sparsely in the z (axial) direction than other directions (roughly 10 to 1). Additionally, the axial dimension is usually much larger than the other dimensions (i.e. we perform very long scans of components with a very tight imaging region). The volumes we are dealing with are like if we imaged at 10 cm x 10 cm square over the length of a human body in a CT scanner. I would like to be able to fill all slice view panes effectively changing the aspect ratio of the displayed image without changing the image spacing so that the measurements and slice positions read the correct positions. Commercial softwares for this type of applications routinely display the data with aspect ratios in each slice view which are not 1:1. Is this possible in slicer either by extension or python script or the like?

Any help with this would be greatly appreciated!

Thanks,

- Jon

---

<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 11, 2019, 3:03pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/2 "2019-09-11T15:03:32Z")

</div>

You can change the field of view in a slice view, for example enlarge it by a factor of 10x along one axis:

```python
sliceNode = getNode('vtkMRMLSliceNodeYellow')
fov = sliceNode.GetFieldOfView()
sliceNode.SetFieldOfView(fov[0], fov[1]*10.0, fov[2])

```

This is not officially supported, so you might run into unexpected situations - mostly that the FOV is reset when you do certain operations (that you may address by adding an observer to the slice node and set the FOV back to your preferred FOV).

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lesage](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jonathan_lesage/32/4693_2.png) [@Jonathan\_Lesage](https://discourse.slicer.org/u/Jonathan_Lesage)\
**Post date:** [September 11, 2019, 3:15pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/3 "2019-09-11T15:15:38Z")

</div>

> [@lassoan](#):
>
> sliceNode = getNode(‘vtkMRMLSliceNodeYellow’) fov = sliceNode.GetFieldOfView() sliceNode.SetFieldOfView(fov[0], fov[1]\*10.0, fov[2])

Thank you so much! Works like a charm!

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lesage](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jonathan_lesage/32/4693_2.png) [@Jonathan\_Lesage](https://discourse.slicer.org/u/Jonathan_Lesage)\
**Post date:** [September 13, 2019, 3:41pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/4 "2019-09-13T15:41:38Z")

</div>

Mr. Lassoan,

I am wondering if a similar set of commands can be used to set the field of view per axis on the volume view?

Many thanks,

- Jon

---

<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 13, 2019, 6:06pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/5 "2019-09-13T18:06:58Z")

</div>

In 3D view, changing the view’s aspect ratio would not make sense (as the view’s aspect ratio is fixed in display space and the object can be rotated around). To display a deformed volume in 3D, you can apply a transform to it (Transforms module) or change its spacing (Volumes module).

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lesage](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jonathan_lesage/32/4693_2.png) [@Jonathan\_Lesage](https://discourse.slicer.org/u/Jonathan_Lesage)\
**Post date:** [September 13, 2019, 8:42pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/6 "2019-09-13T20:42:49Z")

</div>

Hi Andras,

I have done as you’ve suggested in the past and of course I can distort the volume by changing the spacing or applying and transform, the issue is that the rulers and cursor positions do not read their true values afterwards which is critical for our industry. The volume view is not actually required so I can get by using the tips for changing the field of view in the slice panes.

Thanks!

- Jon

---

<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 13, 2019, 9:20pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/7 "2019-09-13T21:20:02Z")

</div>

It would not be hard to add an option to markups to report measurements in the node’s coordinate system instead of the World coordinate system but yours would be the first use case. If we hear from many other users that they would need this, too, then we can add it to the plan. If you need this sooner then you can implement it yourself or contract Kitware or others to develop it for you.

---

<div class="post-metadata">

**Author:** ![fbordignon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fbordignon/32/5269_2.png) [@fbordignon](https://discourse.slicer.org/u/fbordignon)\
**Post date:** [September 30, 2021, 12:36pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/8 "2021-09-30T12:36:07Z")

</div>

> [@lassoan](#):
>
> This is not officially supported, so you might run into unexpected situations - mostly that the FOV is reset when you do certain operations (that you may address by adding an observer to the slice node and set the FOV back to your preferred FOV).

I’ve ran into this today. I’ve set the FOV to make the volume slice occupy the whole width of the sliceview. Can I prevent FOV resetting in some way? I’ve added the observer to revert back the FOV but there is sort of a flickering effect that is unpleasant to the users.  
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 30, 2021, 1:16pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/9 "2021-09-30T13:16:48Z")

</div>

Check all the places that can change the FOV and propose designs that would allow preserving a custom aspect ratio. Keep everything backward compatible and aim for the minimum number of changes and number of impacted classes.

Was it necessary to apply changes/workarounds to make a custom aspect ratio in slice views work correctly?

---

<div class="post-metadata">

**Author:** ![fbordignon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fbordignon/32/5269_2.png) [@fbordignon](https://discourse.slicer.org/u/fbordignon)\
**Post date:** [September 30, 2021, 5:37pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/10 "2021-09-30T17:37:55Z")

</div>

Thanks for the directions. I will take a look at this.

The custom aspect ratio is working fine. We are even applying segmentation tools with it. It is funny that the paint tool looks like an ellipse when we distort the aspect ratio but I believe it is the expected behavior. I will report if I find any issues, so far so good.

---

<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 30, 2021, 5:47pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/11 "2021-09-30T17:47:22Z")

</div>

> [@fbordignon](#):
>
> It is funny that the paint tool looks like an ellipse when we distort the aspect ratio but I believe it is the expected behavior. I will report if I find any issues, so far so good.

That is exactly the correct behavior and probably what you want.

If you have the time and it is not confidential then it would be nice if you could show a few screenshots how it all looks and works.

---

<div class="post-metadata">

**Author:** ![fbordignon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fbordignon/32/5269_2.png) [@fbordignon](https://discourse.slicer.org/u/fbordignon)\
**Post date:** [September 30, 2021, 7:57pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/12 "2021-09-30T19:57:43Z")

</div>

Hey Andras. I’ve recorded a quick demo of the current functionality we are working on. The video can be shared freely. I’ve used a screen cap from the internet as a volume, the real data is way larger on the SI direction. [https://youtu.be/rBt-z9p9vVw](https://youtu.be/rBt-z9p9vVw)  
Except for the part I resize the layout the responsiveness is great. I may be calling too many times the FOV repair function, I will look into that to call it always some time after the last resize event.

The goal is to make a panel like this one below. But for now, we are doing an MVP on the segmentation of this kind of data [https://erlend-viggen.no/dlis-files/](https://erlend-viggen.no/dlis-files/)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/2/0214760c4e81f1cc8222b65782e7cf2786bacb61.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:** [October 1, 2021, 2:58am UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/13 "2021-10-01T02:58:59Z")

</div>

Thanks for sharing, this looks great!

---

<div class="post-metadata">

**Author:** ![fbordignon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fbordignon/32/5269_2.png) [@fbordignon](https://discourse.slicer.org/u/fbordignon)\
**Post date:** [October 1, 2021, 4:26pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/14 "2021-10-01T16:26:15Z")

</div>

@lassoan, I’ve looked into the FOV resetting and found that the vtkMRMLSliceLogic is checking the aspect ratio of the window against the pane AR [here](https://github.com/Slicer/Slicer/blob/1b21b7208594f3b6c1ed387ae648c3e9d757f1d0/Libs/MRML/Logic/vtkMRMLSliceLogic.cxx#L1778)

How do you feel about the following modification proposal?

```cpp
  double windowAspect = (newWidth != 0. ? newHeight / newWidth : 1.);
  double planeAspect = (newFOV[0] != 0. ? newFOV[1] / newFOV[0] : 1.);
  double oldWindowAspect = (oldDimensions[0] != 0. ? oldDimensions[1] / oldDimensions[0] : 1.);
  double oldPlaneAspect = (oldFOV[0] != 0. ? oldFOV[1] / oldFOV[0] : 1.);
  if (windowAspect != planeAspect && oldWindowAspect == oldPlaneAspect)
    {
    newFOV[0] = (windowAspect != 0. ? newFOV[1] / windowAspect : newFOV[0]);
    }

```

This way the newFOV is corrected only if the user/dev did not change the aspect ratio of the slice view. If the aspect ratio is custom, there is no correction of the AR. While on a custom AR, if the user clicks center to volume on sliceviewcontroller, the AR returns to the original one.  
I find it minimally invasive and it keeps the current behavior for the standard not distorted AR. If you think is a good idea I can open a PR for this.  
This fix does not perform the behavior I want for the use case above, but the changes I need to apply to the FOV are less dramatic, improving the overall user experience.  
Thank you very much.

---

<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:** [October 1, 2021, 5:42pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/15 "2021-10-01T17:42:41Z")

</div>

If this is the only place where this causes problems then it should not be too hard to customize the behavior.

The window’s aspect ratio can change at any time and it would be hard to guarantee that the plane aspect ratio immediately follows it, so the check above might not be a robust solution.

Instead, what do you think about adding an experimental “AspectRatio” member to vtkMRMLSliceLogic, set to 1.0 by default. In the documentation of the get/set method it would be described that this is an experimental option only and only 1.0 value is tested. If you add sufficient amount of automatic testing that ensures that all important features work well with a non-default aspect ratio then we may consider making this a non-experimental, officially supported feature.

---

<div class="post-metadata">

**Author:** ![fbordignon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fbordignon/32/5269_2.png) [@fbordignon](https://discourse.slicer.org/u/fbordignon)\
**Post date:** [October 1, 2021, 6:14pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/16 "2021-10-01T18:14:42Z")

</div>

Ok thanks for the reply. I will consider working on your suggestion if I find any problems with the current one that I proposed.

One curious thing is that if the user sets the FOV via slice controller, the custom AR is kept when resizing the view. I did not look into how this is achieved.

---

<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:** [October 1, 2021, 7:17pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/17 "2021-10-01T19:17:36Z")

</div>

> [@fbordignon](#):
>
> I will consider working on your suggestion if I find any problems with the current one that I proposed

It is not likely that we would integrate the change proposed [above](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/14) because it would introduce the risk of the aspect ratio of a view randomly changing. For example, if `vtkMRMLSliceLogic::ResizeSliceNode` is not called immediately after every slice resize (due to event compression, due to some views are being hidden, due to pausing the rendering, due to a change in how a view is created, etc.) then it could distort the view’s aspect ratio. It would also be important to let developers simply and reliably get/set the aspect ratio of a slice view anytime (even before a window has been created for it). In contrast, introducing an aspect ratio property to the logic is clean and simple, if it proves to be a solid solution and tests are added then it could be even made a property of the slice node.

---

<div class="post-metadata">

**Author:** ![fbordignon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fbordignon/32/5269_2.png) [@fbordignon](https://discourse.slicer.org/u/fbordignon)\
**Post date:** [October 2, 2021, 1:30pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/18 "2021-10-02T13:30:25Z")

</div>

Yes, I understand that my proposal is not ideal, but I will use it internally on our compiled version of slicer for now as it mitigates the issue I was having. As soon as I get the time, I will try to work on the suggestions you gave. I agree that they are better in all aspects. We always struggle with the share of time dedicated to the slicer base and the additional code we add to our client. There is always the feeling we are not contributing as much as we are getting help from the community. To be honest I am the only one messing with the slicer code. Next month a new project will kickoff and we will be adding 4 developers to the team, it should allow for more contributions to slicer 👍  
Thanks for all the help and I personally appreciate your incentives to try to make us work on the code base.

---

<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:** [October 2, 2021, 2:16pm UTC](https://discourse.slicer.org/t/fill-slice-views-without-changing-image-spacing/8382/19 "2021-10-02T14:16:46Z")

</div>

Thanks for the information, this sounds great!

If you want, you can add the AspectRatio property to the slice node. That will probably make your implementation simpler.
