颜色查找表LUT

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

查找表(LUT,LookUp Table)是图像颜色转换的强大工具,在许多图形和视频编辑器中使用。

2D LUT

CLUT-from-images

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]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值