Skip to content

Fix labels from Slicer plugin offset by extra background class #716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

adamaji
Copy link
Contributor

@adamaji adamaji commented Mar 31, 2022

Signed-off-by: Adam Aji [email protected]

This PR addresses #713. When running the Slicer plugin, I saw that having the "background" segment visible would affect scribbles by offsetting the expected labels of "2"/"3" for "background_scribbles"/"foreground_scribbles" to "3"/"4". This can also affect saving labels via "Submit Label" by incrementing all classes after "background" by 1.

I'm assuming this offset isn't intended from other references in the code

scribbles_bg_label=2,
scribbles_fg_label=3,

The main change here is to replace ExportVisibleSegmentsToLabelmapNode with ExportSegmentsToLabelmapNode and specify exactly which segments should be exported. For scribbles, I opted to export only the selected currentSegment with the foreground and background scribble segments.

Because of that, this is a potential soft-workaround for #607, as it should allow you to associate the scribbles with different segments in the segmentation. It's still somewhat unclear that that currentSegment combobox is connected to scribbles since it lives under the "SmartEdit / DeepGrow" heading, but since scribbles was already using it, I thought this should be fine for now.

@@ -1279,8 +1279,9 @@ def onSaveLabel(self):
qt.QApplication.setOverrideCursor(qt.Qt.WaitCursor)
segmentationNode = self._segmentNode
labelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode")
slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(
segmentationNode, labelmapVolumeNode, self._volumeNode
save_segment_ids = [segment_id for segment_id in segmentationNode.GetSegmentation().GetSegmentIDs() if segment_id != "background"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we can discard the background label (which is normally used by deepedit multilabel model) along with scribbles background/foreground when you save the label..
but the fix possibly by adding "background" to the list mentioned at: https://github.com/Project-MONAI/MONAILabel/blob/main/plugins/slicer/MONAILabel/MONAILabel.py#L1293

_, segment = self.currentSegment()
selected_label_name = segment.GetName()
save_segment_ids = [selected_label_name, "background_scribbles", "foreground_scribbles"]
slicer.modules.segmentations.logic().ExportSegmentsToLabelmapNode(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a known issue for scribbles.. it currently can't support/persist scribbles per label.. specially in case for multi-label.. what you need is save/persist the bg/fg scribbles (similar to fg/bg fudical/click points) per label.. so the behavior/user experience in case of multilabel might not be good.

However, i will let @masadcv to decide what he needs from the label node.. i guess he might want to get all labels and pick fg/bg label masks as part of pre-transforms + current label name (i guess he needs current label name in case of he wants all labels; which might be the reason, it's not working) and send back the results with corrections..

again only corrected label should get updated.. i guess it needs to be fixed/verified as well..

In future these methods might want to use existing label masks as input along with fg/bg label masks..
Or until that future comes, it's ok for me to include only fg/bg scribbles sent to server to run the scribbles action..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamaji @SachidanandAlle understood.
I would like to keep labels and do selection on the server side. This is to make it future-proof where we can use more advanced multi-label post-processing methods such as CRF that take into account other labels as well.

The scribbles labels are currently hard-coded in server app, these need to be passed from the client - in case the order changes or similar shift in label are present (due to any changes to client). Hence, a need for dynamic updates for this.

As Sachi said, background may need to be removed before saving final segmentation output, but this can be done at https://github.com/Project-MONAI/MONAILabel/blob/main/plugins/slicer/MONAILabel/MONAILabel.py#L1293

I will continue this in PR #717 where I will merge the changes from here for updating the current label and provide a generalisable solution to the problem that we can extend in future to multi-label problems. As this needs proper testing with multilabel problem, I will take sometime and get back with an update when ready.

_, segment = self.currentSegment()
label = segment.GetName()
self.updateSegmentationMask(result_file, [label])
self.updateSegmentationMask(result_file, [selected_label_name])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes,, this will make sure we update the selected mask only 👍

@adamaji
Copy link
Contributor Author

adamaji commented Apr 4, 2022

Closing because this PR will be superseded by work from #717 .

@adamaji adamaji closed this Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants