4-12 颜色映射
我们通过查找表查找一组新的RGB。用新的RGB来代替原来像素值的过程。如果大家不想做表的话可以用一些简单的公式来进行颜色映射。用公式的方法可能无法表达一些更为复杂的效果。因为颜色效果越复杂,那么利用公式进行拟合的时候难度就越大,甚至拟合之后的计算量要远远超过查找表。
import cv2 import numpy as np img = cv2.imread('image2.jpg',1) cv2.imshow('src',img) imgInfo = img.shape height = imgInfo[0] width = imgInfo[1] #rgb -》RGB new "蓝色" # b = b*1.5 # g = g*1.3 dst = 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] 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('dst',dst) cv2.waitKey(0)
import cv2 import numpy as np img = cv2.imread('image1.jpg',1) cv2.imshow('src',img) imgInfo = img.shape height = imgInfo[0] width = imgInfo[1] #rgb -》RGB new "蓝色" # b = b*1.5 # g = g*1.3 dst = 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] 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('dst',dst) cv2.waitKey(0)