# Rotation&zooming 

**URL:** <https://discourse.slicer.org/t/rotation-zooming/1912>\
**Category:** Support\
**Created:** [January 23, 2018, 4:13pm UTC](https://discourse.slicer.org/t/rotation-zooming/1912 "2018-01-23T16:13:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Soufane](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Ahmed\_Soufane](https://discourse.slicer.org/u/Ahmed_Soufane)\
**Post date:** [January 23, 2018, 4:13pm UTC](https://discourse.slicer.org/t/rotation-zooming/1912/1 "2018-01-23T16:13:01Z")

</div>

Hello,

How can I modify or call the rotation of an image on the python interactor on 3dslicer ?

Is it possible to modify or edit zooming in and out of the image on python console ?

---

<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:** [January 23, 2018, 5:38pm UTC](https://discourse.slicer.org/t/rotation-zooming/1912/2 "2018-01-23T17:38:32Z")

</div>

here’s a snippet to get the slice logic from the interface:

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Manipulate\_a\_Slice\_View](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Manipulate_a_Slice_View)

Once you have that you can call methods either on the sliceLogic [1] or you can get the sliceNode [2] and call methods like redLogic.GetSliceNode().SetFieldOfView(20,30,1) to change the zoom.

[1] [http://apidocs.slicer.org/master/classvtkMRMLSliceLogic.html](http://apidocs.slicer.org/master/classvtkMRMLSliceLogic.html)

[2] [http://apidocs.slicer.org/master/classvtkMRMLSliceNode.html](http://apidocs.slicer.org/master/classvtkMRMLSliceNode.html)

---

<div class="post-metadata">

**Author:** ![Ahmed\_Soufane](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Ahmed\_Soufane](https://discourse.slicer.org/u/Ahmed_Soufane)\
**Post date:** [January 27, 2018, 11:25pm UTC](https://discourse.slicer.org/t/rotation-zooming/1912/3 "2018-01-27T23:25:02Z")

</div>

Hello,  
I have tried redLogic.GetSliceNode().SetFieldOfView(20,30,1) in order to change the zoom, but it did not change anything. I was using the four up view, and the red window turned black when I used redlogic for some reason. How can I use it properly in order to change the zoom ?

---

<div class="post-metadata">

**Author:** ![Ahmed\_Soufane](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Ahmed\_Soufane](https://discourse.slicer.org/u/Ahmed_Soufane)\
**Post date:** [January 27, 2018, 11:33pm UTC](https://discourse.slicer.org/t/rotation-zooming/1912/4 "2018-01-27T23:33:12Z")

</div>

This is what I get when I plug in

 ![21%20PM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/9/b92485f6df8bd2ad7922373041f122c68df67348.png) :

 ![group __Slicer__ QtModules](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/d/6df1137267ec170a3d724a3b34379bdafbf36ae3.png)

when I plug in redLogic.SetSliceOffset(10):

 ![21%20PM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/9/b92485f6df8bd2ad7922373041f122c68df67348.png)

I presume that redlogic is controlling the shape of the image and the brightness at the same time one of the windows turned black, instead of controlling the zoom.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Soufane](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Ahmed\_Soufane](https://discourse.slicer.org/u/Ahmed_Soufane)\
**Post date:** [January 27, 2018, 11:38pm UTC](https://discourse.slicer.org/t/rotation-zooming/1912/5 "2018-01-27T23:38:31Z")

</div>

I have figured how it works thanks a lot. However, I do not know how to control the rotation of the image via python interactor ?

Thanks again!

---

<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:** [January 28, 2018, 6:09am UTC](https://discourse.slicer.org/t/rotation-zooming/1912/6 "2018-01-28T06:09:09Z")

</div>

> I do not know how to control the rotation of the image via python interactor

Adjust SliceToRAS transform in the slice node. It is a homogeneous transform, so the top-left 3x3 matrix specifies the slice orientation (first column is slice X, second column is slice Y, third column is slice normal direction) and 4th column specifies slice position.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Soufane](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Ahmed\_Soufane](https://discourse.slicer.org/u/Ahmed_Soufane)\
**Post date:** [March 6, 2018, 4:36am UTC](https://discourse.slicer.org/t/rotation-zooming/1912/7 "2018-03-06T04:36:09Z")

</div>

![20%20PM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/0/30e75f3d7c3765b00dbbdfc0abcb6a120e82baf6.png)As you can see in the attached image whenever I try to execute any different numbers for the x,y and normal slices for the axial view, I do not get to zoom in or out, instead a black image. I believe the problem is I am zooming in a lot, however what I want to know how to control is to zoom in or out of the image itself only via python interactor.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Soufane](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Ahmed\_Soufane](https://discourse.slicer.org/u/Ahmed_Soufane)\
**Post date:** [March 6, 2018, 4:44am UTC](https://discourse.slicer.org/t/rotation-zooming/1912/8 "2018-03-06T04:44:34Z")

</div>

instead I would like to control the zooming in the following mechanism which can be done by using the mouse. But, in my case I want to control the zooming mechanism into the image and out of the image like it can be seen on the following images on the 2D yellow image view.

 ![23%20PM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/1/615f9cd4d143732a9f0bbfffa091a2ac8e58ffbb.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:** [March 6, 2018, 5:20am UTC](https://discourse.slicer.org/t/rotation-zooming/1912/9 "2018-03-06T05:20:06Z")

</div>

FieldOfView defines the zoom factor. Get the old value, multiply x and y components by a factor (e.g., by 1.1 to zoom out a bit), and set the resulting values as new FOV.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Soufane](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Ahmed\_Soufane](https://discourse.slicer.org/u/Ahmed_Soufane)\
**Post date:** [March 7, 2018, 12:41am UTC](https://discourse.slicer.org/t/rotation-zooming/1912/10 "2018-03-07T00:41:20Z")

</div>

I tried the same thing you suggested, but the image disappeared and I could not bring it back.

 ![48%20PM](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/1/c1a501f6ae2bf8f62bb0c7bb0ff14b7f8a10c4dd.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:** [March 7, 2018, 12:58am UTC](https://discourse.slicer.org/t/rotation-zooming/1912/11 "2018-03-07T00:58:19Z")

</div>

You’ve forgot to get the old FOV value (or at least the screenshot that you attached did not show how you got the old value).

---

<div class="post-metadata">

**Author:** ![Ahmed\_Soufane](https://avatars.discourse-cdn.com/v4/letter/a/b38774/32.png) [@Ahmed\_Soufane](https://discourse.slicer.org/u/Ahmed_Soufane)\
**Post date:** [March 7, 2018, 9:00pm UTC](https://discourse.slicer.org/t/rotation-zooming/1912/12 "2018-03-07T21:00:50Z")

</div>

How do I set the resulting values as new FOV ?

---

<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:** [March 11, 2018, 4:32am UTC](https://discourse.slicer.org/t/rotation-zooming/1912/13 "2018-03-11T04:32:12Z")

</div>

Use GetFieldOfView method to get current values, scale them, and set the new values using SetFieldOfView.
