This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)], | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The module is now moved to SlicerSandbox extension: | |
# | |
# https://github.com/PerkLab/SlicerSandbox/tree/master/SegmentCrossSectionArea | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generate input data | |
################################################ | |
import SampleData | |
import numpy as np | |
# Load master volume | |
sampleDataLogic = SampleData.SampleDataLogic() | |
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |