Today, my imaginary readers, we improve our optical flow dramatically. Lets see, what our algorithm produces for images that have more than 1-pixel shifts.

I0 I0I1
OF results:
<img alt="OF results" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAT8AAAD7CAYAAAAcqJO9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl0leW59/HvzkQgYYYkQoLIZAYgBFBq1BJEUGyhKmgVFV5RsXrsqR6Pet6es9ahfxShtsuh7ep5a8X5VK1tRS0iUhtEIA4EHECBQqIhTEqYMpCQ5Hn/uPYmCeDOHu57Pzs+12etvUhCcuVms/fvuZ/pvnyO4zgopZTHJLg9AKWUcoOGn1LKkzT8lFKepOGnlPIkDT+llCdp+CmlPCkp2gIlJSWsWbPGxFiUUipihYWFbN68OeTvj3rmt2bNGhzHsfL47//+b2u1dbw6Zh3vt2vMH330UVjZpbu9SilP0vBTSnlSXIdfSUmJ20MIS1cbL+iYY6GrjRe65pjD5XMcJ6p7e30+H1GWUEqpqIWbRXE981NKKVs0/JRSnqThp5TyJA0/pZQnRX2HRzgWLFgQ9oWISinvKiwsZNmyZVZqxzT8tm3bRnl5eSx/pVKqC0tNTbVWW3d7lVKepOGnlPIkDT+llCdp+CmlPEnDTykVWzE9zfrNNPyU6mq6W66fDyRaqt0XKLBUO0ydht/KlSvJzc1l5MiRLF26NBZjUqprG4i98ACYCmRarJ8HjLBUezLQx1LtMAUNv5aWFu666y5WrlzJ1q1b+eMf/8hnn30Wq7EpZc9AYBTQy0JtB/gxElK9LdT/GrgZONtCbYAhwFgLdQf469p4ziMQdO/7/fffZ8SIEQwdOhSA6667juXLl5OXlxeLsamuJrBFd4ATQL2hmhcDLUADUAuU+z+PxtfAd4C5yDj3AeuBf0ZZN1D7PeAy4CLgM+A1ZPwmVACXAzcBf/bXN6UPEthpQCpw3GDtych0K07CL+jMr7q6mpycnJOfZ2dnU11dbX1QAFyLna3PROAHFur2B25FXjSmXY8chzElCbgU8+NNB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552Ul5eTlpbGkiVL3B5WUDt37uSRRx6hsrKSPXv2UFtby/PPP+/2sMLm8/m6zPvy5z//OSkpKcydO7fT74278Bs8eDBVVVUnP6+qqiI7O9vFEYXmxIkTzJ49mxtvvJErr7zS7eEEtX79el599VXOOeccrr/+et5++23mzZvn9rCCys7OJjs7m/POOw+AOXPmUF5e7vKogvvwww8pLi6mf//+JCUlcfXVV7N+/Xq3hxWSzMxM9u2Txr179+4lIyPD5RF17qmnnmLFihUhb2DiLvwmTpzIjh07qKyspKmpiRdffJFZs2a5PaygHMfhlltuIT8/n7vvvtvt4XRq8eLFVFVVUVFRwQsvvMAll1zCM8884/awgsrKyiInJ4ft27cDsHr1agoKClweVXC5ubmUlZXR0NCA4zisXr2a/Px8t4cVklmzZvH0008D8PTTT8f9Bn3lypU89NBDLF++nNTU1NB+yMrpmCitWLHCGTVqlDN8+HBn8eLFbg+nU2vXrnV8Pp9TWFjojBs3zhk3bpzzxhtvuD2skJSWlnaZs72bN292Jk6c6IwdO9a56qqr4v5sr+M4ztKlS538/Hxn9OjRzrx585ympia3h3Sa6667zjnrrLOc5ORkJzs721m2bJlz8OBBZ+rUqc7IkSOdadOmOYcOHXJ7mCedOt4nnnjCGTFihDNkyJCT77877rij0zp6e5tSypPibrdXKaViQcNPKeVJGn5KKU/S8FNKeZKGn1LKkzT8lFKepOGnlPIkDT+llCf9f5iy7YKmnFDaAAAAAElFTkSuQmCC" />
</td></tr>

You can see, that the algorithm cannot deal with too large displacements. Even with multiple warps. Lets apply multiscale scheme now. We need to construct image pyramid:

#from flow_huber_py import construct_image_pyramid
def construct_image_pyramid(I, pyrlevels, pyrfactor):
    factor = 2. ** .5
    smooth_sigma = (1. / pyrfactor) ** .5 / factor
    pyr = []
    tmp = I
    pyr.append(I) # add original image to pyramid
    for m in range(pyrlevels - 1):
        shape = (numpy.array(tmp.shape) * pyrfactor).astype('int32')

        idx, idy = np.meshgrid(np.arange(shape[1]), np.arange(shape[0]))
        idx = idx *tmp.shape[1] / shape[1].astype('float32')
        idy = idy *tmp.shape[0] / shape[0].astype('float32')

        filt1 = scipy.ndimage.filters.gaussian_filter(tmp, smooth_sigma, order=0, output=None, mode='reflect', cval=0.0, truncate=2.0)
        filt1r = interp2linear(filt1, idx, idy,)

        tmp = filt1r
        pyr.append(filt1r)
    return pyr
Construct our pyramid with 2 layers:
pyrfactor = .7
pyrlevels = 1

I0pyr = construct_image_pyramid(I0, pyrlevels, pyrfactor)
I1pyr = construct_image_pyramid(I1, pyrlevels, pyrfactor)
Let the show begin:
[](https://www.blogger.com/blogger.g?blogID=636453477220885924" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;)import scipy.ndimage

for level in range(pyrlevels - 1, -1, -1):
    M, N = I0pyr[level].shape
    if level == pyrlevels - 1:
        print "asdasd"
        u = numpy.zeros_like(I0pyr[level])
        v = numpy.zeros_like(I0pyr[level])
    else:
        rescale_v, rescale_u = numpy.array([M, N], dtype='float32') / I0pyr[level + 1].shape
        u = scipy.ndimage.zoom(u, [rescale_v, rescale_u], order=3) * rescale_u
        v = scipy.ndimage.zoom(v, [rescale_v, rescale_u], order=3) * rescale_v
        if u.shape != I0pyr[level].shape or v.shape != I0pyr[level].shape:
            raise Exception("Resize failed during transition to higher levels. Need better resize implementation.")

    u0, v0 = u.copy(), v.copy()
    
    I0_ = I0pyr[level]
    I1_ = I1pyr[level]
    
    print I1_.shape, u0.shape, I0pyr[level].shape
    wrpr = Warper( I0_.shape, u0, v0, I0_, I1_, 
              train_function = TrainFunctionTV(u0, v0, rate=0.1, num_steps = 1000, alpha = 0.1), display=0)
    warps = 10
    for i in range(warps):
        wrpr.warp()
    u, v = wrpr.u, wrpr.v
    

    plt.figure()
    plt.subplot(1,2,1)
    plt.imshow( I0pyr[level])
    plt.quiver( u, v, scale_units='xy', angles='xy', scale = 1., color='g')
    plt.subplot(1,2,2)
    plt.imshow( I1pyr[level])
OF results:

Now optical flow is much more adequate.