<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://www.slicer.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Scottg</id>
	<title>Slicer Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://www.slicer.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Scottg"/>
	<link rel="alternate" type="text/html" href="https://www.slicer.org/wiki/Special:Contributions/Scottg"/>
	<updated>2026-04-07T10:37:19Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://www.slicer.org/w/index.php?title=Documentation/Nightly/FAQ/Scripting&amp;diff=30870</id>
		<title>Documentation/Nightly/FAQ/Scripting</title>
		<link rel="alternate" type="text/html" href="https://www.slicer.org/w/index.php?title=Documentation/Nightly/FAQ/Scripting&amp;diff=30870"/>
		<updated>2013-03-01T18:02:30Z</updated>

		<summary type="html">&lt;p&gt;Scottg: /* How to grab full slice image ? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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;
='''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>Scottg</name></author>
		
	</entry>
</feed>