1. from PIL import Image
  2. import numpy as np
  3.  
  4. im = Image.open('heartbleed.png')
  5.  
  6. # In this case, it's a 3-band (red, green, blue) image
  7. # so we'll unpack the bands into 3 separate 2D arrays.
  8. r, g, b = np.array(im).T
  9.  
  10. # Let's make an alpha (transparency) band based on where blue is < 100
  11. a = np.zeros_like(b)
  12. a[b < 100] = 255
  13.  
  14. # Random math... This isn't meant to look good...
  15. # Keep in mind that these are unsigned 8-bit integers, and will overflow.
  16. # You may want to convert to floats for some calculations.
  17. r = (b + g) * 5
  18.  
  19. # Put things back together and save the result...
  20. im = Image.fromarray(np.dstack([item.T for item in (r,g,b,a)]))
  21.  
  22. im.save('output.png')


728x90

'Language' 카테고리의 다른 글

Changes in Python 3.6  (0) 2016.12.24
base 64 원하는 횟수만큼 decoding 하기 python (파일 넣어서)  (0) 2016.12.22
RGB image analysis.py  (0) 2016.12.21
image GPS.py  (0) 2016.12.21
base image.py  (0) 2016.12.21