Skip to content

Instantly share code, notes, and snippets.

@itspacchu
Created June 6, 2021 19:03
Show Gist options
  • Save itspacchu/84694ea7876be5c2b4f487e2d1dadc25 to your computer and use it in GitHub Desktop.
Save itspacchu/84694ea7876be5c2b4f487e2d1dadc25 to your computer and use it in GitHub Desktop.
Distort image based on function
def distortImage(theImage,fxn):
theImage = np.asarray(theImage)
bc,gc,rc = theImage[:,:,0] , theImage[:,:,1] ,theImage[:,:,2]
dc = []
for imgChannel in bc,gc,rc:
dImg = np.zeros(imgChannel.shape)
Image.fromarray(dImg)
for i in range(theImage.shape[0]):
for j in range(theImage.shape[1]):
try:
dImg[i][j] = imgChannel[i + int(fxn(i)[0])][j + int(fxn(j)[1])]
except:
dImg[i][j] = imgChannel[i][j]
dc.append(dImg)
imr = Image.fromarray(dc[0]).convert('L')
img = Image.fromarray(dc[1]).convert('L')
imb = Image.fromarray(dc[2]).convert('L')
merged=Image.merge("RGB",(imr,img,imb))
return merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment