zoukankan      html  css  js  c++  java
  • 图像颜色反转

    反转原理:像素值 = 255-当前像素值

    主要分为灰度图像反转和彩色图像反转

    import cv2
    import numpy as np
    img = cv2.imread('D:/pythonob/imageinpaint/img/zidan.jpg',1)
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    imgInfo = gray.shape
    height = imgInfo[0]
    width = imgInfo[1]
    revGray = np.zeros((height,width,1),np.uint8)#灰度图像颜色反转
    for i in range(0,height):
    for j in range(0,width):
    grayPixel = gray[i,j]
    revGray[i,j] = 255-grayPixel
    revColor = np.zeros((height,width,3),np.uint8)#彩色图像颜色反转
    for i in range(0,height):
    for j in range(0,width):
    (b,g,r) = img[i,j]
    revColor[i,j] = (255-b,255-g,255-r)
    cv2.imshow('src',img)
    cv2.imshow('gray',gray)
    cv2.imshow('reversedGray',revGray)
    cv2.imshow('reversedColor',revColor)
    cv2.waitKey(0)

    效果图:

  • 相关阅读:
    瀑布流
    进度条
    图片延迟加载、scroll
    scroll 滚动广告
    json
    样式更改
    js 不同浏览器的宽度获取
    孤立点挖掘算法
    数据结构算法代码
    深入浅出JMS(一)--JMS基本概念
  • 原文地址:https://www.cnblogs.com/cxxBoo/p/11454349.html
Copyright © 2011-2022 走看看