如何獲取影像的影像色調并將其設定為另一個?
我有這兩個影像,想用蒙娜麗莎的影像顏色制作 Ashley Benson。

uj5u.com熱心網友回復:
我認為沒有“過濾器”可以做到這一點。
使用經典的計算機視覺,您可以對每個影像進行快速傅里葉變換,然后用蒙娜麗莎的影像替換 Ashley Benson 影像的低頻分量。但在這種情況下,您只能更改影像的顏色域。這里的代碼示例:
import cv2
import numpy as np
from matplotlib import pyplot as plt
lisa = cv2.imread(r"path/to/monalisa")
ashley = cv2.imread(r"path/to/ashley")
def domain_adoptation(src, trg, freq):
"""
Parameters:
src - source image, which style has to be changed
trg - target image, which low-frequency domain will be adopted
freq - number of frequencies to be used
Returns:
result - np.array based on srs image (shape and high frequencies)
with low frequencies of the target image
"""
result = np.zeros((src.shape[0],src.shape[1],src.shape[2]))
for i in range(src.shape[2]):
trg_fft = np.fft.fft2(trg[:,:,i])
src_fft = np.fft.fft2(src[:,:,i])
trg_fft_shift = np.fft.fftshift(trg_fft)
src_fft_shift = np.fft.fftshift(src_fft)
src_fft_shift[src.shape[0]//2-freq:src.shape[0]//2 freq,
src.shape[1]//2-freq:src.shape[1]//2 freq] = \
trg_fft_shift[trg.shape[0]//2-freq:trg.shape[0]//2 freq,
trg.shape[1]//2-freq:trg.shape[1]//2 freq]
src_ifft_shift = np.fft.ifftshift(src_fft_shift)
result[:,:,i] = np.fft.ifft2(src_ifft_shift)
result[:,:,i] = np.abs(result[:,:,i])
result = np.float32(result)
result = cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
result = cv2.normalize(result,None,0,1,cv2.NORM_MINMAX)
return result
image = domain_adoptation(src=ashley,trg=lisa,freq=1)
plt.imshow(a)
還有一個GIF:

如果你想得到更好的結果,你可以看看相當古老的深度學習方法,叫做“

當然,有許多現代最先進的風格轉移方法,請參見此處。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/486902.html
