"""
def search(self, cur_r, cur_c):
- min_loss = self.dist(cur_r, cur_c, [0, 0], self.metric)
+ min_loss = self.block_dist(cur_r, cur_c, [0, 0], self.metric)
cur_x = cur_c * self.blk_sz
cur_y = cur_r * self.blk_sz
ref_x = cur_x
for y in xrange(cur_y - self.wnd_sz, cur_y + self.wnd_sz):
for x in xrange(cur_x - self.wnd_sz, cur_x + self.wnd_sz):
if 0 <= x < self.width - self.blk_sz and 0 <= y < self.height - self.blk_sz:
- loss = self.dist(cur_r, cur_c, [y - cur_y, x - cur_x], self.metric)
+ loss = self.block_dist(cur_r, cur_c, [y - cur_y, x - cur_x],
+ self.metric)
if loss < min_loss:
min_loss = loss
ref_x = x
ref_y = y
return ref_x, ref_y
- def est(self):
+ def motion_field_estimation(self):
for i in xrange(self.num_row):
for j in xrange(self.num_col):
ref_x, ref_y = self.search(i, j)
"""
def search(self, cur_r, cur_c):
- dist_loss = self.dist(cur_r, cur_c, [0, 0], self.metric)
+ dist_loss = self.block_dist(cur_r, cur_c, [0, 0], self.metric)
nb_loss = self.neighborLoss(cur_r, cur_c, np.array([0, 0]))
min_loss = dist_loss + self.beta * nb_loss
cur_x = cur_c * self.blk_sz
for y in xrange(cur_y - self.wnd_sz, cur_y + self.wnd_sz):
for x in xrange(cur_x - self.wnd_sz, cur_x + self.wnd_sz):
if 0 <= x < self.width - self.blk_sz and 0 <= y < self.height - self.blk_sz:
- dist_loss = self.dist(cur_r, cur_c, [y - cur_y, x - cur_x],
- self.metric)
+ dist_loss = self.block_dist(cur_r, cur_c, [y - cur_y, x - cur_x],
+ self.metric)
nb_loss = self.neighborLoss(cur_r, cur_c, [y - cur_y, x - cur_x])
loss = dist_loss + self.beta * nb_loss
if loss < min_loss:
ref_y = y
return ref_x, ref_y
- def est(self):
+ def motion_field_estimation(self):
for i in xrange(self.num_row):
for j in xrange(self.num_col):
ref_x, ref_y = self.search(i, j)
avg[i, j] += self.mf[i + r, j + c] / 12.0
return avg
- def est(self):
+ def motion_field_estimation(self):
count = 0
"""
u_{n+1} = ~u_n - Ix(Ix.~u_n+Iy.~v+It)/(IxIx+IyIy+alpha^2)
count += 1
self.mf *= self.blk_sz
- def est_mat(self):
+ def motion_field_estimation_mat(self):
row_idx = []
col_idx = []
data = []
b = np.zeros((N, 1))
for i in xrange(self.num_row):
for j in xrange(self.num_col):
- """(IxIx+alpha^2)u+IxIy.v-alpha^2~u IxIy.u+(IyIy+alpha^2)v-alpha^2~v
- """
+ """(IxIx+alpha^2)u+IxIy.v-alpha^2~u IxIy.u+(IyIy+alpha^2)v-alpha^2~v"""
u_idx = i * 2 * self.num_col + 2 * j
v_idx = u_idx + 1
b[u_idx, 0] = -self.Ix[i, j] * self.It[i, j]
for i in xrange(num_row):
for j in xrange(num_col):
center = (j * blk_sz + 0.5 * blk_sz, i * blk_sz + 0.5 * blk_sz)
+ """mf[i,j][0] is the row shift and mf[i,j][1] is the column shift In PIL coordinates, head[0] is x (column shift) and head[1] is y (row shift).
+ """
head = (center[0] + mf[i, j][1], center[1] + mf[i, j][0])
draw.line([center, head], fill=(255, 0, 0, 255))
return Image.alpha_composite(img_rgba, mf_layer)