def visual_coannotation(lnds_user, lnds_refs, path_dataset, path_user, img_name, path_visu): """ visualise the co-annotation show consensus annotation and use annotation :param DF lnds_user: loaded DataFrame :param DF lnds_refs: loaded DataFrame :param path_dataset: path to the image dataset (root) :param name_set: name of the image set :param name_user_scale: annotation folder containing user name and used scale :param img_name: particular image/annotation/stain name :param str|None path_visu: path to output :return str: figure path """ name_set, name_user_scale = path_user.split(os.sep)[-2:] user, scale = parse_path_user_scale(name_user_scale) folder_scale = TEMPLATE_FOLDER_SCALE % scale image = None if path_dataset is not None and os.path.isdir(path_dataset): path_dir = os.path.join(path_dataset, name_set, folder_scale) paths_image = find_images(path_dir, img_name) image = load_image(paths_image[0]) if paths_image else None lnds_user = lnds_user * (scale / 100.) lnds_refs = lnds_refs * (scale / 100.) fig = figure_image_landmarks(lnds_refs, image, lnds_user, lnds2_name=user) fig_name = NAME_FIGURE_COANNOT % img_name path_dir = os.path.join(path_visu, name_set, name_user_scale) create_folder_path(path_dir) path_fig = os.path.join(path_dir, fig_name) fig.savefig(path_fig) plt.close(fig) return path_fig
def load_image_landmarks(lnds_img_pair): """ load image and related landmarks :param (str, str) lnds_img_pair: tuple with paths :return (str, str, ndarray, ndarray): image folder and name, landmarks and image """ p_lnds, p_img = lnds_img_pair name = os.path.splitext(os.path.basename(p_img))[0] lnd = pd.read_csv(p_lnds) img = load_image(p_img) folder = os.path.basename(os.path.dirname(p_lnds)) return folder, name, lnd, img
def export_visual_set_scale(d_paths): """ export, visualise given set in particular scale :param {str: str} d_paths: dictionary with path patterns :return int: number of processed items """ list_lnds = sorted(glob.glob(os.path.join(d_paths['landmarks'], '*.csv'))) list_lnds_imgs = [] # fined relevant images to the given landmarks for p_lnds in list_lnds: name_ = os.path.splitext(os.path.basename(p_lnds))[0] p_imgs = find_images(d_paths['images'], name_) if p_imgs: list_lnds_imgs.append((p_lnds, sorted(p_imgs)[0])) # if there are no images or landmarks, skip it... if not list_lnds_imgs: logging.debug('no image-landmarks to show...') return 0 # create the output folder if not os.path.isdir(d_paths['output']): os.makedirs(d_paths['output']) # draw and export image-landmarks for p_lnds, p_img in list_lnds_imgs: name_ = os.path.splitext(os.path.basename(p_img))[0] img = load_image(p_img) if img is None: continue fig = figure_image_landmarks(pd.read_csv(p_lnds), img) fig.savefig(os.path.join(d_paths['output'], name_ + '.pdf')) plt.close(fig) # draw and export PAIRS of image-landmarks path_pairs = [(p1, p2) for i, p1 in enumerate(list_lnds_imgs) for p2 in list_lnds_imgs[i + 1:]] for p1, p2 in path_pairs: export_visual_pairs(p1, p2, d_paths['output']) return len(list_lnds_imgs)