Skip to content

Commit cea2b14

Browse files
committed
Fix for #97: handle correctly flow rotations
The flow ought to be transformed with respect to the coordinates where it lands. Also, small angle approximation is not used here. This adds a few more computations but should be manageable in terms of execution time. Moreover, this opens up the door for general linear transforms only by tweaking the coefficients. I measured about +30% execution time increase with this version. That seems needed, however, if we look at how off the transformed flow is with large displacements (eg. FlyingChairs dataset).
1 parent 79894dc commit cea2b14

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

flow_transforms.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,22 @@ def __call__(self, inputs,target):
182182
angle1 = applied_angle - diff/2
183183
angle2 = applied_angle + diff/2
184184
angle1_rad = angle1*np.pi/180
185+
diff_rad = diff*np.pi/180
185186

186187
h, w, _ = target.shape
187188

188-
def rotate_flow(i,j,k):
189-
return -k*(j-w/2)*(diff*np.pi/180) + (1-k)*(i-h/2)*(diff*np.pi/180)
189+
warped_coords = np.mgrid[:w, :h].T + target
190+
warped_coords -= np.array([w / 2, h / 2])
190191

191-
rotate_flow_map = np.fromfunction(rotate_flow, target.shape)
192-
target += rotate_flow_map
192+
warped_coords_rot = np.zeros_like(target)
193+
194+
warped_coords_rot[..., 0] = \
195+
(np.cos(diff_rad) - 1) * warped_coords[..., 0] + np.sin(diff_rad) * warped_coords[..., 1]
196+
197+
warped_coords_rot[..., 1] = \
198+
-np.sin(diff_rad) * warped_coords[..., 0] + (np.cos(diff_rad) - 1) * warped_coords[..., 1]
199+
200+
target += warped_coords_rot
193201

194202
inputs[0] = ndimage.interpolation.rotate(inputs[0], angle1, reshape=self.reshape, order=self.order)
195203
inputs[1] = ndimage.interpolation.rotate(inputs[1], angle2, reshape=self.reshape, order=self.order)

0 commit comments

Comments
 (0)