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 | |
# Load master volume | |
sampleDataLogic = SampleData.SampleDataLogic() | |
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1() | |
# Create segmentation |
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
# This script randomly warps a 3D volume and adds random translations, rotations, | |
# and save each resulting 3D volume (and a screenshot for quick overview) | |
# | |
# The script can be executed by copy-pasting into 3D Slicer's Python console | |
# or in a Jupyter notebook running 3D Slicer kernel (provided by SlicerJupyter extension). | |
# | |
# Prerequisites: | |
# - Recent Slicer-4.11 version | |
# - SlicerIGT extension installed (for random deformations) |
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
# Create a markups fiducial node and place 6 points then copy paste this code into 3D Slicer's Python console. | |
# Two circles will be created (one for each 3 points) and the axis will be computed by connecting their centers. | |
# The circles and the axis is updated as the fiducial point positions are adjusted. | |
def sphereFrom3Points(markupsNode, startPointIndex): | |
"""Compute center and radius of 3-point sphere from 3 fiducial points | |
source: https://stackoverflow.com/questions/20314306/find-arc-circle-equation-given-three-points-in-space-3d | |
""" | |
import numpy as np | |
A = np.zeros(3) |
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
segmentationNode = slicer.mrmlScene.GetFirstNodeByClass('vtkMRMLSegmentationNode') | |
# set value to the size of the larges cracks in the segment surfaces | |
maximumHoleSizeMm = 2.0 | |
############ | |
masterVolumeNode = segmentationNode.GetNodeReference(segmentationNode.GetReferenceImageGeometryReferenceRole()) | |
# Create segment editor to get access to effects | |
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget() | |
# To show segment editor widget (useful for debugging): |
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)) |
OlderNewer