0

I'm trying to perform a 2D multi-class semantic segmentation on ACDC dataset which contains .nifti images: dataset link

The original shape of the masks is (img_heght, img_wdth, img_dpth), so I stored the ground truth slices in np array format in the shape (img_hgt, img_wdth, n_classes)=(128,128,4)

This part of the code is on how I save images and masks:

image_list = ED_image_list
mask_list = ED_mask_list

temp_image_ED=nib.load(image_list[50]).get_fdata()
temp_image_ED=scaler.fit_transform(temp_image_ED.reshape(-1, temp_image_ED.shape[-1])).reshape(temp_image_ED.shape)

zslices = temp_image_ED.shape[2]

temp_mask_ED=nib.load(mask_list[25]).get_fdata()

temp_mask_ED=temp_mask_ED.astype(np.uint8)

#resizing data
temp_image_ED = resize(temp_image_ED, (128, 128, zslices))
temp_image_ED = np.expand_dims(temp_image_ED, axis = 3)

temp_mask_ED = resize(temp_mask_ED, (128, 128, zslices))

temp_mask_ED= to_categorical(temp_mask_ED, num_classes=4)

for slice in range(zslices):
   np.save('/content/drive/MyDrive/ACDC_Dataset_Processed/test/np_array/ES/2D_data/uncropped/img/ED_image'+str(img+1)+'_'+str(slice+1)+'.npy', temp_image_ED[:,:,slice])
      np.save('/content/drive/MyDrive/ACDC_Dataset_Processed/test/np_array/ES/2D_data/uncropped/msk/ED_mask'+str(img+1)+'_'+str(slice+1)+'.npy', temp_mask_ED[:,:,slice])

And this part on how I load and visualize masks:

image = np.load("/content/drive/MyDrive/ACDC_Dataset_Processed/test/np_array/ES/2D_data/uncropped/msk/ED_mask49_5.npy")

image=np.argmax(image, axis=2)

plt.figure(figsize=(12, 8))
plt.subplot(231)
plt.imshow(image[:,:])
plt.title('mask')

But I have got this: mask

I encoutred this problem also with visualizing the predicted masks by the UNet model

#############################################
#Predict on a few test images, one at a time
#Try images: 
img_num = 30

test_img = np.load("/content/drive/MyDrive/ACDC_Dataset_Processed/test/np_array/ED/2D_data/uncropped/train/img/ED_image"+str(img_num)+"_4.npy")

test_mask = np.load("/content/drive/MyDrive/ACDC_Dataset_Processed/test/np_array/ED/2D_data/uncropped/train/msk/ED_mask"+str(img_num)+"_4.npy")
test_mask_argmax=np.argmax(test_mask, axis=2)

test_img_input = np.expand_dims(test_img, axis=0)
test_prediction = my_model.predict(test_img_input)
test_prediction_argmax=np.argmax(test_prediction, axis=3)[0,:,:]

#n_slice=random.randint(0, test_prediction_argmax.shape[2])
n_slice = 55
plt.figure(figsize=(12, 8))
plt.subplot(231)
plt.title('Testing Image')
plt.imshow(test_img[:,:].squeeze(), cmap='gray')
plt.subplot(232)
plt.title('Testing Label')
plt.imshow(test_mask_argmax[:,:])
plt.subplot(233)
plt.title('Prediction on test image')
plt.imshow(test_prediction_argmax[:,:])
plt.show()

This is what I'm having by executing the above code: image/ground truth/predicted mask

0 Answers0