


from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve




def 			UpperCamelCase			(					_a				,						_a				,						_a						)    ->							np.ndarray:
     '''simple docstring'''





     lowercase_				:str       			=				np.stack((horizontal_flow, vertical_flow)				,						2						)

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

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

     lowercase_				:Any       			=				image[grid[:, :, 1], grid[:, :, 0]]

     # Set pixels at invalid locations to 0
     lowercase_				:Tuple       			=				0

     return warped




def 			UpperCamelCase			(					_a				,						_a				,						_a				,						_a = None				,						)    ->							tuple[np.ndarray, np.ndarray]:
     '''simple docstring'''





     if alpha is None:
          lowercase_				:Optional[int]       			=				0.1

     # Initialize flow
     lowercase_				:str       			=				np.zeros_like(a_						)
     lowercase_				:Optional[int]       			=				np.zeros_like(a_						)

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

     # Iteratively refine the flow
     for _ in range(a_						):
          lowercase_				:Dict       			=				warp(a_				,						a_				,						a_						)
          lowercase_				:int       			=				convolve(a_				,						a_						) + convolve(a_				,						a_						)
          lowercase_				:Optional[int]       			=				convolve(a_				,						a_						) + convolve(a_				,						a_						)
          lowercase_				:Any       			=				convolve(a_				,						a_						) + convolve(a_				,						-kernel_t						)

          lowercase_				:str       			=				convolve(a_				,						a_						)
          lowercase_				:int       			=				convolve(a_				,						a_						)

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

          lowercase_				:Tuple       			=				avg_horizontal_velocity - derivative_x * update
          lowercase_				:Union[str, Any]       			=				avg_vertical_velocity - derivative_y * update

     return horizontal_flow, vertical_flow


if __name__ == "__main__":
   import doctest

   doctest.testmod()









from doctest import testmod
from math import sqrt
def      lowerCamelCase					(						a_	)	->			list:
							lowerCAmelCase_										=     []
							if num < 1:
														return facs
							facs.append(1	)
							if num == 1:
														return facs
							facs.append(a_	)
							for i in range(2 ,						int(sqrt(a_	)	) + 1	):
														if num % i == 0:  # If i is a factor of num
																					facs.append(a_	)
																					lowerCAmelCase_										=     num // i  # num//i is the other factor of num
																					if d != i:  # If d and i are distinct
																												facs.append(a_	)  # we have found another factor
							facs.sort()
							return facs


if __name__ == "__main__":
		testmod(name="""factors_of_a_number""", verbose=True)



