def detect_edges(lum: np.ndarray) -> np.ndarray:
    """Detect edges using the luma channel of a frame.

    Arguments:
        lum: 2D 8-bit image representing the luma channel of a frame.

    Returns:
        2D 8-bit image of the same size as the input, where pixels with values of 255
        represent edges, and all other pixels are 0.
    """
    # Initialize kernel.
    kernel_size = estimated_kernel_size(lum.shape[1], lum.shape[0])
    kernel = np.ones((kernel_size, kernel_size), np.uint8)

    # Estimate levels for thresholding.
    # TODO(0.6.3): Add config file entries for sigma, aperture/kernel size, etc.
    sigma: float = 1.0 / 3.0
    median = np.median(lum)
    low = int(max(0, (1.0 - sigma) * median))
    high = int(min(255, (1.0 + sigma) * median))

    # Calculate edges using Canny algorithm, and reduce noise by dilating the edges.
    # This increases edge overlap leading to improved robustness against noise and slow
    # camera movement. Note that very large kernel sizes can negatively affect accuracy.
    edges = cv2.Canny(lum, low, high)
    return cv2.dilate(edges, kernel)
Detect edges using the luma channel of a frame.

    Arguments:
        lum: 2D 8-bit image representing the luma channel of a frame.

    Returns:
        2D 8-bit image of the same size as the input, where pixels with values of 255
        represent edges, and all other pixels are 0.
    
animatediff/utils/util.py