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
评论列表
文章目录