Advertisement
Guest User

Ip

a guest
Mar 26th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import cv2
  2. import math
  3. import numpy as np
  4.  
  5. img = cv2.imread('lena.jpg')
  6. img_gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  7. cv2.imshow("input",img_gray)
  8.  
  9. h=img_gray.shape[0]
  10. w=img_gray.shape[1]
  11.  
  12. alpha=float(input('Input angle = '))
  13. xc=int(input('xc co = '))
  14. yc=int(input('yc co = '))
  15. rmax=int(input('rmax = '))
  16. alpha=math.radians(alpha)
  17. newimg=img_gray.copy()
  18. # newimg=np.zeros((h,w),img_gray.dtype)
  19.  
  20. def distance(dy,dx):
  21. r=math.sqrt(dx*dx+dy*dy)
  22. return r
  23.  
  24. for i in range (h):
  25. for j in range(w):
  26.  
  27.  
  28. dx=i-xc
  29. dy=j-yc
  30.  
  31.  
  32. r=distance(dy,dx)
  33. beta=math.atan2(dy,dx)
  34. beta=beta+alpha*(1-(r/rmax))
  35.  
  36. if(rmax>=r):
  37. x=xc+int(r*math.cos(beta))
  38. y=yc+int(r*math.sin(beta))
  39. else:
  40. x=int(i)
  41. y=int(j)
  42.  
  43.  
  44.  
  45.  
  46.  
  47. newimg[i,j]=img_gray.item(x,y)
  48.  
  49.  
  50.  
  51. cv2.imshow("output",newimg)
  52. cv2.waitKey(0)
  53. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement