-
Notifications
You must be signed in to change notification settings - Fork 52
Update dicom_seg_writer_operator.py #517
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
base: main
Are you sure you want to change the base?
Conversation
Proposing these changes with respect to Project-MONAI#512 (comment) Signed-off-by: kavmar <[email protected]>
|
Hi @kavmar, Sorry for slow response as I am travelling over these few weeks. Thanks for stepping up and creating this PR. However, there are a few problems that I see here. Firstly, I feel strongly that a segment description should not be omitted purely because it does not happen to be present in a particular image. It conveys important information to the receiver of the file when a segment description is included when the corresponding segment is not present: it indicates that the creator of the file checked for the presence of that segment and determined that it was not present. This information is lost if you just omit all segments that are not present. Therefore, the proposed changes should be limited to correcting the mapping of input values to segment numbers stored in the file, and should not attempt to remove or change the segment descriptions themselves. Secondly, the proposed method for specifying this behaviour could be streamlined in my opinion. The Also, the logic to relabel the segmentation mask is currently a little overcomplicated and will be slow for large arrays. There is a simple numpy trick to do this efficiently in a single operation, see here. Another minor comment is that I would not make class properties "public" unless there is a good reason to do so. Therefore I would suggest renaming |
Hi @CPBridge and thanks for response.
I get your point. However, based on my experience, I am concerned with downstream usability. Imagine that the SEG is a result of a model, which is used as an initial segmentation of a multilabel segmentation, such as TotalSegmentator or Vista3D, and the consumer would use it to further finetune some of the classes. I case the input volume would be only a subregion (head) of all possible model outputs (wholebody), the resulting SEG file would have in your described situation all the classes and the user would need to manually check if there aren't any voxels miss classified. This would be very cumbersome, to go through all the classes and check them.
My proposal would leave the option to the user to have the current behavior and leave undetected classes in the SEG file. I am not trying to push my solution. Just to give a space to have the option for those who need or want it. That is why I introduced the parameter 'force_contiguous_labels = False'.
Cleaning up the code, as you propose is of course OK, including more clear names, ... How do we continue? |
A quick note: TotalSegmentator also exports only non-empty masks: https://github.com/wasserth/TotalSegmentator/blob/0fe651c7680d76f64dad9ae4a5be69290c184617/totalsegmentator/dicom_io.py#L150 |
Hi @kavmar I'm sorry again for my slowness here, and thanks for your response. I will try and monitor this thread more closely so that we can make progress!
Yes I think that it is fine to add an option, but I don't think it should be the default behaviour because the semantics are very different. It also would lead to odd situations like it being impossible to create an empty segmentation mask. How would you deal with that? It's definitely going to arise sometimes. Just error out? Or include all empty segments in that case?
Interesting, but I don't think it is especially important what one other tool chooses to do, I'm afraid.
There's just no mechanism to do that in a standardized way in DICOM, so I think we have to rule this out. We are limited by what is allowed by the format. I think for the purposes of the conversation we need to be clear that there are actually two quite distinct problems that you are trying to address here. They seem similar but they are actually totally separate:
Now of course, this creates quite some complexity because the options are combinatorial. The user may want one of these behaviours but not the other. so you need to deal with 4 situations: I am okay to try to support both options, but we need to recognize the complexity. I am not entirely sure which of the two questions Also I mentioned above the new LABELMAP segmentations, which don't have the limitation on consecutive segments. This is now fully supported in highdicom 0.24.0+ which is publicly released. Therefore, if you are more concerned about my question 1 above, we could just add an option for labelmap segmentations which would remove the constraint that segment numbers be consecutive and eliminate question 1 when the labelmap option is used. The downside is that currently only highdicom itself knows how to read and write these files at the moment. |
Hi @CPBridge
Proposing these changes with respect to #512 (comment)