Skip to content

Commit 5784284

Browse files
committed
Interpolate segmentation image to match ct origin, spacing, and direction
1 parent b191390 commit 5784284

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

examples/integrations/itk/IDC_Seg_Primer_Examples.ipynb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"source": [
3434
"import sys\n",
3535
"\n",
36-
"!{sys.executable} -m pip install -q pooch itk-io \"itkwidgets[all]>=1.0a33\""
36+
"!{sys.executable} -m pip install -q pooch itk-io \"itkwidgets[all]>=1.0a33\" pydicom pydicom-seg numpy"
3737
]
3838
},
3939
{
@@ -49,7 +49,10 @@
4949
"import itk\n",
5050
"import pooch\n",
5151
"from pathlib import Path\n",
52-
"from itkwidgets import view"
52+
"from itkwidgets import view\n",
53+
"import pydicom\n",
54+
"import pydicom_seg # Pydicom-Seg is a layer on top of pydicom that handles DICOM SEG objects.# Read the DICOM SEG object using pydicom and pydicom_seg.\n",
55+
"import numpy as np"
5356
]
5457
},
5558
{
@@ -157,7 +160,15 @@
157160
},
158161
"outputs": [],
159162
"source": [
160-
"pred_segthor_image = itk.imread(\"./SEG_DICOM_series/1.nrrd\")"
163+
"seg_dicom = pydicom.dcmread(\"./SEG_DICOM_series/6c8744b0-5dd7-4730-bef7-1ab465ec2337.dcm\")\n",
164+
"seg_reader = pydicom_seg.MultiClassReader()\n",
165+
"seg_obj = seg_reader.read(seg_dicom)\n",
166+
"\n",
167+
"# Convert the DICOM SEG object into an itk image, with correct voxel origin, spacing, and directions in physical space.\n",
168+
"seg_image = itk.image_from_array(seg_obj.data.astype(np.float32))\n",
169+
"seg_image.SetOrigin(ct_image.GetOrigin())\n",
170+
"seg_image.SetSpacing(ct_image.GetSpacing())\n",
171+
"seg_image.SetDirection(ct_image.GetDirection())"
161172
]
162173
},
163174
{

0 commit comments

Comments
 (0)