Skip to content

Instantly share code, notes, and snippets.

@cako
Last active June 25, 2023 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cako/7a13e33bed7607cdd18cda442b643c8a to your computer and use it in GitHub Desktop.
Save cako/7a13e33bed7607cdd18cda442b643c8a to your computer and use it in GitHub Desktop.
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