
from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve

def    UpperCamelCase_ (	a_  ,				a_  ,				a_		)     ->np.ndarray:
		A				=np.stack((horizontal_flow, vertical_flow)  ,				2		)

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

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

		A				=image[grid[:, :, 1], grid[:, :, 0]]

		# Set pixels at invalid locations to 0
		A				=0

		return warped

def    UpperCamelCase_ (	a_  ,				a_  ,				a_  ,				a_ = None  ,				)     ->tuple[np.ndarray, np.ndarray]:
		if alpha is None:
				A				=0.1

		# Initialize flow
		A				=np.zeros_like(__UpperCamelCase		)
		A				=np.zeros_like(__UpperCamelCase		)

		# Prepare kernels for the calculation of the derivatives and the average velocity
		A				=np.array([[-1, 1], [-1, 1]]		) * 0.25
		A				=np.array([[-1, -1], [1, 1]]		) * 0.25
		A				=np.array([[1, 1], [1, 1]]		) * 0.25
		A				=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(__UpperCamelCase		):
				A				=warp(__UpperCamelCase  ,				__UpperCamelCase  ,				__UpperCamelCase		)
				A				=convolve(__UpperCamelCase  ,				__UpperCamelCase		) + convolve(__UpperCamelCase  ,				__UpperCamelCase		)
				A				=convolve(__UpperCamelCase  ,				__UpperCamelCase		) + convolve(__UpperCamelCase  ,				__UpperCamelCase		)
				A				=convolve(__UpperCamelCase  ,				__UpperCamelCase		) + convolve(__UpperCamelCase  ,				-kernel_t		)

				A				=convolve(__UpperCamelCase  ,				__UpperCamelCase		)
				A				=convolve(__UpperCamelCase  ,				__UpperCamelCase		)

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

				A				=avg_horizontal_velocity - derivative_x * update
				A				=avg_vertical_velocity - derivative_y * update

		return horizontal_flow, vertical_flow


if __name__ == "__main__":
	import doctest

	doctest.testmod()






"""simple docstring"""


def        _lowerCamelCase(__UpperCamelCase = 20			)							->					int:

	try:
		_lowerCAmelCase								=int(__UpperCamelCase			)
	except (TypeError, ValueError):
		raise TypeError("""Parameter n must be int or castable to int."""			)
	if n <= 0:
		raise ValueError("""Parameter n must be greater than or equal to one."""			)
	_lowerCAmelCase								=0
	while 1:
		i += n * (n - 1)
		_lowerCAmelCase								=0
		for j in range(2       ,					__UpperCamelCase			):
			if i % j != 0:
				_lowerCAmelCase								=1
				break
		if nfound == 0:
			if i == 0:
				_lowerCAmelCase								=1
			return i
	return None


if __name__ == "__main__":
			print(F"""{solution() = }""")



