Update LCT mode/epsilon

This commit is contained in:
Jeremy Hummel 2019-08-14 00:38:34 -07:00
commit 77eb38811f
6 changed files with 38 additions and 4 deletions

View file

@ -92,7 +92,7 @@ def reinhard_color_transfer(source, target, clip=False, preserve_paper=False, so
return transfer
def linear_color_transfer(target_img, source_img, mode='pca', eps=1e-5):
def linear_color_transfer(target_img, source_img, mode='sym', eps=1e-3):
"""
Matches the colour distribution of the target image to that of the source image
using a linear transform.
@ -128,11 +128,10 @@ def linear_color_transfer(target_img, source_img, mode='pca', eps=1e-5):
Qt_Cs_Qt = Qt.dot(Cs).dot(Qt)
eva_QtCsQt, eve_QtCsQt = np.linalg.eigh(Qt_Cs_Qt)
QtCsQt = eve_QtCsQt.dot(np.sqrt(np.diag(eva_QtCsQt))).dot(eve_QtCsQt.T)
ts = np.linalg.inv(Qt).dot(QtCsQt).dot(np.linalg.pinv(Qt)).dot(t)
ts = np.linalg.pinv(Qt).dot(QtCsQt).dot(np.linalg.pinv(Qt)).dot(t)
matched_img = ts.reshape(*target_img.transpose(2, 0, 1).shape).transpose(1, 2, 0)
matched_img += mu_s
matched_img[matched_img > 1] = 1
matched_img[matched_img < 0] = 0
np.clip(matched_img, 0, 1, out=matched_img)
return matched_img

View file

@ -55,6 +55,41 @@ class ColorTranfer(unittest.TestCase):
cv2.waitKey(0)
cv2.destroyAllWindows()
def test_lct_algorithms(self):
src_samples = SampleLoader.load(SampleType.FACE, './test_src', None)
dst_samples = SampleLoader.load(SampleType.FACE, './test_dst', None)
for src_sample in src_samples:
src_img = src_sample.load_bgr()
src_mask = src_sample.load_mask()
# Toggle to see masks
show_masks = True
grid = []
for ct_sample in dst_samples:
print(src_sample.filename, ct_sample.filename)
ct_img = ct_sample.load_bgr()
ct_mask = ct_sample.load_mask()
results = []
for mode in ['sym']:
for eps in [10**-n for n in range(1, 10, 2)]:
results.append(linear_color_transfer(src_img, ct_img, mode=mode, eps=eps))
if show_masks:
results = [src_mask * im for im in results]
src_img *= src_mask
ct_img *= ct_mask
results = np.concatenate((src_img, ct_img, *results), axis=1)
grid.append(results)
cv2.namedWindow('test output', cv2.WINDOW_NORMAL)
cv2.imshow('test output', np.concatenate(grid, axis=0))
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == '__main__':
unittest.main()

Binary file not shown.

After

Width:  |  Height:  |  Size: 747 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 944 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB