def perform_orientation_swap(path_img, path_out, img_template, swap_type=SWAP_CONDITION): """ compute the density in front adn back part of the egg rotate eventually we split the egg into thirds instead half because the middle part variate :param str path_img: path to input image :param str path_out: path to output folder :param ndarray img_template: template / mean image :param str swap_type: used swap condition """ img, _ = tl_data.load_image_2d(path_img) # cut the same image img_size = img_template.shape img = img[:img_size[0], :img_size[1]] if swap_type == 'cc': b_swap = condition_swap_correl(img, img_template) else: b_swap = condition_swap_density(img) if b_swap: img = img[::-1, ::-1, :] path_img = os.path.join(path_out, os.path.basename(path_img)) tl_data.export_image(path_img, img)
def extract_ellipse_object(idx_row, path_images, path_out, norm_size): """ cut the image selection according ellipse parameters and scale it into given size to have all image in the end the same sizes :param (int, row) idx_row: index and row with ellipse parameters :param str path_images: path to the image folder :param str path_out: path to output folder :param (int, int) norm_size: output image size """ _, row = idx_row # select image with this name and any extension list_imgs = glob.glob(os.path.join(path_images, row['image_name'] + '.*')) path_img = sorted(list_imgs)[0] img, _ = tl_data.load_image_2d(path_img) # create mask according to chosen ellipse ell_params = row[COLUMNS_ELLIPSE].tolist() mask = ell_fit.add_overlap_ellipse(np.zeros(img.shape[:2], dtype=int), ell_params, 1) # cut the particular image img_cut = tl_data.cut_object(img, mask, 0, use_mask=True, bg_color=None) # scaling according to the normal size img_norm = transform.resize(img_cut, norm_size) path_img = os.path.join(path_out, os.path.basename(path_img)) tl_data.export_image(path_img, img_norm)