| 1??作業要求 |
|---|
給定一幅灰度影像,使用任意方法將其變成一幅彩色影像,并盡量使得添加的色彩顯得較為真實,
| 2??核心代碼 |
|---|
import argparse
import matplotlib
import matplotlib.pyplot as plt
from colorizers import *
matplotlib.use('TKAgg')
parser = argparse.ArgumentParser()
parser.add_argument('-i','--img_path', type=str, default='imgs/ansel_adams3.jpg')
parser.add_argument('--use_gpu', action='store_true', help='whether to use GPU')
parser.add_argument('-o','--save_prefix', type=str, default='saved', help='will save into this file with {eccv16.png, siggraph17.png} suffixes')
opt = parser.parse_args()
# 加載上色器
colorizer_eccv16 = eccv16(pretrained=True).eval()
colorizer_siggraph17 = siggraph17(pretrained=True).eval()
if(opt.use_gpu):
colorizer_eccv16.cuda()
colorizer_siggraph17.cuda()
# default size to process images is 256x256
# grab L channel in both original ("orig") and resized ("rs") resolutions
img = load_img("imgs/test2.jpg")
(tens_l_orig, tens_l_rs) = preprocess_img(img, HW=(256,256))
if(opt.use_gpu):
tens_l_rs = tens_l_rs.cuda()
# colorizer outputs 256x256 ab map
# resize and concatenate to original L channel
img_bw = postprocess_tens(tens_l_orig, torch.cat((0*tens_l_orig,0*tens_l_orig),dim=1))
out_img_eccv16 = postprocess_tens(tens_l_orig, colorizer_eccv16(tens_l_rs).cpu())
out_img_siggraph17 = postprocess_tens(tens_l_orig, colorizer_siggraph17(tens_l_rs).cpu())
plt.imsave('%s_eccv16.png'%opt.save_prefix, out_img_eccv16)
plt.imsave('%s_siggraph17.png'%opt.save_prefix, out_img_siggraph17)
plt.figure(figsize=(16,4))
plt.subplot(1,4,1)
plt.imshow(img,aspect='auto')
plt.title('Original')
plt.axis('off')
plt.subplot(1,4,2)
plt.imshow(img_bw,aspect='auto')
plt.title('Input')
plt.axis('off')
plt.subplot(1,4,3)
plt.imshow(out_img_eccv16,aspect='auto')
plt.title('Output (ECCV 16)')
plt.axis('off')
#
plt.subplot(1,4,4)
plt.imshow(out_img_siggraph17,aspect='auto')
plt.title('Output (SIGGRAPH 17)')
plt.axis('off')
plt.show()
| 3??實驗結果 |
|---|
對隨機選取的三張測驗圖片進行上色,首先第一張就是我們輸入的原圖,然后將輸入的原圖轉為灰度影像,也就是第二張圖片,接著我們使用16年ECCV的網路模型進行上色預測,得到處理后的結果,即第三張圖片,最后我們使用17年siggraph快速著色器模型進行自動上色,得到第四張圖的結果,通過對比可以看出,上色結果和原圖相似度還是十分高的,而且沒有任何違和感,效果很魯棒,
💖test1是周董,周董衣服及鋼琴顏色完全相同,只是背景燈光不同而已,

💝test2是藍天白云,自然景物的還原度是最高的,幾乎和原圖無差別,(我估計GAN中的辨別器Discriminator都識別不出來這是上色的假圖片,)

💘test3是Taylor Swift,老霉依舊很美,上色后,和原圖比起來,只是缺少些靚麗感,

| ?實驗原始碼+報告? |
|---|
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/402579.html
標籤:其他
