10、OpenCV像素处理

Python: cv2.split(m[, mv]) → mv 直译:一个通道数组拆分多数组

Python: cv2.merge(mv[, dst]) → dst 直译:多通道数组合并为单数组

# -*- coding: utf-8 -*-
import cv2
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

img = cv2.imread('1.jpg')
img=cv2.resize(img,(3,3))
print 'img=',img
bgr = cv2.split(img)
print 'bgr=',bgr
blue = bgr[0]
print 'blue=',blue
green = bgr[1]
print 'bgr=',green
red = bgr[2]
print 'red=',red
#图像原本颜色是蓝-绿-红
# plt.add(blue)
# plt.show(blue)

changeChannel = cv2.merge([red,green,blue])
#现在为红绿蓝 merge: several arrays to make a single multi-channel array
cv2.imshow('changeChannel',changeChannel)
cv2.imwrite('changeChannel.png',changeChannel)
commonimg=img.copy()
commonimg=cv2.flip(commonimg,0)
cv2.imshow('commonimg',commonimg)
#flip只是数组互换,但是其不涉及像素互换
cv2.waitKey(0)
k=cv2.waitKey(0)&0xff  
print k
if k==27: 
	cv2.destroyAllWindows() 
elif k==ord('s'):
	cv2.imwrite('mypicture.png',img) 
	cv2.destroyAllWindows()
img= [
      [[  0   0   0] [255 255 255] [160 146 150]]
      [[  8   9   7] [164 185 186] [155 139 150]]
      [[ 46  56  57] [249 255 253] [ 33  37  33]]]
bgr= [array([[  0, 255, 160],
       [  8, 164, 155],
       [ 46, 249,  33]], dtype=uint8),
       array([[  0, 255, 146],
       [  9, 185, 139],
       [ 56, 255,  37]], dtype=uint8), 
       array([[  0, 255, 150],
       [  7, 186, 150],
       [ 57, 253,  33]], dtype=uint8)]
blue= [[  0 255 160]
       [  8 164 155]
       [ 46 249  33]]
bgr= [[  0 255 146]
      [  9 185 139]
      [ 56 255  37]]
red= [[  0 255 150]
      [  7 186 150]
      [ 57 253  33]]

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sxj731533730

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值