手把手教你使用python对图片作富士胶片模拟
这篇老外文章更多地是介绍 LUT 和 HaldCLUT 以及如何从0开始编写脚本实现图像的 LUT 处理。
先看看 “Fuji Velvia 50” CLUT 效果:
核心代码
import math
def apply_hald_clut(hald_img, img):
hald_w, hald_h = hald_img.size
clut_size = int(round(math.pow(hald_w, 1/3)))
# We square the clut_size because a 12-bit HaldCLUT has the same amount of information as a 144-bit 3D CLUT
scale = (clut_size * clut_size - 1) / 255
# Convert the PIL image to numpy array
img = np.asarray(img)
# We are reshaping to (144 * 144 * 144, 3) - it helps with indexing
hald_img = np.asarray(hald_img).reshape(clut_size ** 6, 3)
# Figure out the 3D CLUT indexes corresponding to the pixels in our image
clut_r = np.rint(img[:, :, 0] * scale).astype(int)
clut_g = np.rint(img[:, :, 1] * scale).astype(int)
clut_b = np.rint(img[:, :, 2] * scale).astype(int)
filtered_image = np.zeros((img.shape))
# Convert the 3D CLUT indexes into indexes for our HaldCLUT numpy array and copy over the colors to the new image
filtered_image[:, :] = hald_img[clut_r + clut_size ** 2 * clut_g + clut_size ** 4 * clut_b]
filtered_image = Image.fromarray(filtered_image.astype('uint8'), 'RGB')
return filtered_image
velvia_hald_clut = Image.open(urllib.request.urlopen("https://i.imgur.com/31UrdAg.png"))
velvia_truck = apply_hald_clut(velvia_hald_clut, truck)
velvia_truck.show()
全文 https://kevinmartinjose.com/2021/04/27/film-simulations-from-scratch-using-python/
0
See Also
- pip 21.0 发布,完全停止支持 Python 2版本系列
- python 从图片里提取主要颜色
- python 根据字节计算文件大小(k/m/g)的函数
- 推荐个python的爬虫教程?
- 百度BAE正式开放支持Java和Python
Nearby
- 上一篇 › 在线看高分辨率的火星地图,没去过的可以看看
- 下一篇 › GitHub阻止了所有GitHub页面上的FLoC