Skip to content

Commit

Permalink
bugfix: wrong dimension order in _motion_blur()
Browse files Browse the repository at this point in the history
  • Loading branch information
Hvitgar committed Oct 30, 2019
1 parent 94aaac4 commit 55338d1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions imagecorruptions/corruptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,20 @@ def getMotionBlurKernel(width, sigma):

def shift(image, dx, dy):
if(dx < 0):
shifted = np.roll(image, shift=image.shape[0]+dx, axis=0)
shifted[dx:,:] = shifted[dx-1:dx,:]
shifted = np.roll(image, shift=image.shape[1]+dx, axis=1)
shifted[:,dx:] = shifted[:,dx-1:dx]
elif(dx > 0):
shifted = np.roll(image, shift=dx, axis=0)
shifted[:dx,:] = shifted[dx:dx+1,:]
shifted = np.roll(image, shift=dx, axis=1)
shifted[:,:dx] = shifted[:,dx:dx+1]
else:
shifted = image

if(dy < 0):
shifted = np.roll(shifted, shift=image.shape[1]+dy, axis=1)
shifted[:,dy:] = shifted[:,dy-1:dy]
shifted = np.roll(shifted, shift=image.shape[0]+dy, axis=0)
shifted[dy:,:] = shifted[dy-1:dy,:]
elif(dy > 0):
shifted = np.roll(shifted, shift=dy, axis=1)
shifted[:,:dy] = shifted[:,dy:dy+1]
shifted = np.roll(shifted, shift=dy, axis=0)
shifted[:dy,:] = shifted[dy:dy+1,:]
return shifted

def _motion_blur(x, radius, sigma, angle):
Expand All @@ -141,8 +141,8 @@ def _motion_blur(x, radius, sigma, angle):

blurred = np.zeros_like(x, dtype=np.float32)
for i in range(width):
dx = -math.ceil(((i*point[0]) / hypot) - 0.5)
dy = -math.ceil(((i*point[1]) / hypot) - 0.5)
dy = -math.ceil(((i*point[0]) / hypot) - 0.5)
dx = -math.ceil(((i*point[1]) / hypot) - 0.5)
if (np.abs(dy) >= x.shape[0] or np.abs(dx) >= x.shape[1]):
# simulated motion exceeded image borders
break
Expand Down

0 comments on commit 55338d1

Please sign in to comment.