Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. # Image Loading Code used for these examples
  2. from PIL import Image
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5.  
  6. img = Image.open('/home/cat.jpg')
  7. img = np.array(img)
  8. plt.imshow(img)
  9. plt.show()
  10.  
  11. WIDTH, HEIGHT, DEPTH= img.shape
  12.  
  13. # Flipping images with Numpy
  14. flipped_img = np.fliplr(img)
  15. plt.imshow(flipped_img)
  16. plt.show()
  17.  
  18. # Shifting Left
  19. for i in range(HEIGHT, 1, -1):
  20. for j in range(WIDTH):
  21. if (i < HEIGHT-20):
  22. img[j][i] = img[j][i-20]
  23. elif (i < HEIGHT-1):
  24. img[j][i] = 0
  25.  
  26. plt.imshow(img)
  27. plt.show()
  28.  
  29. # Shifting Right
  30. for j in range(WIDTH):
  31. for i in range(HEIGHT):
  32. if (i < HEIGHT-20):
  33. img[j][i] = img[j][i+20]
  34.  
  35. plt.imshow(img)
  36. plt.show()
  37.  
  38. # Shifting Up
  39. for j in range(WIDTH):
  40. for i in range(HEIGHT):
  41. if (j < WIDTH - 20 and j > 20):
  42. img[j][i] = img[j+20][i]
  43. else:
  44. img[j][i] = 0
  45.  
  46. plt.imshow(img)
  47. plt.show()
  48.  
  49. #Shifting Down
  50. for j in range(WIDTH, 1, -1):
  51. for i in range(HEIGHT):
  52. if (j < 144 and j > 20):
  53. img[j][i] = img[j-20][i]
  54.  
  55. plt.imshow(img)
  56. plt.show()
  57.  
  58. # ADDING NOISE
  59. noise = np.random.randint(25, size = (WIDTH, HEIGHT, DEPTH), dtype = 'int64')
  60.  
  61. for i in range(WIDTH):
  62. for j in range(HEIGHT):
  63. for k in range(DEPTH):
  64. if (img[i][j][k] != 255):
  65. img[i][j][k] += noise[i][j][k]
  66. plt.imshow(img)
  67. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement