Save image of 3d view

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.

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

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.

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Center_the_3D_View_on_the_Scene

1 Like

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.

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 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.

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…

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

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?

You can get the segment as vtkPolyData using GetClosedSurfaceRepresentation method and follow basic VTK examples to set up rendering for that polydata.