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
# Load dry bone CT of skull into the scene and run this script to automatically segment endocranium | |
masterVolumeNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLScalarVolumeNode") | |
smoothingKernelSizeMm = 3.0 # this is used for closing small holes in the se | |
# Compute bone threshold value automatically | |
import vtkITK | |
thresholdCalculator = vtkITK.vtkITKImageThresholdCalculator() | |
thresholdCalculator.SetInputData(masterVolumeNode.GetImageData()) | |
thresholdCalculator.SetMethodToOtsu() |
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
# 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 | |
################################################ |
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") |
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 gist contained a script that automatically removes table from a CT volume. | |
# The code was improved and turned into a Slicer module, available in the Sandbox extension: | |
# https://github.com/PerkLab/SlicerSandbox#remove-ct-table | |
# | |
# Source code: | |
# https://github.com/PerkLab/SlicerSandbox/blob/master/RemoveCtTable/RemoveCtTable.py#L251 |
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
# Load/generate input data | |
################################################ | |
# Load master volume | |
import SampleData | |
sampleDataLogic = SampleData.SampleDataLogic() | |
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1() | |
# Define boundary points | |
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
# | |
# | |
# | |
# | |
# | |
# This example has been completely reworked and converted to a module, now available at: | |
# | |
# | |
# https://github.com/lassoan/SlicerLineProfile/blob/master/LineProfile/LineProfile.py | |
# |
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
# Convert volume nodes of 3D Slicer to/from xarray and read/write into zarr format | |
def xarrayFromVolume(volumeNode) -> "xr.DataArray": | |
"""Convert an volume node to an xarray.DataArray. | |
Origin and spacing metadata is preserved in the xarray's coords. The | |
Direction is set in the `direction` attribute. | |
Dims are labeled as `x`, `y`, `z`, `t`, and `c`. | |
This interface is and behavior is experimental and is subject to possible | |
future changes.""" | |
import xarray as xr |
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 can be used with this example scene: | |
# https://github.com/lassoan/PublicTestingData/releases/download/data/ColoredVolumeRenderingScene.mrb | |
volumeNode = getNode('Panoramix-cropped') | |
segmentationNode = getNode('Panoramix-cropped segmentation') | |
boostSegmentOpacity = False # Increase voxel value inside segments to allow making them them more opaque | |
volumesLogic = slicer.modules.volumes.logic() | |
segmentIds = vtk.vtkStringArray() |
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 example was moved to Sandbox extension so that users can more easily install it: | |
https://github.com/PerkLab/SlicerSandbox/blob/master/LoadRemoteFile/LoadRemoteFile.py | |
More information: https://github.com/PerkLab/SlicerSandbox/blob/master/README.md#loadremotefile |