wasdee
4/6/2018 - 8:56 AM

SpeedUp Python

SpeedUp Python

# constract energy grid
E = np.zeros(image.shape + (2,))

Y, X, _ = F_t.shape
E[:, :, :, SMOOTH_CONS_IDX] = 0
E[:, :-1, :, SMOOTH_CONS_IDX] += ((F_t[:, 1:, :] - F_t[:, :-1, :])) ** 2
E[:-1, :, :, SMOOTH_CONS_IDX] += ((F_t[1:, :, :] - F_t[:-1, :, :])) ** 2
E[:-1, :-1, :, SMOOTH_CONS_IDX] += ((F_t[1:, 1:, :] - F_t[:-1, :-1, :])) ** 2
# constract energy grid
E = np.zeros(image.shape + (2,))

for index in np.ndindex(F_t.shape):
      y,x,c = index

      smooth_constraint = 0
      try:
          smooth_constraint += ( (F_t[y,x+1,c] - F_t[y,x,c]) )**2
      except IndexError:
          pass
      try:
          smooth_constraint += ( (F_t[y+1,x,c] - F_t[y,x,c]) )**2
      except IndexError:
          pass
      try:
          smooth_constraint += ( (F_t[y+1,x+1,c] - F_t[y,x,c]) )**2
      except IndexError:
          pass

      E[y,x,c,SMOOTH_CONS_IDX] = smooth_constraint