色彩空间和通道
demo1
import cv2
hsv_image = cv2.imread("./img.png")
cv2.imshow("img", hsv_image)
hsv_image = cv2.cvtColor(hsv_image, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv_image)
cv2.imshow("B", h)
cv2.imshow("G", s)
cv2.imshow("R", v)
cv2.waitKey()
cv2.destroyAllWindows()
demo2
import numpy as np
import cv2
image = cv2.imread("./img.png")
cv2.imshow("flower", image)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow("Gray_image", gray_image)
cv2.waitKey()
cv2.destroyAllWindows()
demo3
import cv2
import numpy as np
image = cv2.imread("./img.png")
cv2.imshow("img", image)
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
cv2.imshow("hsv_img", hsv_image)
cv2.waitKey()
cv2.destroyAllWindows()
demo4
import cv2
bgr_image = cv2.imread("./img.png")
cv2.imshow("img", bgr_image)
b, g, r = cv2.split(bgr_image)
cv2.imshow("B", b)
cv2.imshow("G", g)
cv2.imshow("R", r)
cv2.waitKey()
cv2.destroyAllWindows()
demo5
import cv2
img = cv2.imread("./img.png")
b, g, r = cv2.split(img)
img = cv2.merge([b, g, r])
cv2.imshow("myimage", img)
cv2.waitKey()
cv2.destroyAllWindows()
demo6
import cv2
img = cv2.imread("./img.png")
hsv_img = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv_img)
h[:, :] = 180
new_img = cv2.merge([h, s, v])
cv2.imshow("new_img", new_img)
cv2.waitKey()
cv2.destroyAllWindows()
demo7
import cv2
bgr_img = cv2.imread("./img.png")
bgra_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2BGRA)
cv2.imshow("bgr", bgra_img)
b, g, r, a = cv2.split(bgra_img)
a[:, :] = 172
bgra_172 = cv2.merge([b, g, r, a])
a[:, :] = 0
bgra_0 = cv2.merge([b, g, r, a])
cv2.imwrite("./bgr_img.png", bgr_img)
cv2.imwrite("./bgra_172.png", bgra_172)
cv2.imwrite("./bgra_0.png", bgra_0)
cv2.imshow("1", bgra_172)
cv2.imshow("2", bgra_0)
cv2.waitKey()
cv2.destroyAllWindows()