# Save image of 3d view

**URL:** <https://discourse.slicer.org/t/save-image-of-3d-view/2666>\
**Category:** Development\
**Created:** [April 23, 2018, 1:34pm UTC](https://discourse.slicer.org/t/save-image-of-3d-view/2666 "2018-04-23T13:34:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)\
**Post date:** [April 23, 2018, 1:34pm UTC](https://discourse.slicer.org/t/save-image-of-3d-view/2666/1 "2018-04-23T13:34:22Z")

</div>

i have already have a script for creating and saving segments using slicer 4.9, i need a image of the 3D view of the model, so i can get a reference image of the 3D model created by script. anyone here who already did this , please share the code lines…

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:** [April 23, 2018, 1:40pm UTC](https://discourse.slicer.org/t/save-image-of-3d-view/2666/2 "2018-04-23T13:40:45Z")

</div>

There are several examples for this in the Slicer script repository: [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Capture](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Capture).

---

<div class="post-metadata">

**Author:** ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)\
**Post date:** [April 23, 2018, 2:30pm UTC](https://discourse.slicer.org/t/save-image-of-3d-view/2666/3 "2018-04-23T14:30:27Z")

</div>

yeah its working , but now problem is model is not at the center of the view so output image came with no actual 3D model in it.

---

<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:** [April 23, 2018, 3:42pm UTC](https://discourse.slicer.org/t/save-image-of-3d-view/2666/4 "2018-04-23T15:42:08Z")

</div>

[https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Center\_the\_3D\_View\_on\_the\_Scene](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Center_the_3D_View_on_the_Scene)

---

<div class="post-metadata">

**Author:** ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)\
**Post date:** [April 24, 2018, 10:10am UTC](https://discourse.slicer.org/t/save-image-of-3d-view/2666/5 "2018-04-24T10:10:22Z")

</div>

Thanks @lassoan ,  
but still i cant see my object model in the image just a blank 3d view scene.

also the thing is i want to use --no-window mode for my script , any idea how it will take a snap of the 3D model then.

---

<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:** [April 24, 2018, 12:59pm UTC](https://discourse.slicer.org/t/save-image-of-3d-view/2666/6 "2018-04-24T12:59:38Z")

</div>

If you use `--no-window` then there will be no GUI and you have to create a render window, renderer, actor, mapper, set up display properties, camera, and capture the render window. It is perfectly doable, there are [lots of examples](https://lorensen.github.io/VTKExamples/site/) for these. You’ll probably see your custom render window appearing for a moment. Depending on your environment, you might be able to create an off-screen render window, which does not show up on your desktop at all.

However, it may be simpler to just keep the main window - you can disable the splash screen and hide the main window as soon as it is created, so you would only see a window appearing for a moment.

---

<div class="post-metadata">

**Author:** ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)\
**Post date:** [April 24, 2018, 2:22pm UTC](https://discourse.slicer.org/t/save-image-of-3d-view/2666/7 "2018-04-24T14:22:29Z")

</div>

yeah, i can see in your examples to create render window setup needs lots of elements,  
how can we disable splash screen and main window? its sounds easy way…

---

<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:** [April 25, 2018, 1:26am UTC](https://discourse.slicer.org/t/save-image-of-3d-view/2666/8 "2018-04-25T01:26:08Z")

</div>

You can disable splash screen by adding `--no-splash` and `--launcher-no-splash`. See list of all options here: [https://www.slicer.org/wiki/Documentation/Nightly/Developers/Launcher](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Launcher)

---

<div class="post-metadata">

**Author:** ![anandmulay3](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@anandmulay3](https://discourse.slicer.org/u/anandmulay3)\
**Post date:** [May 14, 2018, 10:46am UTC](https://discourse.slicer.org/t/save-image-of-3d-view/2666/9 "2018-05-14T10:46:27Z")

</div>

Hi @lassoan i have tried to setup all the things i.e. camera, mappper , actor , render window , renederer and set of display properties from one of your example( cameraModel1.py).

So now the thing is i tried to set threeDView window to the new render window it working fine in GUI mode , but as i said i want it in `--no-window` mode, so i tried to run it and error occurs when we try to get threeDView window; as expected, without that line i can render the window which pops for a sec. and then i capture that windows and it disappears.

now my query is - How can i set my segments as an Actor to that render-window?/ How can i show /render the segment in this renderwindow?

---

<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:** [May 14, 2018, 1:33pm UTC](https://discourse.slicer.org/t/save-image-of-3d-view/2666/10 "2018-05-14T13:33:32Z")

</div>

> [@anandmulay3](#):
>
> How can i set my segments as an Actor to that render-window?

You can get the segment as vtkPolyData using [GetClosedSurfaceRepresentation](http://apidocs.slicer.org/master/classvtkMRMLSegmentationNode.html#a71ebfa4439ec3ebdf57994888f572623) method and follow basic [VTK examples](https://lorensen.github.io/VTKExamples/site/) to set up rendering for that polydata.
