# Change image without changing zoom and positions of sliders

**URL:** <https://discourse.slicer.org/t/change-image-without-changing-zoom-and-positions-of-sliders/13784>\
**Category:** Development\
**Created:** [September 30, 2020, 11:54pm UTC](https://discourse.slicer.org/t/change-image-without-changing-zoom-and-positions-of-sliders/13784 "2020-09-30T23:54:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohan\_n](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rohan_n/32/78474_2.png) [@rohan\_n](https://discourse.slicer.org/u/rohan_n)\
**Post date:** [September 30, 2020, 11:54pm UTC](https://discourse.slicer.org/t/change-image-without-changing-zoom-and-positions-of-sliders/13784/1 "2020-09-30T23:54:31Z")

</div>

I have a scripted module that looks like this.

 ![exampleimg9_30_2020](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/6/d6a11bee25598efda8057234d3ad6f189e1ea3b8.jpeg)  
In the example shown, the user has zoomed in on both the red and the yellow slices, and the red & yellow slice slider positions are off center.  
The user is about to display a different image by choosing that image from the dropdown menu. Image selection from the dropdown menu prompts my scripted module to call  
`slicer.util.setSliceViewerLayers(background=self.inputSelector.currentNodeID)`  
so that the image chosen by the user will be displayed. However, it appears that this line of code automatically resets the zoom and slice slider positions to their default values.  
Is there any way I can call  
`slicer.util.setSliceViewerLayers(background=self.inputSelector.currentNodeID)`  
without resetting zoom and slider positions, so that the user doesn’t lose track of the region they have zoomed into whenever they switch images?

Thanks,  
Rohan

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [October 1, 2020, 7:37am UTC](https://discourse.slicer.org/t/change-image-without-changing-zoom-and-positions-of-sliders/13784/2 "2020-10-01T07:37:10Z")

</div>

I’m not completely sure that this doesn’t change any other setting, but as far as I remember it doesn’t.

```auto
sliceCompositeNodes = slicer.util.getNodesByClass('vtkMRMLSliceCompositeNode')
for sliceCompositeNode in sliceCompositeNodes:
  sliceCompositeNode.SetBackgroundVolumeID(newVolumeNode.GetID())

```

---

<div class="post-metadata">

**Author:** ![rohan\_n](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rohan_n/32/78474_2.png) [@rohan\_n](https://discourse.slicer.org/u/rohan_n)\
**Post date:** [October 1, 2020, 4:38pm UTC](https://discourse.slicer.org/t/change-image-without-changing-zoom-and-positions-of-sliders/13784/3 "2020-10-01T16:38:42Z")

</div>

Thank you, this way of switching image displayed does what I need.
