簡體   English   中英

將漸變 map 從圖像應用到另一個具有透明度的圖像 Python(PIL、numpy 等)

[英]Applying a gradient map from image to another image with transparency in Python (PIL, numpy, etc)

我一直在努力嘗試將源自圖像文件的漸變 map 應用於包含 alpha/透明度的灰度圖像。 以下包括源圖像和漸變 map 圖像。 我首先嘗試使用 numpy 進行此操作,但沒有成功。 這樣做的目的是能夠使用漸變貼圖以編程方式為圖像層着色。 任何幫助,將不勝感激。 謝謝!

示例源圖像

要應用的示例顏色圖/漸變

示例預期結果

from PIL import Image

gray, alpha = Image.open(source_fn).convert('LA').split()
gradient = Image.open(gradient_fn).convert('RGB').resize((256, 1))
lut = []
for band in gradient.split():
    lut += list(band.getdata())

out = gray.point(lut, 'RGB')
out.putalpha(alpha)
out.save(out_fn, 'PNG')

這是結果。 它與您作為預期結果提供的示例不太匹配,但我認為這只是對輸入范圍應該是 map 到梯度的誤解。 我相信你可以自己解決這個問題。

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM