Skip to content

Instantly share code, notes, and snippets.

View pieper's full-sized avatar

Steve Pieper pieper

View GitHub Profile
@pieper
pieper / renderSmooth
Created September 17, 2014 23:06
render a smoothed image by supersampling - hack for slicer4
lm = slicer.app.layoutManager()
tw = lm.threeDWidget(0)
tv = tw.threeDView()
rw = tv.renderWindow()
ren = rw.GetRenderers().GetItemAsObject(0)
wti = vtk.vtkWindowToImageFilter()
wti.SetMagnification(4)
@pieper
pieper / gist:6186477
Last active December 20, 2015 19:58
"""
The following can be pasted into the python console to examine the headers
of all the dicom objects in the database
"""
import DICOMLib
parent = qt.QWidget()
layout = qt.QVBoxLayout()
parent.setLayout(layout)
@pieper
pieper / decruft.py
Last active December 20, 2015 18:38
decruft.py - does some math morphology operations to clean up a segmentation so that only the big connected regions are kept.
"""
Run this with a label map loaded in the slicer editor.
Change this path to be wherever you save this file and then paste
the line into the slicer python console:
execfile('/Users/pieper/Dropbox/hacks/slicer/decruft.py')
This script will apply the algorithm and display the result.
You can use the editor's undo operation to get back to the
@pieper
pieper / gist:5770098
Last active November 5, 2020 08:38
This is the final edited version of the VolumeScroller.py example script for this tutorial: http://www.na-mic.org/Wiki/index.php/2013_Project_Week_Breakout_Session:Slicer4Python
import os
import unittest
from __main__ import vtk, qt, ctk, slicer
#
# VolumeScroller
#
class VolumeScroller:
def __init__(self, parent):
@pieper
pieper / gist:5270696
Created March 29, 2013 13:03
Save a slicer 3D view to an obj file
>>> o = vtk.vtkOBJExporter()
>>> o.SetFilePrefix('/tmp/obj/fibers')
>>> lm = slicer.app.layoutManager()
>>> tdv = lm.threeDWidget(0).threeDView()
>>> rw = tdv.renderWindow()
>>> o.SetRenderWindow(rw)
>>> o.Write()
import os
import slicer
from __main__ import qt
from __main__ import ctk
#########################################################
#
#
comment = """