Created
June 6, 2021 19:03
-
-
Save itspacchu/84694ea7876be5c2b4f487e2d1dadc25 to your computer and use it in GitHub Desktop.
Distort image based on function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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