def test(): from color_transfer.img import DAY, NIGHT src_file = DAY ref_file = NIGHT src = imread(src_file) ref = imread(ref_file) patch_match_c = True interp = 2 # bilinear normalize = "standardize" level = 1 t = ADE20KTransfer(patch_match_c) transferred = t.transfer(src, ref, level, interp, normalize) display([src, ref, transferred])
def test(): from color_transfer.img import DAY, NIGHT # choose your source and reference images src_file, ref_file = DAY, NIGHT src = imread(src_file) ref = imread(ref_file) # parameters, normally no need to change patch_match_c = True interp = 2 # bilinear normalize = "standardize" level = 1 n_clusters = 3 # 3 for sky, building and ground total_iter = 5 # number of iterations for PatchMatch epochs = 250 # number of epochs for transfer estimate # color transfer ct = ClusterTransfer(patch_match_c) transferred = ct.transfer(src, ref, level, n_clusters, interp, normalize, total_iter, epochs) display([src, ref, transferred])
def test(): import os import matplotlib.pyplot as plt from color_transfer.parts.pilutil import imread path = "/".join( os.path.realpath(__file__).replace( "\\", "/").split("/")[:-1]) + "/parts/test/pspnet50_ade20k" pattern = path + "/%d.jpg" weights = "E:/ai/weights/pretrained/pspnet50_ade20k.h5" sr = SkyRecognizer(weights) for i in range(10): file = pattern % i img = imread(file) mask = sr.recognize(img) ax = plt.subplot(121) ax.imshow(img) ax = plt.subplot(122) ax.imshow(mask) plt.show()
import os import numpy as np import matplotlib.pyplot as plt from color_transfer.parts.pilutil import imread, imresize from color_transfer.parts.fast_guided_filter import fast_guided_filter path = "/".join(os.path.realpath(__file__).replace("\\", "/").split("/")[:-1]) a = imread(path + "/a.jpg") b = imread(path + "/b.jpg") w, h = a.shape[:2] w, h = w // 8, h // 8 a_low = imresize(a, (w, h)) / 255 b_low = imresize(b, (w, h)) / 255 a_high = a / 255 # equal channels b_high = fast_guided_filter(a_low, b_low, a_high) plt.subplot(221).imshow(a_low) plt.subplot(222).imshow(a_high) plt.subplot(223).imshow(b_low) plt.subplot(224).imshow(b_high) plt.show() # different channels a_low = np.mean(a_low, axis=2, keepdims=True) a_high = np.mean(a_high, axis=2, keepdims=True) b_high = fast_guided_filter(a_low, b_low, a_high) plt.subplot(221).imshow(a_low[:, :, 0]) plt.subplot(222).imshow(a_high[:, :, 0]) plt.subplot(223).imshow(b_low) plt.subplot(224).imshow(b_high) plt.show()
import os import numpy as np import matplotlib.pyplot as plt from color_transfer.parts.pilutil import imread from color_transfer.parts.nnf_computation_c import nn_search, bds_vote path = "/".join(os.path.realpath(__file__).replace("\\", "/").split("/")[:-1]) src = imread(path + "/a.jpg") ref = imread(path + "/b.jpg") patch_size = 3 total_iter = 2 w = 1 nnf_sr, nnf_rs = nn_search(src, ref, patch_size, total_iter) # nn search guide = bds_vote(ref, nnf_sr, nnf_rs, patch_size, w) # bds vote guide = np.uint8(guide) plt.subplot(121).imshow(src) plt.subplot(122).imshow(guide) plt.show()
import os import matplotlib.pyplot as plt from color_transfer.parts.pspnet50_ade20k import PSPNet50ADE20K from color_transfer.parts.pilutil import imread path = "/".join(os.path.realpath(__file__).replace("\\", "/").split("/")[:-1]) pattern = path + "/%d.jpg" psp = PSPNet50ADE20K() for i in range(10): file = pattern % i img = imread(file) predicted = psp.colorize(psp.predict(img)) ax = plt.subplot(121) ax.imshow(img) ax = plt.subplot(122) ax.imshow(predicted) plt.show()