# Higher resolution for screen captures of 3D view?

**URL:** <https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880>\
**Category:** Support\
**Tags:** screen-capture\
**Created:** [October 23, 2019, 5:23pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880 "2019-10-23T17:23:25Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [February 11, 2021, 1:28am UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/21 "2021-02-11T01:28:46Z")

</div>

do you know some python code for this scale factor

---

<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:** [February 11, 2021, 3:16am UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/22 "2021-02-11T03:16:25Z")

</div>

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](https://github.com/Slicer/Slicer/issues/3885). Slicer’s VTK version will be upgraded in a couple of weeks, there is a chance that it will fix the high-resolution rendering.

---

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [February 11, 2021, 4:01am UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/23 "2021-02-11T04:01:23Z")

</div>

its any python code for this rendering I’m using the 4.10.2 version because it supports FreeSurferLabel

---

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [February 11, 2021, 4:04am UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/24 "2021-02-11T04:04:51Z")

</div>

also if theres any code for this scale factor (magnification factore) I would like to try 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:** [February 11, 2021, 4:16am UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/25 "2021-02-11T04:16:36Z")

</div>

> [@aldoSanchez](#):
>
> its any python code for this rendering I’m using the 4.10.2 version because it supports FreeSurferLabel

Current Slicer release has this label, too, just install SlicerFreeSurfer extension.

> [@aldoSanchez](#):
>
> also if theres any code for this scale factor (magnification factore) I would like to try it

You can use any of the [capture code snippets in the script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Capture). Right now, there is no benefit in using the annotation screenshot tool and adjusting the scaling factor.

---

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [February 11, 2021, 8:56am UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/26 "2021-02-11T08:56:42Z")

</div>

I have this code  
#########

viewNodeID = ‘vtkMRMLSliceNodeRed’  
import ScreenCapture  
cap = ScreenCapture.ScreenCaptureLogic()  
view = cap.viewFromNode(slicer.mrmlScene.GetNodeByID(viewNodeID))  
cap.captureImageFromView(view,‘C:/Users/aldot/Desktop/python/Red.png’)

#########  
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](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Capture)

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/d/edef1f3a9dfe93594c8f7df501f5b39e46f2ef30.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:** [February 11, 2021, 5:45pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/27 "2021-02-11T17:45:46Z")

</div>

We will make sure the scale factor is exposed in Python when scaling gets fixed.

---

<div class="post-metadata">

**Author:** ![aldoSanchez](https://avatars.discourse-cdn.com/v4/letter/a/5f9b8f/32.png) [@aldoSanchez](https://discourse.slicer.org/u/aldoSanchez)\
**Post date:** [February 11, 2021, 6:07pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/28 "2021-02-11T18:07:12Z")

</div>

thanks for your reply.

---

<div class="post-metadata">

**Author:** ![dale.fournier](https://avatars.discourse-cdn.com/v4/letter/d/f0a364/32.png) [@dale.fournier](https://discourse.slicer.org/u/dale.fournier)\
**Post date:** [March 19, 2023, 5:34pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/29 "2023-03-19T17:34:19Z")

</div>

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?

Thanks,  
Dale

---

<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:** [March 19, 2023, 6:15pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/30 "2023-03-19T18:15:49Z")

</div>

You made me curious, so I tried [offscreen rendering](https://kitware.github.io/vtk-examples/site/Cxx/Utilities/OffScreenRendering/) 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:

> **[out.png](https://drive.google.com/file/d/1sJh1qNYKqzur0kPGharPd_fLKPXcLjIj/view?usp=sharing)**
>
> Google Drive file.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/7/e786811920cc3e684ad3f938add3e1a5cc22ce52.jpeg)

```auto

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:

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/4/84feaa85766872c302812aa11b5fd27252c517f8.jpeg)

---

<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:** [March 19, 2023, 7:38pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/31 "2023-03-19T19:38:37Z")

</div>

Here’s an example with volume rendering at 5k x 5k:

> **[specimin5k.png](https://drive.google.com/file/d/1x5I0h_z0AUIkYgvLWO9hAztUgap2LWXi/view?usp=share_link)**
>
> Google Drive file.

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.

---

<div class="post-metadata">

**Author:** ![nsvitek](https://avatars.discourse-cdn.com/v4/letter/n/848f3c/32.png) [@nsvitek](https://discourse.slicer.org/u/nsvitek)\
**Post date:** [August 7, 2023, 1:16pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/32 "2023-08-07T13:16:40Z")

</div>

I’d like to second this question 2.5 years later: is high-resolution screen capture possible? I tried last week and had the same issue described with the scaling factor (increases size, but not resolution). It’s one big thing keeping Slicer from being a complete solution for descriptive research.

---

<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:** [August 7, 2023, 2:47pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/33 "2023-08-07T14:47:29Z")

</div>

Did you try the workaround posted above?

---

<div class="post-metadata">

**Author:** ![nsvitek](https://avatars.discourse-cdn.com/v4/letter/n/848f3c/32.png) [@nsvitek](https://discourse.slicer.org/u/nsvitek)\
**Post date:** [August 7, 2023, 4:43pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/34 "2023-08-07T16:43:10Z")

</div>

I did, twice. I tried before I posted and the program froze. I tried again line by line just now and it did write an image file this time, but the image was 72 kb and completely blank. Admittedly, I’m a novice to Slicer and python is very, very rusty.

---

<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:** [August 7, 2023, 6:13pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/35 "2023-08-07T18:13:40Z")

</div>

It may just take time to render a big image. That code tries to make a 5k x 5k image and maybe that’s bigger than you need or maybe you can try on a different computer. I tested on a mac pro with lots of memory.

---

<div class="post-metadata">

**Author:** ![nsvitek](https://avatars.discourse-cdn.com/v4/letter/n/848f3c/32.png) [@nsvitek](https://discourse.slicer.org/u/nsvitek)\
**Post date:** [August 15, 2023, 2:32pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/36 "2023-08-15T14:32:33Z")

</div>

Okay, it’s working now to take the kind of images you included, but there’s one more hurdle I can’t figure out how to overcome:

For a lot of publication-quality imagery, I need a scale bar. I’ve tried modifying your example to change the view node by modifying line 10 into:

```auto
lm = slicer.app.layoutManager()
view = lm.threeDWidget(0).threeDView()
view.mrmlViewNode().SetRenderMode(1)
view.mrmlViewNode().SetRulerType(1)
view.mrmlViewNode().SetRulerColor(2)
ren3d = view.renderWindow().GetRenderers().GetItemAsObject(0)

```

And that might change the view I can see in Slicer, but it doesn’t change what gets written to the file. I’ve been trying to follow the code and it seems I’m not properly accessing what gets added to the vtkRenderer…where do rulers interact with the renderer?

---

<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:** [August 15, 2023, 9:56pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/37 "2023-08-15T21:56:38Z")

</div>

Right, the example I pasted above only transfers some of the basic elements of the rendered scene over to the high res rendering. The Color Legend and rulers are rendered as overlays so they would need to be added to the script. I don’t recall, but they may be in dedicated renderers. It should be possible to add them if you study the vtk code and the slicer displayable managers, but I believe they are rendered in pixel space, meaning they could look very small in the resulting images (this would be a problem in the original scale factor approach too). If you just need the reference ruler, you might just add a markup line of the reference size and set the thickness so it looks nicer.

---

<div class="post-metadata">

**Author:** ![nsvitek](https://avatars.discourse-cdn.com/v4/letter/n/848f3c/32.png) [@nsvitek](https://discourse.slicer.org/u/nsvitek)\
**Post date:** [August 31, 2023, 2:46pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/38 "2023-08-31T14:46:18Z")

</div>

Thank you for the suggestions. I followed the latter and got it working well enough.

If anyone else is looking to something similar in the future, I modified the example code at the link [here](https://discourse.slicer.org/t/how-to-draw-a-simple-line-with-vtkmrmlmarkupslinenode/18820) to create a horizontal markup line of desired size, then ran the rest of the scene rendering / writing code. The line was included in the image and functioned perfectly well as a scale bar.

---

<div class="post-metadata">

**Author:** ![JaredAmudeo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jaredamudeo/32/77474_2.png) [@JaredAmudeo](https://discourse.slicer.org/u/JaredAmudeo)\
**Post date:** [September 8, 2024, 6:43am UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/39 "2024-09-08T06:43:38Z")

</div>

> [@hherhold](#):
>
> My scene files are typically simple - camera, model, maybe 3 lights (key, fill, kick) and usually very simple surface shaders

How do you do it to be able to export or work with the scale bar when exporting the model and working on it in Blender?

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [September 8, 2024, 2:38pm UTC](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880/40 "2024-09-08T14:38:55Z")

</div>

Hey Jared,

I just DM’d you my “method” for making scale bars in rendered images, let me know if you have any questions. Happy to repost here if people are interested.

[Previous page](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880.md?page=1)

[Next page](https://discourse.slicer.org/t/higher-resolution-for-screen-captures-of-3d-view/8880.md?page=3)
