serhii.net

In the middle of the desert you can say anything you want

UNLISTED

13 Sep 2024

Slicer developing a stats module plugin

Copying here from 240905-2052 Developing a 3D Slicer extension because semi-private?

Writing a statistics (sub)module

Registering my stats plugin

After some trial and error, emulating Slicer/Modules/Scripted/SegmentStatistics/SegmentStatistics.py:

TO REGISTER my plugin, I did

from SegmentStatistics import SegmentStatisticsLogic
from Plugins.myPlugin import MyPlugin

# 


def registerNewStats():
    SegmentStatisticsLogic.registerPlugin(MyPlugin())


# ... 

class myScriptedModule(ScriptedLoadableModule):
    """Uses ScriptedLoadableModule base class, available at:
    https://github.com/Slicer/Slicer/blob/main/Base/Python/slicer/ScriptedLoadableModule.py
    """

        # Additional initialization step after application startup is complete
        slicer.app.connect("startupCompleted()", registerSampleData)
        slicer.app.connect("startupCompleted()", registerNewStats)

Hiding the UI of the scripted plugin

Interactions between my Plugin and the main SegmentationStatistics module

In the main module:

  • getMeasurementInfo(key)1 iterates through plugins till it finds one that provides the stat key, then its plugin.getMeasurementInfo(key), this gives it the metadata about that measurement.

  • The Plugin should implement that and computeStatistics(segmentID) that returns a dictionary

  • createMeasurementInfo2 is about creating machine-readable metadata, the DICOM stuff is optional I think

Problems

  • Is this really one stat per segment? So if I want to do more complex stuff I can’t
  • BUT still this approach is the most useful wrt. calculating per-segment stats in a table, then I can give this table to a third module inside the same extension!
  • Still unsolved then: the NAMES of the segmentations

Colors

  • ACTUALLY — If I create a color file, import it, then I convert the segmentation to a labelmap volume, apply colors to it, then import back, I get a segmentation with the correct names!
    • color nodes are vtkMRMLColorNode, I can attach it to a segmentation prolly
    • I can create one as colorNode = slicer.util.loadColorTable('c:/tmp/tmp/Segmentation-label_ColorTable.ctbl')3
    • color files syntax is Colors — 3D Slicer documentation
# Color table file C:/Users/andra/OneDrive/Projects/SlicerTesting2022/20220109-ColorLegend/Segmentation-label_ColorTable.ctbl
# 4 values
0 Background 0 0 0 0
1 artery 216 101 79 255
2 bone 241 214 145 255
3 connective_tissue 111 184 210 255

OK ColorTableNode is where this is (and the colors can be seen), ColorTableStorageNode is the file. BUT ColorNode is used in the scripts. ??

table is child of not-table but I can use them both identically I think

Filling holes

Fills all internal holes inside segments. For example, fills in empty regions inside vertebral bodies segmented with Grow from seeds with intensity-based masking. is awesome and shows many cool things.

Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus