본문 바로가기
OpenCV

[OpenCV] splitmerge.py: Color Channels

by Lizardee 2024. 4. 10.

import cv2 as cv
import numpy as np

# Reading an image
img = cv.imread('Photos/boston.jpg')
cv.imshow('Boston', img)

# Blank image
blank = np.zeros(img.shape[:2], dtype='uint8')


# 1. Splitting a color
b,g,r = cv.split(img)

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)

print(img.shape)  # Shape of 3
print(b.shape)  # Shape of 1
print(g.shape)  # Shape of 1
print(r.shape)  # Shape of 1


# 2. Merging an image
merged = cv.merge([b,g,r])
cv.imshow('Merged Image', merged)


cv.waitKey(0)

 

'OpenCV' 카테고리의 다른 글

[OpenCV] bitwise.py: BITWISE Operations  (0) 2024.04.11
[OpenCV] smoothing.py: Blurring Techniques  (0) 2024.04.11
[OpenCV] contours.py  (0) 2024.04.10
[OpenCV] transformations.py  (0) 2024.04.10
[OpenCV] basic.py  (0) 2024.04.10