Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. # Author: Filipe Chagas
  2. # Email: filipe.ferraz0@gmail.com
  3. # Github profile: github.com/FilipeChagasDev
  4. # Description: Applies the "sepia" effect to an image using OpenCV and Numpy
  5.  
  6. import numpy as np
  7. import cv2
  8.  
  9. def sepia(src_image):
  10. gray = cv2.cvtColor(src_image, cv2.COLOR_BGR2GRAY)
  11. normalized_gray = np.array(gray, np.float32)/255
  12. #solid color
  13. sepia = np.ones(src_image.shape)
  14. sepia[:,:,0] *= 153 #B
  15. sepia[:,:,1] *= 204 #G
  16. sepia[:,:,2] *= 255 #R
  17. #hadamard
  18. sepia[:,:,0] *= normalized_gray #B
  19. sepia[:,:,1] *= normalized_gray #G
  20. sepia[:,:,2] *= normalized_gray #R
  21. return np.array(sepia, np.uint8)
  22.  
  23. image = cv2.imread(raw_input('source filename: '))
  24. image2 = sepia(image)
  25. cv2.imshow('', image2)
  26. cv2.waitKey()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement