Skip to content

SLICER_Segmentation_Src_research

KKnoernschild edited this page Mar 8, 2019 · 1 revision

Link to file format for segmentation specifically to SLICER

output:https://github.com/Slicer/Slicer/blob/e5a9a7cab3267b93d7bcc40020bdca5ea3568a35/Libs/MRML/Core/vtkMRMLSegmentationStorageNode.cxx

Link to nrrd file format directly from the .seg.nrrd file\

http://teem.sourceforge.net/nrrd/format.html

KEY_SEGMENT_NAME is the tag name (in the form of a string) KEY_SEGMENT_ID is the segment numerical ID tag (in the form of a string)

ExposeMetaDatastd::String current segment name -> looks to be the input for the segment name that isnt just the key value

segment index is the number paired to the segment header strings, which is type unsigned int based off the region size of the 4th dimension of the segment image (ie the number of segments)

Treats all inputs as strings Segment_Name is the numeric tag that the segmentation gets assigned in the segment editor when created

each segment is saved as an image that is the size of a bounding box around the segment volume.

e.g. Segment1_Extent = 43 82 43 75 86 120

the segment is saved to the ID and Tag, which are both defined win the header as Segment_Name and Segment_ID

metadata is saved as strings

itk::ExposeMetaData -> currently searching for how this function works

itk::ExposeMetaDatastd::string(metadata, GetSegmentationMetaDataKey(KEY_SEGMENTATION_EXTENT).c_str(), commonExtent);

metadata is the header/key pair read in , segment is the key for the value wanted , commonExtent is the output, so the results even if numerical is outputted as a string.

there is one other version used thats explicitly referenced as a double, but that is for PET scans and is a weight/injection size parameter. All other references convert to string. So if the initial save of the image is a string, and its read as a string by VTK/ITK, I dont think that it necessarily needs to be saved as a numerical output for the tags.

For numerical outputs, stringstream used to obtain and save the values (int in the case of the bounding box extent)

Segmentation also recognizes reading a nrrd file that doesn't necessarily have an image associated with it, but juts header information

When the slicer module is back on my machine, I want to check if the segmentation are loaded and assigned numerically even if there is a string tag in the slot, figure out if the tag itself is the label or if its read in and assigned a numerical tag to the segmentation

Need to figure out what/where the masterRepresentation is

automatically checks for segmentation and duplicate info in the header file, ignores the duplicate if previously found

Changing the ID did not have any effect on the saving or loading of the image, so it would be possible to save more information in that slot, as long as there were no duplicates (since the segment ID is what is read to check if the segment is duplicated) - > not finding where the seg_ID is located when the image is loaded into Slicer - label itself is easily visible but not the ID

Segmentation only labels the actual pixels of the image, eveyrthing else is labeled as 'NONE'

Currently appending my own key:value pairs to the headers to see how the segment editor reacts to reading them

nothing changes the outputs but when reloading the seg image in it only loads one plane. -> only shows a single plane when not loaded in with another image

Adding in another key pair value is adding in another segmented area, with no defined image space: treats adding in a label that isnt in the label list as if its still another segment label

Opening .seg.nrrd with text editor to add in header info corrupts the file

using pythonnrrd you can open and edit the file, write as a new .seg.nrrd and it will still read properly into itk. you can store additional tag and definition in the headers, as long as you have a way to read them back using the python cmd in Slicer _>just confirmed. If you create duplicates of headers It finds and overrites the same name in the same position with the new key value pair

Screenshots

Adding in new header info per subject AddedToDict

ResultInsert

Checking inserts to each segment -> File still loads segmentation properly with new data. As long as the data doesnt overlap or have the same key as another pair in the dict, you should be able to store any data you want

TRIO BrainLabelMap to segmentation

Looking at inserting the TSV data into the Segmentation file, but there are thousands of tags inthe TSV file to the 250 or so Segmentations that the Labelmap outputs when Slicer converts

Took the TRIO-TRIO-MR2_Dense and created segmentation labelmap: reading the header data in python outputs a sorted dict (e.g. Segment381 , Segment39 , segment 3 , Segment 430 , segment43 , segment 4 (ect))

I haven't checked yet to see ifthe color of the labelmap is the same as that of the TSV file for the corresponding label, since There isnt a 1-1 match with there being many more labels in the TSV file

LUT applied

LookUpAppliedAndSegmented

HeaderInfo after LUT is applied and segmentations are saved as a .seg.nrrd

HeaderInfo

There isnt a way to combine the image and the segmentation files together, but you can zip them as a package, and if you load that directory into slicer it loads all files that have been zipped.

20 seconds for the brain segment and image to be loaded into slicer (with the header information already changed)

Scripting

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository helpful scripts for slicer -> segmentation creation from labelmaps included in this.

theres also a set lookuptable as well, so youhsould be able to write a python scriptthat is ran through slicer to create all of these (dont have to load and display )

https://discourse.slicer.org/t/how-to-save-seg-nrrd-with-script/4614/3 -> there was issues with saving .seg.nrrd but the solution script/call is in this thread

Need access to the .nrrd python package in the Slicer environment to be able to access files down the road

https://docs.python.org/3/library/argparse.html