41. 颜色映射

2019-11-13  本文已影响0人  十里江城
import cv2
import numpy as np
import random
import math

img = cv2.imread('face.jpg', 1) 
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]

# RGB new 蓝色更强   b = b * 1.5  g = g * 1.3
# 定义三维零矩阵 类型为np.uint8
dst = np.zeros((height, width, 3), np.uint8)
print('dst.shape: ', dst.shape)
print('img.shape: ', img.shape)

for i in range(0, height):
    for j in range(0, width):
        (b, g, r) = img[i, j]
        b = b * 1.5
        g = g * 1.3
        if b > 255:
            b = 255
        if g > 255:
            g = 255
        dst[i, j] = (b, g, r)
        
cv2.imshow('src', img)
# 类似电影特效
cv2.imshow('dst', dst)
cv2.waitKey(0)

定义的三维零矩阵维度如下:


image.png

颜色映射的效果如下:


image.png
上一篇 下一篇

猜你喜欢

热点阅读