Python图像处理——opencv图像的颜色通道

图片主要由三原色组成,红色、绿色,蓝色。
图片
Python图像处理——opencv图像的颜色通道_第1张图片

代码

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import cv2 as cv
import numpy as np

#读取图片位置
original = cv.imread('C:/Users/Administrator/Desktop/spider/hua.jpg')

cv.imshow('Original', original)

blue = np.zeros_like(original)
blue[..., 0] = original[..., 0]
cv.imshow('blue', blue)

green = np.zeros_like(original)
green[..., 1] = original[..., 1]
cv.imshow('green', green)

red = np.zeros_like(original)
red[..., 2] = original[..., 2]
cv.imshow('red', red)

cv.waitKey()
#图片写入
cv.imwrite('C:/Users/Administrator/Desktop/spider/hua_red.jpg', red)

你可能感兴趣的:(程序员)