Skip to content

Instantly share code, notes, and snippets.

View pieper's full-sized avatar

Steve Pieper pieper

View GitHub Profile
@pieper
pieper / export-nnunet-dataset.py
Last active June 5, 2026 13:22
LNQ trainer runner + dataset exporter (fetched by trainer.yml.tmpl on first boot). See https://github.com/pieper/SlicerLNQ-Chronicler when published.
#!/usr/bin/env python3
"""Export a Project's approved Annotations as an nnU-Net v2 dataset directory.
For every case_id in the project's CohortResolution where the head Annotation
matches --status (default approved) and has a seg_ref, this writes:
<output_root>/Dataset<NNN>_<task>/imagesTr/<case_id>_0000.nrrd -> CT (from cohort)
<output_root>/Dataset<NNN>_<task>/labelsTr/<case_id>.nrrd -> seg (from annotation)
<output_root>/Dataset<NNN>_<task>/dataset.json -> nnU-Net manifest

Let me fetch the forum post to understand Mike's question.

Web Fetchhttps://discourse.slicer.org/t/bug-in-importlabelmaptosegmentationnode-if-multiple-parent-transforms/46524

Fetched from https://discourse.slicer.org/t/bug-in-importlabelmaptosegmentationnode-if-multiple-parent-transforms/46524

Let me look more carefully at the forum post to understand the details, and also look at the relevant source code in the Slicer repositories to understand the bug better.

Web Fetchhttps://discourse.slicer.org/t/bug-in-importlabelmaptosegmentationnode-if-multiple-parent-transforms/46524

@pieper
pieper / GrowCutWarp.py
Created October 3, 2025 14:49
GrowCutWarp
import warp as wp
import numpy as np
"""
This is a demo of OpenCL code ported automatically to Warp using Google Gemini.
Given this input file, the code below was generated and worked the first time.
https://github.com/pieper/SlicerCL/blob/master/GrowCutCL/GrowCutCL.cl.in
@pieper
pieper / idc-chart.py
Created June 27, 2025 00:38
IDC-chart in Slicer
import json
import random
import sys
try:
import idc_index
import pandas
except ModuleNotFoundError:
import pip
pip.main("install idc_index".split())
@pieper
pieper / fish.py
Last active October 4, 2023 22:48
RGBA volume rendering in 3D Slicer from segmentation
import numpy
dataDir = "/opt/data/SlicerMorph/20231003-ColorizedVR"
segName = "Segmentation"
ctFullName = "deep_snail_2_14.9um_2k__rec1100"
ctName = "deep_snail_2_14"
try:
slicer.util.getNode(segName)
except slicer.util.MRMLNodeNotFoundException:
slicer.util.loadVolume(f"{dataDir}/{ctFullName}.nrrd")
@pieper
pieper / segment-names.py
Created June 13, 2023 16:02
Example of assigning segment names from table
import glob
import numpy
import os
import random
includeEdema = True
exec(open("/opt/data/nac/neurosurgicalatlas/MONAI/labels.py").read())
tureSynthSegGlob = "/opt/data/nac/neurosurgicalatlas/MONAI/Ture-subset-2022-12-03-nii-seg/Ture-*-*.nrrd_synthseg.nii.gz"
@pieper
pieper / ss2-Ture-028-registration.py
Created December 8, 2022 18:49
example slicer transforms
"""
exec(open("/opt/data/nac/neurosurgicalatlas/ss2-Ture-028-registration.py").read())
"""
import glob
from math import floor, ceil
import numpy
@pieper
pieper / sardana.py
Created June 27, 2022 16:21
reading multichannel tiff
"""
p = "/Volumes/GoogleDrive/My Drive/hacks/sardana.py"
exec(open(p).read())
Screencapture of result posted here (slide 7): https://docs.google.com/presentation/d/12cDI-HHQ4OhNTN4oqx-yFiyPAqvDB5sxKrimrWgdAOY/edit?usp=sharing
"""
#
@pieper
pieper / loadPointCloud.py
Created June 3, 2022 20:57
Load a ply point cloud in Slicer
"""
filePath = "/Users/pieper/slicer/latest/SlicerMorph/loadPointCloud.py"
modelPath = "/opt/tmp/georeferenced_model.vtk"
exec(open(filePath).read())
"""
modelNode = slicer.util.loadModel(modelPath)
@pieper
pieper / ngff.py
Last active January 9, 2026 16:50
Display NGFF volume data in 3D Slicer
"""
Display zarr from s3 buckets for example data from here:
https://www.openmicroscopy.org/2020/11/04/zarr-data.html
exec(open("/Users/pieper/idc/ngff.py").read())
see also: /Volumes/GoogleDrive/My\ Drive/hacks/sardana.py
https://gist.github.com/pieper/10ee6add544633f4c75dbb293ef087bc