Created
July 13, 2018 16:58
-
-
Save hherhold/ec3f74d20ca63866555f3e66d1f3621c to your computer and use it in GitHub Desktop.
Find islands in a certain voxel size range.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
original_Segment_Name = 'Segment_Name_Here' | |
low_island_size = 20 | |
high_island_size = 200 | |
# | |
# Switch to segment editor and pick logical effects, and get the segment to work on. | |
# | |
slicer.util.selectModule('SegmentEditor') | |
segmentEditorWidget = slicer.modules.segmenteditor.widgetRepresentation().self().editor | |
segmentEditorWidget.setActiveEffectByName("Logical operators") | |
effect = segmentEditorWidget.activeEffect() | |
segmentationNode = getNode('Segmentation') | |
segmentation = segmentationNode.GetSegmentation() | |
air_segment_id = segmentation.GetSegmentIdBySegmentName(original_Segment_Name) | |
# | |
# Make a low to max by coping original and removing islands smaller than low. | |
# | |
segmentation = getNode('Segmentation').GetSegmentation() | |
low_to_max_segment_id = segmentation.AddEmptySegment() | |
segmentEditorWidget.setCurrentSegmentID(low_to_max_segment_id) | |
effect.setParameter("Operation", "COPY") | |
effect.setParameter("ModifierSegmentID", air_segment_id) | |
effect.self().onApply() | |
segmentEditorWidget.setActiveEffectByName('Islands') | |
effect = segmentEditorWidget.activeEffect() | |
effect.setParameter('Operation','REMOVE_SMALL_ISLANDS') | |
effect.setParameter('MinimumSize', low_island_size) | |
effect.self().onApply() | |
# | |
# Make a high to max in the same fashion. | |
# | |
high_to_max_segment_id = segmentation.AddEmptySegment() | |
segmentEditorWidget.setCurrentSegmentID(high_to_max_segment_id) | |
segmentEditorWidget.setActiveEffectByName('Logical operators') | |
effect = segmentEditorWidget.activeEffect() | |
effect.setParameter("Operation", "COPY") | |
effect.setParameter("ModifierSegmentID", air_segment_id) | |
effect.self().onApply() | |
segmentEditorWidget.setActiveEffectByName('Islands') | |
effect = segmentEditorWidget.activeEffect() | |
effect.setParameter('Operation','REMOVE_SMALL_ISLANDS') | |
effect.setParameter('MinimumSize', high_island_size) | |
effect.self().onApply() | |
# | |
# Finally, make a low to high segment bu subtracting high to max from low to max. | |
# | |
low_to_high_segment_id = segmentation.AddEmptySegment() | |
segmentEditorWidget.setCurrentSegmentID(low_to_high_segment_id) | |
segmentEditorWidget.setActiveEffectByName('Logical operators') | |
effect = segmentEditorWidget.activeEffect() | |
effect.setParameter("Operation", "COPY") | |
effect.setParameter("ModifierSegmentID", low_to_max_segment_id) | |
effect.self().onApply() | |
effect.setParameter("Operation", "SUBTRACT") | |
effect.setParameter("ModifierSegmentID", high_to_max_segment_id) | |
effect.self().onApply() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment