def make_binary_mask(probs: np.ndarray, threshold: float = -1) -> np.ndarray: """ Computes the binary mask of the detected class from probabilities :param probs: array with values in range [0, 1] :param threshold: threshold between [0 and 1], if negative Otsu's adaptive threshold will be used :return: binary mask """ mask = binarization.thresholding(probs, threshold) mask = binarization.cleaning_binary(mask, kernel_size=5) return mask
def post_process_probs_ornament(probability_maps): binary_maps = np.zeros_like(probability_maps, np.uint8) binary_maps = np.delete(binary_maps, 0, 2) # Ornament binary_image = binarization.thresholding(probability_maps[:, :, 1], threshold=0.75) binary_image = binarization.cleaning_binary(binary_image, kernel_size=3) boxes = boxes_detection.find_boxes(binary_image, mode='rectangle', min_area=0.) bin_map = np.zeros_like(binary_maps) binary_maps[:, :, 0] = cv2.fillPoly(bin_map, boxes, (255, 0, 0))[:, :, 0] return binary_maps, boxes
def page_post_processing_fn(probs: np.ndarray, threshold: float=0.5, output_basename: str=None, kernel_size: int = 5) -> np.ndarray: """ Computes the binary mask of the detected Page from the probabilities outputed by network :param probs: array in range [0, 1] of shape HxWx2 :param threshold: threshold between [0 and 1], if negative Otsu's adaptive threshold will be used :param output_basename: :param kernel_size: size of kernel for morphological cleaning """ mask = binarization.thresholding(probs[:, :, 1], threshold=threshold) result = binarization.cleaning_binary(mask, size=kernel_size) if output_basename is not None: imsave('{}.png'.format(output_basename), result*255) return result