-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathimage_ops.py
25 lines (20 loc) · 849 Bytes
/
image_ops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import numpy as np
from PIL import Image
image = Image.open("../manning-logo.png").convert("L")
width, height = image.size
image_arr = np.array(image)
brighter_arr = image_arr + 5
Image.fromarray(brighter_arr).save("brighter.png")
brighter2_arr = image_arr * 2
Image.fromarray(brighter2_arr).save("brighter2.png")
print(image_arr.max(), image_arr.dtype)
print(brighter_arr.max(), brighter_arr.dtype)
print(brighter2_arr.max(), brighter2_arr.dtype)
brighter3_arr = image_arr.astype(np.uint16)
brighter3_arr = brighter3_arr * 2
print(brighter3_arr.max(), brighter3_arr.dtype)
brighter3_arr = np.minimum(brighter3_arr, 255) # do not confuse with min
print(brighter3_arr.max(), brighter3_arr.dtype)
brighter3_arr = brighter3_arr.astype(np.uint8)
print(brighter3_arr.max(), brighter3_arr.dtype)
Image.fromarray(brighter3_arr).save("brighter3.png")