def test_imfuse(): """Test function for imfuse() """ # path and name of test files im1_name = os.path.join(data_path, "left.png") im2_name = os.path.join(data_path, "right.png") # read test images and their masks im1 = cv2.imread(im1_name) im2 = cv2.imread(im2_name) # fuse images imf = pymg.imfuse(im1, im2) # plot images plt.close('all') plt.subplot(221) plt.imshow(im1) plt.title("Left image") plt.subplot(222) plt.imshow(im2) plt.title("Right image") plt.subplot(212) plt.imshow(imf) plt.title("imfuse") plt.show(block=False)
preddice_test_pred = dice_model.predict( im_test[i, :, :, :].reshape((1, ) + im_test.shape[1:])) # plot results plt.clf() plt.subplot(321) plt.imshow(im_test[i, :, :, :]) plt.title('histology, i = ' + str(i)) plt.subplot(323) plt.imshow(seg_test[i, :, :, 0]) plt.title('ground truth contours') plt.subplot(324) aux = cv2.dilate(predseg_test[i, :, :, 0], kernel=np.ones(shape=(3, 3))) # dilate for better visualisation plt.imshow(pystoim.imfuse(seg_test[i, :, :, 0], aux).astype(np.float32)) plt.title('ground truth (gree) vs. \npredicted (purple) contours') plt.subplot(325) plt.imshow(preddice_test[i, :, :, 0], cmap='Greys_r') plt.title('ground truth Dice coeff') plt.subplot(326) plt.imshow(preddice_test_pred[0, :, :, 0]) plt.title('estimated Dice coeff') # visualise results i = 18 # run image through network preddice_test_pred = dice_model.predict( im_test[i, :, :, :].reshape((1, ) + im_test.shape[1:]))
qual = cytometer.utils.match_overlapping_labels( labels_test=labels[i, :, :, 0], labels_ref=reflab[i, :, :, 0]) labels_qual_augmented = cytometer.utils.paint_labels( labels=labels_augmented, paint_labs=qual['lab_test'], paint_values=qual['dice']) # compare randomly transformed histology to corresponding Dice coefficient plt.clf() plt.subplot(321) plt.imshow(aux_dataset['im'][0, :, :, :]) plt.subplot(322) plt.imshow(labels_qual_augmented, cmap='Greys_r') plt.subplot(323) aux = pystoim.imfuse(aux_dataset['im'][0, :, :, :], labels_qual_augmented) plt.imshow(aux, cmap='Greys_r') plt.subplot(324) plt.imshow(labels_augmented) plt.subplot(325) plt.imshow(labels_borders_augmented) # filenames for the Dice coefficient augmented files predlab_file = os.path.join( training_augmented_dir, base_name.replace( 'im_seed_nan_', 'predlab_kfold_' + str(fold_i).zfill(2) + '_seed_' + str(seed).zfill(3) + '_')) predseg_file = os.path.join( training_augmented_dir, base_name.replace(
mask = mask.astype(np.float32) if DEBUG: for i in range(n_im): print(' ** Image: ' + str(i) + '/' + str(n_im - 1)) plt.clf() plt.subplot(221) plt.imshow(im[i, :, :, :]) plt.subplot(222) plt.imshow(dmap[i, :, :, 0]) plt.subplot(223) plt.imshow(mask[i, :, :, 0]) plt.subplot(224) a = im[i, :, :, :] b = mask[i, :, :, 0] plt.imshow(pystoim.imfuse(a, b)) plt.show() '''Receptive field ''' # list of model files to inspect model_files = glob.glob(os.path.join(saved_models_dir, model_name)) receptive_field_size = [] for model_file in model_files: print(model_file) # estimate receptive field of the model def model_build_func(input_shape):