转自:https://blog.csdn.net/water_Popcorn/article/details/101534108

 

方法一:

import  cv2  as cv
import numpy as np
# 像素取反
def get_img_info(img):
    height = img.shape[0]  #
    width = img.shape[1]     #
    channels = img.shape[2]  #通道数
    #将图像的每个像素点进行反选操作
    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
    cv.imshow("reserve", img)
    cv.waitKey()
     cv.destroyAllWindows()

 

方法二:

# 像素取反
def get_img_reserve(img):
#直接调用反选函数
   dst = cv.bitwise_not(img)
   cv.imshow("reserve",dst)
   cv.waitKey()
   cv.destroyAllWindows()

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

 

posted on 2020-02-25 15:26  Manuel  阅读(820)  评论(0编辑  收藏  举报