python之图像处理

1、创建图像

image=numpy.zeros((height,width),dtype=numpy.uint8) 

2、遍历像素值

import cv2
import numpy as np
def access_pixel(img):
    print(img.shape)
    height = img.shape[0]
    width = img.shape[1]
    channels = img.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 = img[row,col,c]
                img[row,col,c] = 255 - pv
    cv2.imshow("pixel_image",img)

def create_image():
    img = np.zeros([528,400,3],np.uint8)
    img[:,:,0] = np.ones([528,400])*255
    cv2.imshow("img_creat",img)

 

posted @ 2020-04-19 17:32  玥茹苟  阅读(394)  评论(0编辑  收藏  举报