Language

individual bands of image.py

๐“›๐“พ๐“ฌ๐“ฎ๐“ฝ๐“ฎ_๐“ข๐“ฝ๐“ฎ๐“ต๐“ต๐“ช 2016. 12. 21.
728x90
๋ฐ˜์‘ํ˜•

  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. = np.zeros_like(b)
  12. a[< 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. = (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

๋Œ“๊ธ€