def split_image_into_sudoku_pieces_adaptive_global(image, otsu_local=False, apply_gaussian=False): L = image.shape[0] d = int(np.ceil(L / 9)) dd = d // 5 output = [] if apply_gaussian: image = gaussian_filter(image, sigma=1.0) if not otsu_local: image = to_binary_adaptive(image) for k in range(9): this_row = [] start_row_i = max([k * d - dd, 0]) stop_row_i = min([(k + 1) * d + dd, L]) for kk in range(9): start_col_i = max([kk * d - dd, 0]) stop_col_i = min([(kk + 1) * d + dd, L]) i = image[start_row_i:stop_row_i, start_col_i:stop_col_i].copy() if otsu_local: i = to_binary_otsu(i) i = binary_opening(i) i = to_binary_otsu(i) if apply_gaussian: i = to_binary_otsu(binary_dilation(i)) this_row.append(i) output.append(this_row) return output, image
def get_centered_blob(img, border_size=1): img = to_binary_otsu(img) blob = _get_most_centered_blob(img) if blob is None: blob = _get_most_centered_blob(to_binary_otsu(binary_dilation(img))) if blob is None: return None blob_img = add_border(blob, (28, 28), border_size=border_size) blob_img = to_binary_otsu(blob_img) return blob_img
def get_centered_blob(img, border_size=1): img = to_binary_otsu(img) blob = _get_most_centered_blob(img) if blob is None: blob = _get_most_centered_blob(to_binary_otsu(binary_dilation(img))) if blob is None: return None blob_img = add_border(blob, (28, 28), border_size=border_size) blob_img = to_binary_otsu(blob_img) return blob_img