mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-08-22 06:23:20 -07:00
Update LCT mode/epsilon
This commit is contained in:
parent
390a9638d5
commit
77eb38811f
6 changed files with 38 additions and 4 deletions
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
BIN
imagelib/test/test output_screenshot_14.08.2019-lca.png
Normal file
BIN
imagelib/test/test output_screenshot_14.08.2019-lca.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 747 KiB |
BIN
imagelib/test/test output_screenshot_14.08.2019-lct-2.png
Normal file
BIN
imagelib/test/test output_screenshot_14.08.2019-lct-2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 944 KiB |
BIN
imagelib/test/test output_screenshot_14.08.2019-lct-eps-2.png
Normal file
BIN
imagelib/test/test output_screenshot_14.08.2019-lct-eps-2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 677 KiB |
BIN
imagelib/test/test output_screenshot_14.08.2019-lct-eps.png
Normal file
BIN
imagelib/test/test output_screenshot_14.08.2019-lct-eps.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
Loading…
Add table
Add a link
Reference in a new issue