Skip to content

Instantly share code, notes, and snippets.

Andras Lasso lassoan

Block or report user

Report or block lassoan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lassoan
lassoan / CurvedPlanarReformatting.py
Created Oct 22, 2019
Computing a panoramic X-ray from a cone-beam dental CT. Demonstration of how an image can be resampled along a curve - the code is not optimized for performance or quality and distance along curve is not scaled (we simply used all point indices instead of retrieving point indices based on desired distance along curve).
View CurvedPlanarReformatting.py
# Get a dental CT scan
import SampleData
volumeNode = SampleData.SampleDataLogic().downloadDentalSurgery()[1]
# Define curve
curveNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLMarkupsCurveNode')
curveNode.CreateDefaultDisplayNodes()
curveNode.GetCurveGenerator().SetNumberOfPointsPerInterpolatingSegment(25) # add more curve points between control points than the default 10
curveNode.AddControlPoint(vtk.vtkVector3d(-45.85526315789473, -104.59210526315789, 74.67105263157896))
curveNode.AddControlPoint(vtk.vtkVector3d(-50.9078947368421, -90.06578947368418, 66.4605263157895))
@lassoan
lassoan / SliceAreaPlot.py
Created Aug 6, 2019 — 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.
View SliceAreaPlot.py
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
#
View AutoWindowLevelTest.py
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 / SegmentByThresholding.py
Last active May 15, 2019
This example shows how to estimate fat, muscle, and bone volume in a CT image by simple thresholding.
View SegmentByThresholding.py
# 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 / SimpleView.py
Last active Dec 20, 2018
Simple 3D Slicer based image viewer
View SimpleView.py
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]
@lassoan
lassoan / SegmentQuantification.py
Last active May 23, 2018
This example shows how to compute volume and surface area of a segment in 3D Slicer
View SegmentQuantification.py
# Load master volume
import SampleData
sampleDataLogic = SampleData.SampleDataLogic()
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1()
# Helper function to compare computed volume and surface to ground truth
def printError(computedSurfaceAreaMm2, computedVolumeMm3, radius):
import math
groundTruthSurfaceAreaMm2 = 4.0*math.pi*radius*radius
groundTruthVolumeMm3 = 4.0/3.0*math.pi*radius*radius*radius
@lassoan
lassoan / ReconstructSurface.py
Created Mar 16, 2018
Reconstruct open surface from labelmap
View ReconstructSurface.py
# 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 / MaskVolumeHistogramPlot.py
Last active Sep 3, 2019
Histogram plot of volume masked by segments
View MaskVolumeHistogramPlot.py
# Generate input data
################################################
import SampleData
import numpy as np
# Load master volume
sampleDataLogic = SampleData.SampleDataLogic()
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1()
@lassoan
lassoan / CardiacAgatstonScoring
Last active Oct 11, 2018
Cardiac Agatston scoring function for 3D Slicer
View CardiacAgatstonScoring
# There are several variants of the metric. If you need to compute the metric slice by slice then
# you can use Mask volume effect (available in Segment Editor module after you install SegmentEditorExtraEffects
# extension) to create a volume where all voxels are blanked out except the calcifications in the selected vessel
# and compute the total score using this script.
def computeAgatstonScore(volumeNode, minimumIntensityThreshold=130, minimumIslandSizeInMm2=1.0, verbose=False):
import numpy as np
import math
import SimpleITK as sitk
voxelArray = slicer.util.arrayFromVolume(volumeNode)
@lassoan
lassoan / ExtractSkin.py
Last active Jun 12, 2019
This example demonstrates how to extract skin surface from an MRI image using thresholding and smoothing effect of Segment Editor
View ExtractSkin.py
import SampleData
sampleDataLogic = SampleData.SampleDataLogic()
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1()
# Create segmentation
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)
addedSegmentID = segmentationNode.GetSegmentation().AddEmptySegment("skin")
You can’t perform that action at this time.