jkushwaha commited on
Commit
2e0ee0f
·
1 Parent(s): c6a95ef

Upload cv.py

Browse files
Files changed (1) hide show
  1. cv.py +28 -0
cv.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+
3
+ # Import the image
4
+ file_name = "gfg_black.png"
5
+
6
+ # Read the image
7
+ src = cv2.imread(file_name, 1)
8
+
9
+ # Convert image to image gray
10
+ tmp = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
11
+
12
+ # Applying thresholding technique
13
+ _, alpha = cv2.threshold(tmp, 0, 255, cv2.THRESH_BINARY)
14
+
15
+ # Using cv2.split() to split channels
16
+ # of coloured image
17
+ b, g, r = cv2.split(src)
18
+
19
+ # Making list of Red, Green, Blue
20
+ # Channels and alpha
21
+ rgba = [b, g, r, alpha]
22
+
23
+ # Using cv2.merge() to merge rgba
24
+ # into a coloured/multi-channeled image
25
+ dst = cv2.merge(rgba, 4)
26
+
27
+ # Writing and saving to a new image
28
+ cv2.imwrite("gfg_white.png", dst)