bowang-lab / MedSAM

Segment Anything in Medical Images
https://www.nature.com/articles/s41467-024-44824-z
Apache License 2.0
2.98k stars 412 forks source link

关于多标签掩码的处理 #297

Closed LReion closed 2 months ago

LReion commented 2 months ago

我的训练集的图像和标签都是3d的,但是标签是多标签在同一个通道中,用不同的像素值标记的结构。但是我看了一下pre_CT_MR.py文件中的预处理,只判断了一个像素值大于0也就是前景,那么我有一个问题,如果是我这样的多标签的应该如何处理。或者说需要单独将每个标签单独做成图像和其对应的二值掩码。

ff98li commented 2 months ago

Hi there,

You don't need to convert the masks into one-hot encodings or create separate binary masks for each label. When you mentioned foreground values, I assume you were referring to line 130 in the script. The purpose is to identify slices that contain the organs/lesions of interest by checking if any labeled pixel values are greater than zero in ground truth, and we are only retaining slices that contain the organs/lesions of interest that are relevant for training.

LReion commented 2 months ago

Hello, I saw that all the slices that were judged to be foreground pixel values ​​were selected. That means I don't need to convert the mask to a one-hot or binary mask separately. In other words, can the labels of multi-organ masks also be processed and directly trained?

LReion commented 2 months ago

In addition, one label 12 is removed. If I need to perform segmentation training for each label, should I set this to an empty list, line 75 in pre_CT_MR.

ff98li commented 2 months ago

Hello, I saw that all the slices that were judged to be foreground pixel values ​​were selected. That means I don't need to convert the mask to a one-hot or binary mask separately. In other words, can the labels of multi-organ masks also be processed and directly trained?

That's correct. The preprocessing script can handle the multi-label masks.

In addition, one label 12 is removed. If I need to perform segmentation training for each label, should I set this to an empty list, line 75 in pre_CT_MR.

Yes, you will need to empty that list so that no label values are excluded from your dataset.

LReion commented 2 months ago

Thank you for your answer. Best wishes.