python-opencv--图像像素通道读取及修改

data/dtype/size/shape/len
‘’’

import cv2 as cv
import numpy as np

def access_pixes(image):
print(image.shape)
height = image.shape[0]
width = image.shape[1]
channels = image.shape[2]
print(“width : %s, height : %s, channels : %s”%(width, height, channels))
for row in range(height):
for col in range(width):
for c in range(channels):
pv = image[row, col, c]
image[row, col, c] = 255-pv #像素取反
cv.imshow(“pixels_demo”, image)

def create_image():
#多通道修改
‘’’
img = np.zeros([512, 512, 3], np.uint8) #定义一个三维都是0的矩阵
img[:, :, 0] = np.ones([512, 512])*255 #修改第一个通道(blue通道)
cv.imshow(“new image”, img)

#单通道修改
img = np.ones([512, 512, 1], np.uint8)  #定义一个一维的单通道矩阵
img = img*127
cv.imshow("new image", img)
'''

m1 = np.ones([3, 3], np.uint8)
m1.fill(122.83)
print(m1)

m2 = m1.resh
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值