Python-OpenCV图像处理-02-numpy数组操作

 创建新图像:

利用数组操作

import cv2 as cv
import numpy as np

像素属性读取: 

这里的图像说白了就是二维的数组每个数组元素的数值代表颜色,由(bgr)三张单色的图片混合而成。这里叫做通道数:

def access_pixels(image):#像素属性读取函数
    print(image.shape)
    height = image.shape[0]
    width =image.shape[1]
    channels =image.shape[2]
    print("height:  %s width: %s channels: %s"%(height,width,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)

创建数组:

m1 =np.ones([3,3],np.uint8)    
m1.fill(2)#在数组中元素全填上2

因为前文也说了彩色图像实际上就是由数组定义的单色图像的叠加

创建图像:

def create_image():
    #图像全部变成0
    img = np.zeros([400,400,3],np.uint8)#创建一个图像 多通道 bgr
    img[:,:,0] =255#b g r 三个通道
    img[:,:,1] = np.ones([400,400])*255
    cv.imshow("new image",img)
    #创建单通道的图像  灰度图像
    img1 =np.zeros([400,400,1],np.uint8)
    img1[:,:,0] = np.ones([400,400])*111
    cv.imshow("new image :",img1)

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Vuko-wxh

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

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

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

打赏作者

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

抵扣说明:

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

余额充值