查找表(LUT,LookUp Table)是图像颜色转换的强大工具,在许多图形和视频编辑器中使用。
2D LUT
2D LUT生成
def generate_identify_color_matrix(width, height, channel):
img = np.zeros((width, height, channels), dtype=np.uint8)
for by in range(8):
for bx in range(8):
for g in range(64):
for r in range(64):
x = r + bx * 64
y = g + by * 64
img[y][x][0] = int(r * 255.0 / 63.0 + 0.5)
img[y][x][1] = int(g * 255.0 / 63.0 + 0.5)
img[y][x][2] = int((bx + by * 8.0) * 255.0 / 63.0 + 0.5)
return img
identity_lut = generate_identify_color_matrix()

2D LUT 用于图像转换
from typing import Tuple
from functools import lru_cache
from math import floor
import numpy as np
import cv2
def lut_apply(image, lut):
img_list = image.tolist()
# dst_img = image.copy()
dst_img = np.zeros((image.shape[0], image.shape[1], image.shape[2]), dtype=np.uint8)
for iy in range(image.shape[0]):
for ix in range(image.shape[1]):
b, g, r = img_list[iy][ix] #bgr mode
x, y, bx, by = color_coordinate(r, g, b)
lut_y = y + by * 64
lut_x = x + bx * 64
dst_img[iy][ix][0] = lut[lut_y][lut_x][0]
dst_img[iy][ix][1] = lut[lut_y][lut_x]

查找表(LUT)是图像颜色转换的强大工具。博客介绍了2D LUT和3D LUT的生成方法,如3D LUT的Hald CLUT生成,还阐述了它们在图像转换中的应用,像3D LUT(Hald CLUT)借助Pillow库应用于图像,最后讲解了2D LUT和3D LUT之间的相互转换。
最低0.47元/天 解锁文章
832

被折叠的 条评论
为什么被折叠?



