<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.5%2FFAQ%2FScripting</id>
	<title>Documentation/4.5/FAQ/Scripting - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://www.slicer.org/w/index.php?action=history&amp;feed=atom&amp;title=Documentation%2F4.5%2FFAQ%2FScripting"/>
	<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.5/FAQ/Scripting&amp;action=history"/>
	<updated>2026-05-05T19:21:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://www.slicer.org/w/index.php?title=Documentation/4.5/FAQ/Scripting&amp;diff=43626&amp;oldid=prev</id>
		<title>UpdateBot: Nightly -&gt; 4.5</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/4.5/FAQ/Scripting&amp;diff=43626&amp;oldid=prev"/>
		<updated>2015-11-12T22:05:16Z</updated>

		<summary type="html">&lt;p&gt;Nightly -&amp;gt; 4.5&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;noinclude&amp;gt;{{documentation/versioncheck}}&amp;lt;/noinclude&amp;gt;&lt;br /&gt;
&amp;lt;noinclude&amp;gt;__TOC__&lt;br /&gt;
={{#titleparts: {{PAGENAME}} | | -1 }}=&amp;lt;/noinclude&amp;gt;&amp;lt;includeonly&amp;gt;&lt;br /&gt;
{{#ifeq: {{#titleparts: {{PAGENAME}} | 3 }} | Documentation/{{documentation/version}}/Developers | | ='''User FAQ: {{{1}}}'''=}}&lt;br /&gt;
&amp;lt;/includeonly&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How to grab full slice image (+-volume, +-model) ? ==&lt;br /&gt;
&lt;br /&gt;
=== A Few General Approaches ===&lt;br /&gt;
&lt;br /&gt;
There are multiple ways to access image data from one or all of the slice views.  &lt;br /&gt;
&lt;br /&gt;
==== VTK Window to Image Function  (vtk.vtkWindowToImageFilter() ====&lt;br /&gt;
&lt;br /&gt;
: #   Example to grab image from red slice view and output as TIF&lt;br /&gt;
&lt;br /&gt;
: lm = slicer.app.layoutManager()&lt;br /&gt;
: redWidget = lm.sliceWidget('Red')&lt;br /&gt;
: redView = redWidget.sliceView()	&lt;br /&gt;
: wti = vtk.vtkWindowToImageFilter()&lt;br /&gt;
: wti.SetInput(redView.renderWindow())&lt;br /&gt;
: wti.Update()&lt;br /&gt;
: w = vtk.vtkTIFFWriter()&lt;br /&gt;
: w.SetInputConnection(wti.GetOutputPort())&lt;br /&gt;
: w.SetFileName('tmp/test.tif')&lt;br /&gt;
: w.Write()&lt;br /&gt;
&lt;br /&gt;
==== Direct access to widget data using ====&lt;br /&gt;
&lt;br /&gt;
: #    Example grabs image from red slice view and outputs as PNG&lt;br /&gt;
&lt;br /&gt;
: lm = slicer.app.layoutManager()&lt;br /&gt;
: redWidget = lm.sliceWidget('Red')&lt;br /&gt;
: im = redWidget.imageData()&lt;br /&gt;
: w = vtk.vtkPNGWriter()&lt;br /&gt;
: w.SetInput(im)&lt;br /&gt;
: w.SetFileName('tmp/test.png')&lt;br /&gt;
: w.Write()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== QImages using the qt.QPixmap.grabWidget function ====&lt;br /&gt;
      &lt;br /&gt;
: #   example to grab all views and store in 'image'&lt;br /&gt;
          image = qt.QPixmap.grabWidget(slicer.util.mainWindow()).toImage()&lt;br /&gt;
&lt;br /&gt;
: #   example to grab 3d view, store in tdv, then output as a png image file&lt;br /&gt;
          tdv = lm.threeDWidget(0).threeDView()&lt;br /&gt;
          qt.QPixmap().grabWidget(tdv).toImage().save('/tmp/test.png')&lt;br /&gt;
&lt;br /&gt;
=== Notes ===&lt;br /&gt;
&lt;br /&gt;
This is also useful for slicing up whatever is shown (eg. voxelizing model data) by iterating this over the dimensions of the volume/model &lt;br /&gt;
&lt;br /&gt;
In order to view models in the slice view make sure to activate the &amp;quot;Slice Intersections Visible&amp;quot; property of the model&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Specific Example ===&lt;br /&gt;
&lt;br /&gt;
The following script iterates through the red slice view and outputs each slice as a .png image.  &lt;br /&gt;
It was originally designed to output volume+model data together slice-by-slice&lt;br /&gt;
&lt;br /&gt;
: https://gist.github.com/gortscizz/5060517&lt;/div&gt;</summary>
		<author><name>UpdateBot</name></author>
		
	</entry>
</feed>