do you know some python code for this scale factor
Full layout is just digital zoom, so it just makes the image bigger but does not improve image quality.
Rendering of individual views actually increases the resolution but it is currently broken. Slicer’s VTK version will be upgraded in a couple of weeks, there is a chance that it will fix the high-resolution rendering.
its any python code for this rendering I’m using the 4.10.2 version because it supports FreeSurferLabel
also if theres any code for this scale factor (magnification factore) I would like to try it
Current Slicer release has this label, too, just install SlicerFreeSurfer extension.
You can use any of the capture code snippets in the script repository. Right now, there is no benefit in using the annotation screenshot tool and adjusting the scaling factor.
I have this code
viewNodeID = ‘vtkMRMLSliceNodeRed’
cap = ScreenCapture.ScreenCaptureLogic()
view = cap.viewFromNode(slicer.mrmlScene.GetNodeByID(viewNodeID))
but I also want to change the Scale factor lets say to 3 and that information is not in capture code snippets in the script repository
We will make sure the scale factor is exposed in Python when scaling gets fixed.
thanks for your reply.
Hi there. I am interested to rehash this previous forum (RE. exporting high quality images from the 3D view). It is such valuable data to properly showcase.
In the end, does adjusting the “scale factor” remain the only current option? OR have there been any changes since the last post in 2021?
You made me curious, so I tried offscreen rendering and it basically works, although it sometimes leads to a crash when interacting with the view after rendering. But something like the code below could be added as a feature if someone wants to play with it. It could use more tweaks, but if it’s useful for people we could put it in the script repository for now.
Here’s the full res 5kx5x version:
vtk.vtkGraphicsFactory() gf = vtk.vtkGraphicsFactory() gf.SetOffScreenOnlyMode(1) gf.SetUseMesaClasses(1) rw = vtk.vtkRenderWindow() rw.SetOffScreenRendering(1) ren = vtk.vtkRenderer() rw.SetSize(5000,5000) lm = slicer.app.layoutManager() ren3d = lm.threeDWidget(0).threeDView().renderWindow().GetRenderers().GetItemAsObject(0) actors = ren3d.GetActors() for index in range(actors.GetNumberOfItems()): ren.AddActor(actors.GetItemAsObject(index)) lights = ren3d.GetLights() for index in range(lights.GetNumberOfItems()): ren.AddLight(lights.GetItemAsObject(index)) volumes = ren3d.GetVolumes() for index in range(volumes.GetNumberOfItems()): ren.AddVolume(volumes.GetItemAsObject(index)) camera = ren3d.GetActiveCamera() ren.SetActiveCamera(camera) rw.AddRenderer(ren) rw.Render() wti = vtk.vtkWindowToImageFilter() wti.SetInput(rw) wti.Update() writer = vtk.vtkPNGWriter() writer.SetInputConnection(wti.GetOutputPort()) writer.SetFileName("/tmp/out.png") writer.Update() writer.Write() i = wti.GetOutput()
Here’s an inset of what the full resolution looks like:
Here’s an example with volume rendering at 5k x 5k:
The crashes are because actors are not meant to be shared across render windows like this script does, but for doing one-off renders this works. If someone wants to give it a shot, integrating off-screen rendering properly with the application wouldn’t be too hard since we know it will work.