I imported CT images and radiotherapy structures (segmented organ shuch as bladder , rectum, and … ) into the 3D Slicer , then created a binary labelmap of the structures. The software assigned a label value (index) for each organ, but for a specific organ (e.g. bladder) in Different patients do not have the same label value. How can I assign the same label value to each organ in different patients?
If you save the segmentation as is, as a nrrd file, then you can find the label for each segment in the file header (in
If you think that this solution is not ideal for you then other approaches are available, too. What is your workflow? What software do you use to further process the segmentation? What is the overall goal of your project?
Thank you very much!
I want to segment the organs using deep learning.
In the next step, Python software will be used.
I already need to create binary images for image processing. And I have to assign the same label value for each specific organ in all patients. For example, I want the bladder to get label value 2, rectum 3, for all patients.
I would appreciate if you mention other methods.
@Sunderlandkyl what do you think would be a good solution? Maybe we could add an optional a color node input for segmentation labelmap export? Then the exporter could look up colors based on segment name or terminology. Some people already have a color table (which is used during import) and if the same colormap is used for export then the labelmaps would remain consistent.
There was also a similar question for the import side. There is a solution for the import but it requires a good number of clicks and it is unlikely that users could figure it out by themselves. How do you think we could simplify? Should we add a color node selector to the qSlicerSegmentationsIOOptionsWidget for reading?
Maybe a common solution for both import and export would be to make it easier to create custom terminologies or improve color nodes so that they can contain standard terminologies. We could then use these to map label values to/from segment names and terminology.
Adding a color node option to import/export would be a good way to handle this issue.
I spent some time trying to come up with alternatives and couldn’t think of anything else that would handle the label values as efficiently/cleanly.
Yes, agreed. We spent some time discussing it on this morning’s hangout and this would also help a use case I’m working on.
Finally, I found a simple solution: first, in the segmentation module, move all the structure to the right and then sort them as desired on the left (based on the index you want the structure to take) , in next step , in the data module, create binary labelmap of structures.
I’ve added an issue to keep track of this task: https://github.com/Slicer/Slicer/issues/5044
I’ve added a few code snippets that should be useful: Documentation/Nightly/ScriptRepository - Slicer Wiki
extract_segments extracts segments by name and sets their label in the output voxel array to specified values. To achieve what you described, you would need to run these few lines:
input_filename = "/path/to/input.seg.nrrd" output_filename = "/path/to/outpput.seg.nrrd" segment_list = [("bladder", 2), ("rectum", 3), ("prostate", 5)] voxels, header = nrrd.read(input_filename) read_segmentation_info(input_filename) output_voxels, output_header = extract_segments(voxels, header, segmentation_info, segment_list) nrrd.write(output_filename, output_voxels, output_header)