MIC-DKFZ / nnUNet

Apache License 2.0
5.72k stars 1.73k forks source link

A question on exchanging label 1 and 2 in Dataset137_Bra21.py #2056

Closed TSbme closed 4 months ago

TSbme commented 6 months ago

The final result of these two lines of code, why isn't it that the points with values of 1 and 2 both become 2? image

Why isn't it written in this following form?

seg_new[img_npy == 4] = 3 seg_new[img_npy == 2] = -1 # Temporarily change 2 to -1 seg_new[img_npy == 1] = 2 seg_new[img_npy == -1] = 1 # Then change -1 to 1

GregorKoehler commented 5 months ago

Hi @TSbme , I'm not sure I understand your question correctly here, but it indeed does seem strange that the labels 1 and 2 are flipped here. Can you link this part of the code in the current version?

TSbme commented 5 months ago

Hi @GregorKoehler , Thanks for your reply! The path is 'nnunetv2/dataset_conversion/Dataset137_BraTS21.py' Please check the following fuction. def convert_labels_back_to_BraTS(seg: np.ndarray): new_seg = np.zeros_like(seg) new_seg[seg == 1] = 2 new_seg[seg == 3] = 4 new_seg[seg == 2] = 1 return new_seg

FabianIsensee commented 4 months ago

Nothing is overwritten and we need no temporary changes because we write to a new target array which is initialized with 0 and we read from the original segmentation. The reason two labels are flipped is because of consistency with other brain tumor segmentation projects I was working with at the time. What order the labels are in doesn't matter. If you change it please remember to change the regions / region_class_order accordingly. My recommendation would be to leave things as they are

GregorKoehler commented 4 months ago

Hi @TSbme,

I hope Fabian answered your questions! I'll close the issue for now, but feel free to reopen if you need further clarification!