Skip to content

Instantly share code, notes, and snippets.

View lassoan's full-sized avatar

Andras Lasso lassoan

View GitHub Profile
@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 / SegmentGrowCutSimple.py
Last active May 6, 2023 15:08
This example demonstrates how to run Grow from seeds effect in batch mode (without GUI, using qMRMLSegmentEditorWidget) using 3D Slicer
# Generate input data
################################################
import SampleData
# Load master volume
sampleDataLogic = SampleData.SampleDataLogic()
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1()
# Create segmentation
@lassoan
lassoan / SegmentGrowCut.py
Last active August 19, 2021 18:46
This example script demonstrates how a grow-cut operation can be performed without graphical user interface using 3D Slicer
# This example script demonstrates how a grow-cut
# operation can be performed without graphical user interface.
# The first half of the script downloads input data and creates seed segments.
# The second half of the script converts segments to merged labelmap (that's the required
# input format for grow-cut filter), computes the complete segmentation, and writes
# results into new segments.
# Generate input data
################################################
@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 / LineProfile.py
Last active August 25, 2022 02:45
3D Slicer module for computing intensity profile in a volume along a ruler line
#
#
#
#
#
# This example has been completely reworked and converted to a module, now available at:
#
#
# https://github.com/lassoan/SlicerLineProfile/blob/master/LineProfile/LineProfile.py
#
@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 / ExtractSkin.py
Last active May 24, 2022 17:53
This example demonstrates how to extract skin surface from an MRI image using thresholding and smoothing effect of Segment Editor
import SampleData
sampleDataLogic = SampleData.SampleDataLogic()
masterVolumeNode = sampleDataLogic.downloadMRHead()
# Create segmentation
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)
addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment("skin")
@lassoan
lassoan / CardiacAgatstonScoring
Last active September 18, 2023 03:36
Cardiac Agatston scoring function for 3D Slicer
# There are several variants of the metric. If you need to compute the metric slice by slice then
# you can use Mask volume effect to create a volume where all voxels are blanked out (set to -1000)
# except the calcifications in the selected vessel and compute the total score using this script.
# (based on Agatston (1990) - https://www.sciencedirect.com/science/article/pii/073510979090282T)
#
# Sample data set is available at:
# https://github.com/lassoan/PublicTestingData/releases/download/data/CardiacAgatstonScore.mrb
def computeAgatstonScore(volumeNode, minimumIntensityThreshold=130, minimumIslandSizeInMm2=1.0, verbose=False):
import numpy as np
@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 / 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())