In [2]:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
In [3]:
# loading the frames
frame_0 = mpimg.imread('i/smw_background_ball_1.png')
frame_1 = mpimg.imread('i/smw_background_ball_2.png')
# showing the frames
f, (plt1, plt2) = plt.subplots(1, 2)
plt1.set_title('frame_0');plt1.imshow(frame_0,interpolation='nearest');
plt2.set_title('frame_1');plt2.imshow(frame_1,interpolation='nearest');
In [4]:
plt.imshow(np.subtract(frame_0[:,:,0], frame_1[:,:,0]),interpolation='nearest',cmap=plt.cm.binary);
In [5]:
# the block we want to motion estimate
ball = frame_0[27:37,1:11,]
block_size = 10
plt.imshow(ball,interpolation='nearest');
In [6]:
# let's pretend we had motion estimation (full scan, reduced scan(lfp)...)
# and that the motion vectors were:
x = 26
y = 10
predicted_frame = np.array(frame_1)
# applying the motion compensation
predicted_frame[x:(x+block_size),y:(y+block_size),] = ball
plt.imshow(predicted_frame,interpolation='nearest');
In [7]:
f, (plt1, plt2) = plt.subplots(1, 2)
plt1.set_title('Frame difference');plt1.imshow(np.subtract(frame_0[:,:,0], frame_1[:,:,0]),interpolation='nearest',cmap=plt.cm.binary);
plt2.set_title('Motion estimation');plt2.imshow(np.subtract(predicted_frame[:,:,0], frame_1[:,:,0]),interpolation='nearest',cmap=plt.cm.binary);