Skip to content

Instantly share code, notes, and snippets.

View lassoan's full-sized avatar

Andras Lasso lassoan

View GitHub Profile
@lassoan
lassoan / export_files_assembla.ps1
Created September 25, 2017 13:49
Download all files from Assembla (Files tool - including all ticket and wiki attachments)
##################
## Written by: Kyle Sunderland
##
## Downloads all files from an assembla project
## Need to change repo_name, api_key, and api_secret for the script to work
##################
$repo_name = "REPO_NAME" # Name of the repo
# personal keys found at: https://app.assembla.com/user/edit/manage_clients
@lassoan
lassoan / ReconstructSurface.py
Created March 16, 2018 02:40
Reconstruct open surface from labelmap
# Important: the input volume must have isotropic spacing.
# If surface is thick, use Extract skeleton module with Skeleton type = 2D, Do not prune branches = enabled.
# Increase radius parameter to fill more holes.
# Increase dimension to preserve more details.
inputLabelmap = getNode('Input labelmap')
ici = vtk.vtkImageChangeInformation()
ici.SetInputData(inputLabelmap.GetImageData())
ici.SetOutputSpacing(inputLabelmap.GetSpacing())
@lassoan
lassoan / MarkupsInfo.py
Created September 21, 2017 13:17
Compute the total length between all the points of a markup list in 3D Slicer
from __main__ import qt, slicer
#
# MarkupsInfo module
#
class MarkupsInfo:
def __init__(self, parent):
import string
parent.title = "Markups info"
@lassoan
lassoan / SimpleView.py
Last active December 20, 2018 18:32
Simple 3D Slicer based image viewer
def showSimpleUserInterface(simpleView):
# Do not store these display settings permanently
settings = qt.QSettings()
settings.setValue('MainWindow/RestoreGeometry', not simpleView)
for toolbar in slicer.util.mainWindow().findChildren('QToolBar'):
toolbar.setVisible(not simpleView)
modulePanelDockWidget = slicer.util.mainWindow().findChildren('QDockWidget','PanelDockWidget')[0]
volumesDir = r"c:\Users\andra\OneDrive\Projects\SlicerTesting4\20190523-AutoWWWL\volumes"
screenshotsDir = r"c:\Users\andra\OneDrive\Projects\SlicerTesting4\20190523-AutoWWWL\screenshots"
methods = [
["baseline", autoContrastSlicerDefault],
["hist-0.1-99.9", lambda fn: autoContrastVtkImageHistogramStatisticsDefault(fn, 0.1, 99.9, 0.00, 0.0)], # = itksnap
["hist-1.0-99.9", lambda fn: autoContrastVtkImageHistogramStatisticsDefault(fn, 1.0, 99.9, 0.10, 0.0)],
["hist-1.0-99.0-x0.10", lambda fn: autoContrastVtkImageHistogramStatisticsDefault(fn, 1.0, 99.0, 0.10, 0.10)],
["hist-1.0-99.0-x0.20", lambda fn: autoContrastVtkImageHistogramStatisticsDefault(fn, 1.0, 99.0, 0.10, 0.20)],
]
@lassoan
lassoan / AngleMeasurement.py
Last active June 22, 2019 20:17
3D Slicer scripted module for measuring angle between rulers
#
# Installation:
# - Save this file as AngleMeasurement.py to a directory on your computer
# - Add the directory to the additional module paths in the Slicer application settings:
# - Choose in the menu: Edit / Application settings
# - Click Modules, click >> next to Additional module paths
# - Click Add, and choose the .py file's location
# - After you restart Slicer, "Angle Measurment" module should show up in Quantification category
#
@lassoan
lassoan / MaskVolumeHistogramPlot.py
Last active September 3, 2019 16:08
Histogram plot of volume masked by segments
# Generate input data
################################################
import SampleData
import numpy as np
# Load master volume
sampleDataLogic = SampleData.SampleDataLogic()
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1()
@lassoan
lassoan / SliceAreaPlot.py
Created August 6, 2019 03:43 — forked from hherhold/SliceAreaPlot.py
Example module that computes and plots the cross sectional area of each visible segment. Direction of cross-section can be picked.
import os
import unittest
import vtk, qt, ctk, slicer
from slicer.ScriptedLoadableModule import *
from array import array
import logging
import vtk.util.numpy_support
import numpy as np
#
@lassoan
lassoan / SegmentByThresholding.py
Last active March 23, 2020 22:00
This example shows how to estimate fat, muscle, and bone volume in a CT image by simple thresholding.
# Download a sample data set (chest CT)
import SampleData
masterVolumeNode = SampleData.SampleDataLogic().downloadCTChest()
# Create segmentation
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)
# Create temporary segment editor to get access to effects
@lassoan
lassoan / create-partof-hierarchy.py
Created March 30, 2020 22:12
Create 3D Slicer subject hierarchy from BodyParts3D
# Source data can be obtained from http://lifesciencedb.jp/bp3d/ (tested with partof_BP3D_4.0_obj_99)
# These input file must be loaded into the scene:
# - partof_inclusion_relation_list.txt and partof_element_parts.txt (loaded as Table nodes)
# - OBJ files
shNode = slicer.mrmlScene.GetSubjectHierarchyNode()
sceneItemID = shNode.GetSceneItemID()
def getItemParentsFmaIds(shNode, itemShItemId):
existingParentShItemId = shNode.GetItemParent(itemShItemId)