Dear community,
I started to use Slicer3D some time ago. Currently, to develop a spine segmentation model, i am using the MIRACLE dataset: MIRACLE-Center/CTSpine1K: A Large-Scale Dataset for Spinal Vertebrae Segmentation in Computed Tomography (github.com). Nonetheless, some of CT images and their segmentations have different geometries, e.g.: different origin and even different voxel size.
I tried to use the following code to register the images:
imgs = [i for i in sorted(listdir(folder_img)) if isfile(join(folder_img, i))]
#print(imgs)
fold_mask = [m for m in sorted(listdir(folder_mask)) if isfile(join(folder_mask, m))]
for img, mk in zip (imgs, fold_mask):
name_img = os.path.splitext(img)[0]
name_imgf = re.sub(".nii", "", name_img)
# load volume image
volumeNode = loadVolume(join(folder_img, img))
# load labels
segmentationNode = slicer.util.loadSegmentation(join(folder_mask, mk))
originalSpacing = volumeNode.GetSpacing()
print("Original spacing:", originalSpacing)
originalOrigin = volumeNode.GetOrigin()
print("Original origin:", originalOrigin)
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(volumeNode)
labelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode")
slicer.modules.segmentations.logic().ExportAllSegmentsToLabelmapNode(segmentationNode, labelmapVolumeNode, slicer.vtkSegmentation.EXTENT_REFERENCE_GEOMETRY)
savef = join(save_path, name_imgf + ext)
saveNode(labelmapVolumeNode, savef)
slicer.mrmlScene.Clear(0)
Nonetheless, when slicer exports the labels, it exports only a cropped version of the segmentations (same pixel numbers as the original image), but does not align the segmentation file.
Have you encountered the same problem? How did you fix it?
Thanks a lot.
Best