Specify if input data is onehot for KeepLargestConnectedComponent
#3578
Replies: 6 comments 6 replies
-
Hi @YuanTingHsieh , Could you please help share some comments here? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
-
For single channel data, you should pass For multiple channel data, if the first channel is background, and you have 5 channels (categories) in total, you can pass |
Beta Was this translation helpful? Give feedback.
-
@YuanTingHsieh I can understand this by reading the doc. This is exactly what I mean by the inconvenience, because I'm always using onehot format no matter the data are single or multiple channels, and I'm not putting the background on the first channel. So I'll have to add an if clause when specifying But it seems that if I put the background on the first channel, then it becomes consistent for both single and multiple channel data. Is this the preferred way to work with? |
Beta Was this translation helpful? Give feedback.
-
Let's say your single channel data use pixel 1 as foreground. Your multi-channel data has 3 channels and no background. This is the current usage. |
Beta Was this translation helpful? Give feedback.
-
@YuanTingHsieh Hello, sorry for the late reply. I mean, I want to treat "single-channel data" as "data that can have variable channels only just has one channel". So in this case, I still want to pass |
Beta Was this translation helpful? Give feedback.
-
Just coming here from #3776 (thanks @Nic-Ma). If something is one-hotted, then the sum along the channel dimension should be one. If an image is one-hotted, but only contains 1 channel, then I feel it should be filled with all 1s and be meaningless. If we're dealing with binary data, then the onehot will have 2 channels. Perhaps I'm missing something, but is there a legitimate use case where the data is one-hotted but only has 1 channel dimension? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
I'm using the post-processing transform
KeepLargestConnectedComponent
, its calculation depends on if the input data is in onehot format. Currently, the transform determines if the input data is onehot by checking the number of channels.MONAI/monai/transforms/post/array.py
Line 338 in f6648a3
I think this may be inconvenient and error-prone. I'm working on different experiments with different numbers of segmentation categories and I'm always using onehot format. While some of them may only have one category, in this case, the current implementation will treat the input data as non-onehot. If I simply specify
applied_labels
with the number of channels, this would cause unexpected results.Describe the solution you'd like
Add
onehot
parameter in__init__
ofKeepLargestConnectedComponent
(e.g., just like whatDiceLoss
does). Consider making it required, or keep the current behavior as default and deprecate it gradually.Beta Was this translation helpful? Give feedback.
All reactions