-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverseAlpha.py
More file actions
37 lines (30 loc) · 789 Bytes
/
reverseAlpha.py
File metadata and controls
37 lines (30 loc) · 789 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
"""
Python script that inverts transparency from a PNG image.
For example a pixel with alpha value of x will become a pixel with alpha value of 255 - x.
"""
import sys
import os
import cv2
import numpy as np
def invert_alpha(img):
"""
Inverts the alpha channel of an image.
"""
# img = img[:, :, :3]
img[:, :, 3] = 255 - img[:, :, 3]
return img
def main():
file = "Assets/spot.png"
if len(sys.argv) > 1:
file = sys.argv[1]
if not os.path.isfile(file):
print("File not found:", file)
sys.exit(1)
img = cv2.imread(file, cv2.IMREAD_UNCHANGED)
img[:, :, :3] = 255
print(img.shape)
img = invert_alpha(img)
cv2.imwrite("Assets/inverted_spot.png", img)
print("Done!")
if __name__ == "__main__":
main()