labels = np.unique(img)
one_hot = np.zeros((2, D, H, W))
for i in range(0, num_labels):
     seg_ =  img == labels[i]
     one_hot[i, :, :, :] = seg_[:, 0:img.shape[1], 0:img.shape[2], 0:img.shape[3]]