highdicom: Provide meaningful error message if all Segmentation frames are empty

When using the static method of _omit_empty_frames, if there are no empty frames present (frames without positive pixels), then numpy thows an exception with regard to the empty non_empty_frames list passed into np.stack.

https://github.com/herrmannlab/highdicom/blob/95f39dd722ae6d357af3f942e2130d0ff4d68bfc/src/highdicom/seg/sop.py#L1037-L1078

May I suggest just a check on the array before proceeding?

        if len(non_empty_frames) == 0:
            return (pixel_array, plane_positions, []) 

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 24 (8 by maintainers)

Most upvoted comments

My personal leaning is to continue to allow segmentations with no “positive” pixels. The reason being that otherwise it becomes difficult to differentiate between a segmentation that was run and produced no positive output, and simply the lack of a segmentation. If we think in the context of an automated process (my bias of course), I would not want a segmentation process that crashed and therefore produced no output segmentation to be interpreted as the absence of a finding. This becomes especially important when segmentation processes are effectively serving as detectors too, most commonly for abnormalities such as lesions, tumors, strokes, stones, etc. The only way around this I think is to always accompany by an SR, and while I think that is probably a good idea, I imagine many people will not do this.

Anyway, we can leave this issue open to discuss with @dclunie but in the meantime I will create a PR later to improve the obviously bad error message users are currently getting “empty” segmentations.

@fedorov it sounds like you are concerned about current OHIF not having features to make it clear that segmentations are empty, and that’s a fair issue. But I agree with the sentiment that @CPBridge summarized as the ability to “differentiate between a segmentation that was run and produced no positive output, and simply the lack of a segmentation”.

To me, for example, running a tumor segmentation and getting an empty result would be a very positive thing. Running a tumor segmentation and getting no result would be worrisome. The first would have metadata about the source data, the version of the segmentation algorithm, the date it was run, etc. and the result would be a clean bill of health. The second would just be a void of information. I agree we can have other metadata channels to further clarify the semantics, but even so having a blank segmentation result seems like a valid and useful construct.

@CPBridge I would suggest not raising an error when omit_empty_frames is True and no non-empty frames exist, but instead log a warning message and encode all frames. If one performs segmentation, one may not know upfront whether the operation will result in any pixel will be assigned a value greater than one and one would thus have to always set omit_empty_frames to False to be on the save side.

Apologies for the delayed response. @CPBridge This is occurring in my use case when the pixel array contains entirely False values, i.e. all of the contained frames do not contain positive pixels. Thank you for the activity on this!