def _visualise_registration(self, df_row): """ visualise the registration results according what landmarks were estimated - in registration or moving frame :param (int, dict) df_row: tow from iterated table """ _, dict_row = df_row image_ref = tl_io.load_image(dict_row[COL_IMAGE_REF]) points_ref = tl_io.load_landmarks(dict_row[COL_POINTS_REF]) points_move = tl_io.load_landmarks(dict_row[COL_POINTS_MOVE]) # visualise particular experiment by idx if COL_POINTS_REF_WARP in dict_row: if COL_IMAGE_REF_WARP not in dict_row \ or not isinstance(dict_row[COL_IMAGE_REF_WARP], str): logging.warning('missing registered image "%s"', COL_IMAGE_REF_WARP) return None if COL_POINTS_REF_WARP not in dict_row \ or not isinstance(dict_row[COL_POINTS_REF_WARP], str): logging.warning('missing registered landmarks "%s"', COL_POINTS_REF_WARP) return None image_warp = tl_io.load_image(dict_row[COL_IMAGE_REF_WARP]) points_warp = tl_io.load_landmarks(dict_row[COL_POINTS_REF_WARP]) # draw image with landmarks image = tl_visu.draw_image_points(image_warp, points_warp) tl_io.save_image(os.path.join(dict_row[COL_REG_DIR], NAME_IMAGE_MOVE_WARP_POINTS), image) # visualise the landmarks move during registration fig = tl_visu.draw_images_warped_landmarks(image_ref, image_warp, points_move, points_ref, points_warp) elif COL_POINTS_MOVE_WARP in dict_row: image_move = tl_io.load_image(dict_row[COL_IMAGE_MOVE]) # image_warp = tl_io.load_image(row['Moving image, Transf.']) points_warp = tl_io.load_landmarks(dict_row[COL_POINTS_MOVE_WARP]) # draw image with landmarks image = tl_visu.draw_image_points(image_move, points_warp) tl_io.save_image(os.path.join(dict_row[COL_REG_DIR], NAME_IMAGE_REF_POINTS_WARP), image) # visualise the landmarks move during registration fig = tl_visu.draw_images_warped_landmarks(image_ref, image_move, points_ref, points_move, points_warp) else: logging.error('not allowed scenario: no output image or landmarks') fig, _ = tl_visu.create_figure((1, 1)) path_fig = os.path.join(dict_row[COL_REG_DIR], NAME_IMAGE_REGIST_VISUAL) tl_visu.export_figure(path_fig, fig) return path_fig
def _visualise_registration(self, df_row): """ visualise the registration results according what landmarks were estimated - in registration or moving frame :param (int, dict) df_row: tow from iterated table """ _, row = df_row path_img_ref, _, path_lnds_ref, path_lnds_move = self._get_paths(row) image_ref = tl_io.load_image(path_img_ref) points_ref = tl_io.load_landmarks(path_lnds_ref) points_move = tl_io.load_landmarks(path_lnds_move) # visualise particular experiment by idx if COL_POINTS_MOVE_WARP in row: fig = self.__visual_image_move_warp_lnds_move_warp( row, image_ref, points_ref, points_move) if fig is None: return None elif COL_POINTS_REF_WARP in row: fig = self.__visual_image_ref_warp_lnds_move_warp( row, image_ref, points_ref, points_move) else: logging.error('Visualisation: no output image or landmarks') fig, _ = tl_visu.create_figure((1, 1)) path_fig = os.path.join(self._get_path_reg_dir(row), NAME_IMAGE_WARPED_VISUAL) tl_visu.export_figure(path_fig, fig) return path_fig
def __visual_image_ref_warp_lnds_move_warp(self, record, image_ref, points_ref, points_move): """ visualise the case with warped reference landmarks to the move frame :param {} record: row with the experiment :param ndarray image_ref: reference image :param ndarray points_ref: landmarks in reference frame :param ndarray points_move: landmarks in moving frame :return obj: """ image_move = tl_io.load_image(self._update_path( record[COL_IMAGE_MOVE])) # image_warp = tl_io.load_image(row['Moving image, Transf.']) path_points_warp = self._update_path(record[COL_POINTS_REF_WARP], 'expt') points_warp = tl_io.load_landmarks(path_points_warp) # draw image with landmarks image = tl_visu.draw_image_points(image_move, points_warp) tl_io.save_image( os.path.join(self._get_path_reg_dir(record), NAME_IMAGE_REF_POINTS_WARP), image) # visualise the landmarks move during registration fig = tl_visu.draw_images_warped_landmarks(image_ref, image_move, points_ref, points_move, points_warp) return fig
def __compute_landmarks_statistic(self, df_row): """ after successful registration load initial nad estimated landmarks afterwords compute various statistic for init, and final alignment :param (int, dict) df_row: tow from iterated table """ idx, row = df_row path_img_ref, _, path_lnds_ref, path_lnds_move = self._get_paths(row) # load initial landmarks points_ref = tl_io.load_landmarks(path_lnds_ref) points_move = tl_io.load_landmarks(path_lnds_move) points_warped = [] img_size = tl_io.load_image(path_img_ref).shape[:2] # compute statistic self.__compute_landmarks_inaccuracy(idx, points_ref, points_move, 'init', img_size) # load transformed landmarks if COL_POINTS_REF_WARP in row: points_target = points_move path_landmarks = self._update_path(row[COL_POINTS_REF_WARP], 'expt') elif COL_POINTS_MOVE_WARP in row: points_target = points_ref path_landmarks = self._update_path(row[COL_POINTS_MOVE_WARP], 'expt') else: logging.error('Statistic: no output landmarks') points_target, path_landmarks = [], None # load landmarks if isinstance(path_landmarks, str): points_warped = tl_io.load_landmarks(path_landmarks) # compute statistic img_size = tl_io.load_image(path_img_ref).shape[:2] if list(points_target) and list(points_warped): self.__compute_landmarks_inaccuracy(idx, points_target, points_warped, 'final', img_size)
def __visual_image_move_warp_lnds_move_warp(self, record, image_ref, points_ref, points_move): """ visualise the case with warped moving image and landmarks to the reference frame so they are simple to overlap :param {} record: row with the experiment :param ndarray image_ref: :param ndarray points_move: :param ndarray points_ref: :return obj | None: """ if COL_IMAGE_MOVE_WARP not in record \ or not isinstance(record[COL_IMAGE_MOVE_WARP], str): logging.warning('Missing registered image "%s"', COL_IMAGE_MOVE_WARP) return None if COL_POINTS_MOVE_WARP not in record \ or not isinstance(record[COL_POINTS_MOVE_WARP], str): logging.warning('Missing registered landmarks "%s"', COL_POINTS_MOVE_WARP) return None path_image_warp = self._update_path(record[COL_IMAGE_MOVE_WARP], 'expt') image_warp = tl_io.load_image(path_image_warp) path_points_warp = self._update_path(record[COL_POINTS_MOVE_WARP], 'expt') points_warp = tl_io.load_landmarks(path_points_warp) # draw image with landmarks image = tl_visu.draw_image_points(image_warp, points_warp) tl_io.save_image( os.path.join(self._get_path_reg_dir(record), NAME_IMAGE_MOVE_WARP_POINTS), image) # visualise the landmarks move during registration fig = tl_visu.draw_images_warped_landmarks(image_ref, image_warp, points_move, points_ref, points_warp) return fig