Last active
June 25, 2023 22:54
-
-
Save cako/7a13e33bed7607cdd18cda442b643c8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment