from typing import Tuple import numpy as np from numpy.core.multiarray import normalize_axis_index from numpy.typing import NDArray def sobel(arr: NDArray, axes: Tuple[int, int] = (-2, -1)) -> NDArray: """Compute the Sobel filter of an image Parameters ---------- arr : NDArray Input image axes : Tuple[int, int], optional Axes over which to compute the filter, by default (-2, -1) Returns ------- NDArray Output """ # Only accepts 2D arrays if arr.ndim != 2: raise NotImplementedError # Ensure that the axis[0] is the first axis, and axis[1] is the second axis. # The obscure `normalize_axis_index` converts negative indices to indices between # 0 and arr.ndim - 1. if any(normalize_axis_index(ax, arr.ndim) != i for i, ax in zip(range(2), axes)): raise NotImplementedError pass