prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  [PYTEST WARNING] Horn schunk
  ### Feature description
  
  @skief @poyea Please could you resolve this warning
  ```
  computer_vision/horn_schunck.py:15
    /home/runner/work/Python/Python/computer_vision/horn_schunck.py:15:
      DeprecationWarning: Please use `convolve` from the `scipy.ndimage` namespace, the `scipy.ndimage.filters` namespace is deprecated.
      from scipy.ndimage.filters import convolve
  ```
  
  origin: #7211
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `computer_vision/horn_schunck.py`
  Content:
  ```
  1 """
  2     The Horn-Schunck method estimates the optical flow for every single pixel of
  3     a sequence of images.
  4     It works by assuming brightness constancy between two consecutive frames
  5     and smoothness in the optical flow.
  6 
  7     Useful resources:
  8     Wikipedia: https://en.wikipedia.org/wiki/Horn%E2%80%93Schunck_method
  9     Paper: http://image.diku.dk/imagecanon/material/HornSchunckOptical_Flow.pdf
  10 """
  11 
  12 from typing import SupportsIndex
  13 
  14 import numpy as np
  15 from scipy.ndimage.filters import convolve
  16 
  17 
  18 def warp(
  19     image: np.ndarray, horizontal_flow: np.ndarray, vertical_flow: np.ndarray
  20 ) -> np.ndarray:
  21     """
  22     Warps the pixels of an image into a new image using the horizontal and vertical
  23     flows.
  24     Pixels that are warped from an invalid location are set to 0.
  25 
  26     Parameters:
  27         image: Grayscale image
  28         horizontal_flow: Horizontal flow
  29         vertical_flow: Vertical flow
  30 
  31     Returns: Warped image
  32 
  33     >>> warp(np.array([[0, 1, 2], [0, 3, 0], [2, 2, 2]]), \
  34     np.array([[0, 1, -1], [-1, 0, 0], [1, 1, 1]]), \
  35     np.array([[0, 0, 0], [0, 1, 0], [0, 0, 1]]))
  36     array([[0, 0, 0],
  37            [3, 1, 0],
  38            [0, 2, 3]])
  39     """
  40     flow = np.stack((horizontal_flow, vertical_flow), 2)
  41 
  42     # Create a grid of all pixel coordinates and subtract the flow to get the
  43     # target pixels coordinates
  44     grid = np.stack(
  45         np.meshgrid(np.arange(0, image.shape[1]), np.arange(0, image.shape[0])), 2
  46     )
  47     grid = np.round(grid - flow).astype(np.int32)
  48 
  49     # Find the locations outside of the original image
  50     invalid = (grid < 0) | (grid >= np.array([image.shape[1], image.shape[0]]))
  51     grid[invalid] = 0
  52 
  53     warped = image[grid[:, :, 1], grid[:, :, 0]]
  54 
  55     # Set pixels at invalid locations to 0
  56     warped[invalid[:, :, 0] | invalid[:, :, 1]] = 0
  57 
  58     return warped
  59 
  60 
  61 def horn_schunck(
  62     image0: np.ndarray,
  63     image1: np.ndarray,
  64     num_iter: SupportsIndex,
  65     alpha: float | None = None,
  66 ) -> tuple[np.ndarray, np.ndarray]:
  67     """
  68     This function performs the Horn-Schunck algorithm and returns the estimated
  69     optical flow. It is assumed that the input images are grayscale and
  70     normalized to be in [0, 1].
  71 
  72     Parameters:
  73         image0: First image of the sequence
  74         image1: Second image of the sequence
  75         alpha: Regularization constant
  76         num_iter: Number of iterations performed
  77 
  78     Returns: estimated horizontal & vertical flow
  79 
  80     >>> np.round(horn_schunck(np.array([[0, 0, 2], [0, 0, 2]]), \
  81     np.array([[0, 2, 0], [0, 2, 0]]), alpha=0.1, num_iter=110)).\
  82     astype(np.int32)
  83     array([[[ 0, -1, -1],
  84             [ 0, -1, -1]],
  85     <BLANKLINE>
  86            [[ 0,  0,  0],
  87             [ 0,  0,  0]]], dtype=int32)
  88     """
  89     if alpha is None:
  90         alpha = 0.1
  91 
  92     # Initialize flow
  93     horizontal_flow = np.zeros_like(image0)
  94     vertical_flow = np.zeros_like(image0)
  95 
  96     # Prepare kernels for the calculation of the derivatives and the average velocity
  97     kernel_x = np.array([[-1, 1], [-1, 1]]) * 0.25
  98     kernel_y = np.array([[-1, -1], [1, 1]]) * 0.25
  99     kernel_t = np.array([[1, 1], [1, 1]]) * 0.25
  100     kernel_laplacian = np.array(
  101         [[1 / 12, 1 / 6, 1 / 12], [1 / 6, 0, 1 / 6], [1 / 12, 1 / 6, 1 / 12]]
  102     )
  103 
  104     # Iteratively refine the flow
  105     for _ in range(num_iter):
  106         warped_image = warp(image0, horizontal_flow, vertical_flow)
  107         derivative_x = convolve(warped_image, kernel_x) + convolve(image1, kernel_x)
  108         derivative_y = convolve(warped_image, kernel_y) + convolve(image1, kernel_y)
  109         derivative_t = convolve(warped_image, kernel_t) + convolve(image1, -kernel_t)
  110 
  111         avg_horizontal_velocity = convolve(horizontal_flow, kernel_laplacian)
  112         avg_vertical_velocity = convolve(vertical_flow, kernel_laplacian)
  113 
  114         # This updates the flow as proposed in the paper (Step 12)
  115         update = (
  116             derivative_x * avg_horizontal_velocity
  117             + derivative_y * avg_vertical_velocity
  118             + derivative_t
  119         )
  120         update = update / (alpha**2 + derivative_x**2 + derivative_y**2)
  121 
  122         horizontal_flow = avg_horizontal_velocity - derivative_x * update
  123         vertical_flow = avg_vertical_velocity - derivative_y * update
  124 
  125     return horizontal_flow, vertical_flow
  126 
  127 
  128 if __name__ == "__main__":
  129     import doctest
  130 
  131     doctest.testmod()
  132
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/computer_vision/horn_schunck.py b/computer_vision/horn_schunck.py
  --- a/computer_vision/horn_schunck.py
  +++ b/computer_vision/horn_schunck.py
  @@ -12,7 +12,7 @@
   from typing import SupportsIndex
   
   import numpy as np
  -from scipy.ndimage.filters import convolve
  +from scipy.ndimage import convolve
   
   
   def warp(
  
verification_info: {"golden_diff": "diff --git a/computer_vision/horn_schunck.py b/computer_vision/horn_schunck.py\n--- a/computer_vision/horn_schunck.py\n+++ b/computer_vision/horn_schunck.py\n@@ -12,7 +12,7 @@\n from typing import SupportsIndex\n \n import numpy as np\n-from scipy.ndimage.filters import convolve\n+from scipy.ndimage import convolve\n \n \n def warp(\n", "issue": "[PYTEST WARNING] Horn schunk\n### Feature description\r\n\r\n@skief @poyea Please could you resolve this warning\r\n```\r\ncomputer_vision/horn_schunck.py:15\r\n  /home/runner/work/Python/Python/computer_vision/horn_schunck.py:15:\r\n    DeprecationWarning: Please use `convolve` from the `scipy.ndimage` namespace, the `scipy.ndimage.filters` namespace is deprecated.\r\n    from scipy.ndimage.filters import convolve\r\n```\r\n\r\norigin: #7211\n", "before_files": [{"content": "\"\"\"\n    The Horn-Schunck method estimates the optical flow for every single pixel of\n    a sequence of images.\n    It works by assuming brightness constancy between two consecutive frames\n    and smoothness in the optical flow.\n\n    Useful resources:\n    Wikipedia: https://en.wikipedia.org/wiki/Horn%E2%80%93Schunck_method\n    Paper: http://image.diku.dk/imagecanon/material/HornSchunckOptical_Flow.pdf\n\"\"\"\n\nfrom typing import SupportsIndex\n\nimport numpy as np\nfrom scipy.ndimage.filters import convolve\n\n\ndef warp(\n    image: np.ndarray, horizontal_flow: np.ndarray, vertical_flow: np.ndarray\n) -> np.ndarray:\n    \"\"\"\n    Warps the pixels of an image into a new image using the horizontal and vertical\n    flows.\n    Pixels that are warped from an invalid location are set to 0.\n\n    Parameters:\n        image: Grayscale image\n        horizontal_flow: Horizontal flow\n        vertical_flow: Vertical flow\n\n    Returns: Warped image\n\n    >>> warp(np.array([[0, 1, 2], [0, 3, 0], [2, 2, 2]]), \\\n    np.array([[0, 1, -1], [-1, 0, 0], [1, 1, 1]]), \\\n    np.array([[0, 0, 0], [0, 1, 0], [0, 0, 1]]))\n    array([[0, 0, 0],\n           [3, 1, 0],\n           [0, 2, 3]])\n    \"\"\"\n    flow = np.stack((horizontal_flow, vertical_flow), 2)\n\n    # Create a grid of all pixel coordinates and subtract the flow to get the\n    # target pixels coordinates\n    grid = np.stack(\n        np.meshgrid(np.arange(0, image.shape[1]), np.arange(0, image.shape[0])), 2\n    )\n    grid = np.round(grid - flow).astype(np.int32)\n\n    # Find the locations outside of the original image\n    invalid = (grid < 0) | (grid >= np.array([image.shape[1], image.shape[0]]))\n    grid[invalid] = 0\n\n    warped = image[grid[:, :, 1], grid[:, :, 0]]\n\n    # Set pixels at invalid locations to 0\n    warped[invalid[:, :, 0] | invalid[:, :, 1]] = 0\n\n    return warped\n\n\ndef horn_schunck(\n    image0: np.ndarray,\n    image1: np.ndarray,\n    num_iter: SupportsIndex,\n    alpha: float | None = None,\n) -> tuple[np.ndarray, np.ndarray]:\n    \"\"\"\n    This function performs the Horn-Schunck algorithm and returns the estimated\n    optical flow. It is assumed that the input images are grayscale and\n    normalized to be in [0, 1].\n\n    Parameters:\n        image0: First image of the sequence\n        image1: Second image of the sequence\n        alpha: Regularization constant\n        num_iter: Number of iterations performed\n\n    Returns: estimated horizontal & vertical flow\n\n    >>> np.round(horn_schunck(np.array([[0, 0, 2], [0, 0, 2]]), \\\n    np.array([[0, 2, 0], [0, 2, 0]]), alpha=0.1, num_iter=110)).\\\n    astype(np.int32)\n    array([[[ 0, -1, -1],\n            [ 0, -1, -1]],\n    <BLANKLINE>\n           [[ 0,  0,  0],\n            [ 0,  0,  0]]], dtype=int32)\n    \"\"\"\n    if alpha is None:\n        alpha = 0.1\n\n    # Initialize flow\n    horizontal_flow = np.zeros_like(image0)\n    vertical_flow = np.zeros_like(image0)\n\n    # Prepare kernels for the calculation of the derivatives and the average velocity\n    kernel_x = np.array([[-1, 1], [-1, 1]]) * 0.25\n    kernel_y = np.array([[-1, -1], [1, 1]]) * 0.25\n    kernel_t = np.array([[1, 1], [1, 1]]) * 0.25\n    kernel_laplacian = np.array(\n        [[1 / 12, 1 / 6, 1 / 12], [1 / 6, 0, 1 / 6], [1 / 12, 1 / 6, 1 / 12]]\n    )\n\n    # Iteratively refine the flow\n    for _ in range(num_iter):\n        warped_image = warp(image0, horizontal_flow, vertical_flow)\n        derivative_x = convolve(warped_image, kernel_x) + convolve(image1, kernel_x)\n        derivative_y = convolve(warped_image, kernel_y) + convolve(image1, kernel_y)\n        derivative_t = convolve(warped_image, kernel_t) + convolve(image1, -kernel_t)\n\n        avg_horizontal_velocity = convolve(horizontal_flow, kernel_laplacian)\n        avg_vertical_velocity = convolve(vertical_flow, kernel_laplacian)\n\n        # This updates the flow as proposed in the paper (Step 12)\n        update = (\n            derivative_x * avg_horizontal_velocity\n            + derivative_y * avg_vertical_velocity\n            + derivative_t\n        )\n        update = update / (alpha**2 + derivative_x**2 + derivative_y**2)\n\n        horizontal_flow = avg_horizontal_velocity - derivative_x * update\n        vertical_flow = avg_vertical_velocity - derivative_y * update\n\n    return horizontal_flow, vertical_flow\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n", "path": "computer_vision/horn_schunck.py"}], "after_files": [{"content": "\"\"\"\n    The Horn-Schunck method estimates the optical flow for every single pixel of\n    a sequence of images.\n    It works by assuming brightness constancy between two consecutive frames\n    and smoothness in the optical flow.\n\n    Useful resources:\n    Wikipedia: https://en.wikipedia.org/wiki/Horn%E2%80%93Schunck_method\n    Paper: http://image.diku.dk/imagecanon/material/HornSchunckOptical_Flow.pdf\n\"\"\"\n\nfrom typing import SupportsIndex\n\nimport numpy as np\nfrom scipy.ndimage import convolve\n\n\ndef warp(\n    image: np.ndarray, horizontal_flow: np.ndarray, vertical_flow: np.ndarray\n) -> np.ndarray:\n    \"\"\"\n    Warps the pixels of an image into a new image using the horizontal and vertical\n    flows.\n    Pixels that are warped from an invalid location are set to 0.\n\n    Parameters:\n        image: Grayscale image\n        horizontal_flow: Horizontal flow\n        vertical_flow: Vertical flow\n\n    Returns: Warped image\n\n    >>> warp(np.array([[0, 1, 2], [0, 3, 0], [2, 2, 2]]), \\\n    np.array([[0, 1, -1], [-1, 0, 0], [1, 1, 1]]), \\\n    np.array([[0, 0, 0], [0, 1, 0], [0, 0, 1]]))\n    array([[0, 0, 0],\n           [3, 1, 0],\n           [0, 2, 3]])\n    \"\"\"\n    flow = np.stack((horizontal_flow, vertical_flow), 2)\n\n    # Create a grid of all pixel coordinates and subtract the flow to get the\n    # target pixels coordinates\n    grid = np.stack(\n        np.meshgrid(np.arange(0, image.shape[1]), np.arange(0, image.shape[0])), 2\n    )\n    grid = np.round(grid - flow).astype(np.int32)\n\n    # Find the locations outside of the original image\n    invalid = (grid < 0) | (grid >= np.array([image.shape[1], image.shape[0]]))\n    grid[invalid] = 0\n\n    warped = image[grid[:, :, 1], grid[:, :, 0]]\n\n    # Set pixels at invalid locations to 0\n    warped[invalid[:, :, 0] | invalid[:, :, 1]] = 0\n\n    return warped\n\n\ndef horn_schunck(\n    image0: np.ndarray,\n    image1: np.ndarray,\n    num_iter: SupportsIndex,\n    alpha: float | None = None,\n) -> tuple[np.ndarray, np.ndarray]:\n    \"\"\"\n    This function performs the Horn-Schunck algorithm and returns the estimated\n    optical flow. It is assumed that the input images are grayscale and\n    normalized to be in [0, 1].\n\n    Parameters:\n        image0: First image of the sequence\n        image1: Second image of the sequence\n        alpha: Regularization constant\n        num_iter: Number of iterations performed\n\n    Returns: estimated horizontal & vertical flow\n\n    >>> np.round(horn_schunck(np.array([[0, 0, 2], [0, 0, 2]]), \\\n    np.array([[0, 2, 0], [0, 2, 0]]), alpha=0.1, num_iter=110)).\\\n    astype(np.int32)\n    array([[[ 0, -1, -1],\n            [ 0, -1, -1]],\n    <BLANKLINE>\n           [[ 0,  0,  0],\n            [ 0,  0,  0]]], dtype=int32)\n    \"\"\"\n    if alpha is None:\n        alpha = 0.1\n\n    # Initialize flow\n    horizontal_flow = np.zeros_like(image0)\n    vertical_flow = np.zeros_like(image0)\n\n    # Prepare kernels for the calculation of the derivatives and the average velocity\n    kernel_x = np.array([[-1, 1], [-1, 1]]) * 0.25\n    kernel_y = np.array([[-1, -1], [1, 1]]) * 0.25\n    kernel_t = np.array([[1, 1], [1, 1]]) * 0.25\n    kernel_laplacian = np.array(\n        [[1 / 12, 1 / 6, 1 / 12], [1 / 6, 0, 1 / 6], [1 / 12, 1 / 6, 1 / 12]]\n    )\n\n    # Iteratively refine the flow\n    for _ in range(num_iter):\n        warped_image = warp(image0, horizontal_flow, vertical_flow)\n        derivative_x = convolve(warped_image, kernel_x) + convolve(image1, kernel_x)\n        derivative_y = convolve(warped_image, kernel_y) + convolve(image1, kernel_y)\n        derivative_t = convolve(warped_image, kernel_t) + convolve(image1, -kernel_t)\n\n        avg_horizontal_velocity = convolve(horizontal_flow, kernel_laplacian)\n        avg_vertical_velocity = convolve(vertical_flow, kernel_laplacian)\n\n        # This updates the flow as proposed in the paper (Step 12)\n        update = (\n            derivative_x * avg_horizontal_velocity\n            + derivative_y * avg_vertical_velocity\n            + derivative_t\n        )\n        update = update / (alpha**2 + derivative_x**2 + derivative_y**2)\n\n        horizontal_flow = avg_horizontal_velocity - derivative_x * update\n        vertical_flow = avg_vertical_velocity - derivative_y * update\n\n    return horizontal_flow, vertical_flow\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n", "path": "computer_vision/horn_schunck.py"}]}