Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Provides SimpleITK medical image processing: segmentation, registration, filtering, resampling, morphology for DICOM, NIfTI, NRRD.
64% 91%+27 ptsof test cases passed
Passed 20 of 22 test cases with the skill, and 14 of 22 without it.
Instantiate the SimpleITK filter object used to compute intensity statistics for labeled image regions.
The code instantiates sitk.LabelIntensityStatisticsImageFilter().
3 of 3 safety checks passed
SimpleITK simplifies the Insight Toolkit (ITK) for medical image processing: segmentation, registration, filtering, resampling, and morphological operations. Supports DICOM, NIfTI, NRRD, and 50+ file formats.
uv pip install SimpleITK
import SimpleITK as sitk
import numpy as np
image = sitk.ReadImage("ct_scan.nii.gz")
print(image.GetSize(), image.GetSpacing(), image.GetOrigin())
array = sitk.GetArrayFromImage(image)
print(array.shape) # (z, y, x)
binary = sitk.BinaryThreshold(image, lower=200, upper=500, insideValue=1, outsideValue=0)
cc = sitk.ConnectedComponent(binary)
stats = sitk.LabelIntensityStatisticsImageFilter()
stats.Execute(cc, image)
for label in stats.GetLabels():
print(f"Label {label}: mean={stats.GetMean(label):.1f}")
fixed = sitk.ReadImage("template.nii.gz")
moving = sitk.ReadImage("moving.nii.gz")
Next to this one in the catalogue, plus more from the same author.