-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplitmerge.py
More file actions
35 lines (26 loc) · 785 Bytes
/
splitmerge.py
File metadata and controls
35 lines (26 loc) · 785 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
import cv2 as cv
import numpy as np
img = cv.imread('Photos/countryside.jpg')
cv.imshow('Street', img)
blank = np.zeros(img.shape[:2], dtype='uint8')
# Split an image into its respective color channels
b, g, r = cv.split(img)
# Reconstruct the image to display the actual color involved in that channel
blue = cv.merge([b, blank, blank])
green = cv.merge([blank, g, blank])
red = cv.merge([blank, blank, r])
cv.imshow('Blue', blue)
cv.imshow('Green', green)
cv.imshow('Red', red)
# #is shown gray cause have a shape of one
# cv.imshow('Blue', b)
# cv.imshow('Green', g)
# cv.imshow('Red', r)
print(img.shape)
print(b.shape)
print(g.shape)
print(r.shape)
# Merge the color channels back to its original image
merged = cv.merge([b,g,r])
cv.imshow('Merged', merged)
cv.waitKey(0)