

"""simple docstring"""




from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve
def      lowerCAmelCase  (    __UpperCamelCase							,			__UpperCamelCase							,			__UpperCamelCase					):
 '''simple docstring'''





 UpperCAmelCase__    :     Dict          =    np.stack((horizontal_flow, vertical_flow)							,			2					)

 # Create a grid of all pixel coordinates and subtract the flow to get the
 # target pixels coordinates
 UpperCAmelCase__    :     int          =    np.stack(
     np.meshgrid(np.arange(0							,			image.shape[1]					)							,			np.arange(0							,			image.shape[0]					)					)							,			2					)
 UpperCAmelCase__    :     List[Any]          =    np.round(grid - flow					).astype(np.intaa					)

 # Find the locations outside of the original image
 UpperCAmelCase__    :     List[str]          =    (grid < 0) | (grid >= np.array([image.shape[1], image.shape[0]]					))
 UpperCAmelCase__    :     Optional[Any]          =    0

 UpperCAmelCase__    :     Optional[Any]          =    image[grid[:, :, 1], grid[:, :, 0]]

 # Set pixels at invalid locations to 0
 UpperCAmelCase__    :     Dict          =    0

 return warped
def      lowerCAmelCase  (    __UpperCamelCase							,			__UpperCamelCase							,			__UpperCamelCase							,			__UpperCamelCase = None							,			):
 '''simple docstring'''





 if alpha is None:
  UpperCAmelCase__    :     Any          =    0.1

 # Initialize flow
 UpperCAmelCase__    :     Optional[Any]          =    np.zeros_like(lowerCAmelCase_					)
 UpperCAmelCase__    :     str          =    np.zeros_like(lowerCAmelCase_					)

 # Prepare kernels for the calculation of the derivatives and the average velocity
 UpperCAmelCase__    :     str          =    np.array([[-1, 1], [-1, 1]]					) * 0.25
 UpperCAmelCase__    :     Tuple          =    np.array([[-1, -1], [1, 1]]					) * 0.25
 UpperCAmelCase__    :     Optional[int]          =    np.array([[1, 1], [1, 1]]					) * 0.25
 UpperCAmelCase__    :     Union[str, Any]          =    np.array(
     [[1 / 12, 1 / 6, 1 / 12], [1 / 6, 0, 1 / 6], [1 / 12, 1 / 6, 1 / 12]]					)

 # Iteratively refine the flow
 for _ in range(lowerCAmelCase_					):
  UpperCAmelCase__    :     List[Any]          =    warp(lowerCAmelCase_							,			lowerCAmelCase_							,			lowerCAmelCase_					)
  UpperCAmelCase__    :     List[Any]          =    convolve(lowerCAmelCase_							,			lowerCAmelCase_					) + convolve(lowerCAmelCase_							,			lowerCAmelCase_					)
  UpperCAmelCase__    :     Any          =    convolve(lowerCAmelCase_							,			lowerCAmelCase_					) + convolve(lowerCAmelCase_							,			lowerCAmelCase_					)
  UpperCAmelCase__    :     Optional[Any]          =    convolve(lowerCAmelCase_							,			lowerCAmelCase_					) + convolve(lowerCAmelCase_							,			-kernel_t					)

  UpperCAmelCase__    :     Optional[int]          =    convolve(lowerCAmelCase_							,			lowerCAmelCase_					)
  UpperCAmelCase__    :     Tuple          =    convolve(lowerCAmelCase_							,			lowerCAmelCase_					)

  # This updates the flow as proposed in the paper (Step 12)
  UpperCAmelCase__    :     int          =    (
      derivative_x * avg_horizontal_velocity
      + derivative_y * avg_vertical_velocity
      + derivative_t
  )
  UpperCAmelCase__    :     Any          =    update / (alpha**2 + derivative_x**2 + derivative_y**2)

  UpperCAmelCase__    :     str          =    avg_horizontal_velocity - derivative_x * update
  UpperCAmelCase__    :     Dict          =    avg_vertical_velocity - derivative_y * update

 return horizontal_flow, vertical_flow


if __name__ == "__main__":
      import doctest

      doctest.testmod()







'''simple docstring'''

from itertools import permutations







def __A  (    ):
     _UpperCAmelCase					:  Union[str, Any]         =    list(map("""""".join ,       permutations("""0123456789"""       )       )       )
     return result[99_9999]


if __name__ == "__main__":
   print(solution())


