def export_visual(name, annot, segm, img, path_out, drop_labels, segm_alpha=1.): """ given visualisation of segmented image and annotation :param dict df_row: :param str path_out: path to the visualisation directory :param [int] drop_labels: whether skip some labels """ # relabel for simpler visualisations of class differences if np.sum(annot < 0) > 0: annot[annot < 0] = -1 _, lut, _ = relabel_sequential(annot + 1) lut = fill_lut(lut, segm, offset=1) annot = lut[annot.astype(int) + 1] - 1 segm = lut[segm.astype(int) + 1] - 1 else: annot, lut, _ = relabel_sequential(annot) lut = fill_lut(lut, segm, offset=0) segm = lut[segm.astype(int)] # normalise alpha in range (0, 1) segm_alpha = tl_visu.norm_aplha(segm_alpha) fig = tl_visu.figure_overlap_annot_segm_image(annot, segm, img, drop_labels=drop_labels, segm_alpha=segm_alpha) logging.debug('>> exporting -> %s', name) fig.savefig(os.path.join(path_out, '%s.png' % name)) plt.close(fig)
def visualise_overlap( path_img, path_seg, path_out, b_img_scale=BOOL_IMAGE_RESCALE_INTENSITY, b_img_contour=BOOL_SAVE_IMAGE_CONTOUR, b_relabel=BOOL_ANNOT_RELABEL, segm_alpha=MIDDLE_ALPHA_OVERLAP, ): img, _ = tl_data.load_image_2d(path_img) seg, _ = tl_data.load_image_2d(path_seg) # normalise alpha in range (0, 1) segm_alpha = tl_visu.norm_aplha(segm_alpha) if b_relabel: seg, _, _ = segmentation.relabel_sequential(seg.copy()) if img.ndim == 2: # for gray images of ovary img = np.rollaxis(np.tile(img, (3, 1, 1)), 0, 3) if b_img_scale: p_low, p_high = np.percentile(img, q=(3, 98)) # plt.imshow(255 - img, cmap='Greys') img = exposure.rescale_intensity(img, in_range=(p_low, p_high), out_range='uint8') if b_img_contour: path_im_visu = os.path.splitext(path_out)[0] + '_contour.png' img_contour = segmentation.mark_boundaries(img[:, :, :3], seg, color=COLOR_CONTOUR, mode='subpixel') plt.imsave(path_im_visu, img_contour) # else: # for colour images of disc # mask = (np.sum(img, axis=2) == 0) # img[mask] = [255, 255, 255] fig = tl_visu.figure_image_segm_results(img, seg, SIZE_SUB_FIGURE, mid_labels_alpha=segm_alpha, mid_image_gray=MIDDLE_IMAGE_GRAY) fig.savefig(path_out) plt.close(fig)