mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-08-22 06:23:20 -07:00
Formatting
This commit is contained in:
parent
e2bc65d5f0
commit
62c7be73b6
1 changed files with 88 additions and 84 deletions
|
@ -1,6 +1,7 @@
|
|||
import numpy as np
|
||||
import cv2
|
||||
|
||||
|
||||
def reinhard_color_transfer(target, source, clip=False, preserve_paper=False, source_mask=None, target_mask=None):
|
||||
"""
|
||||
Transfers the color distribution from the source to the target
|
||||
|
@ -35,7 +36,6 @@ def reinhard_color_transfer(target, source, clip=False, preserve_paper=False, so
|
|||
OpenCV image (w, h, 3) NumPy array (uint8)
|
||||
"""
|
||||
|
||||
|
||||
# convert the images from the RGB to L*ab* color space, being
|
||||
# sure to utilizing the floating point data type (note: OpenCV
|
||||
# expects floats to be 32-bit, so use that instead of 64-bit)
|
||||
|
@ -85,13 +85,14 @@ def reinhard_color_transfer(target, source, clip=False, preserve_paper=False, so
|
|||
# return the color transferred image
|
||||
return transfer
|
||||
|
||||
|
||||
def linear_color_transfer(target_img, source_img, mode='pca', eps=1e-5):
|
||||
'''
|
||||
"""
|
||||
Matches the colour distribution of the target image to that of the source image
|
||||
using a linear transform.
|
||||
Images are expected to be of form (w,h,c) and float in [0,1].
|
||||
Modes are chol, pca or sym for different choices of basis.
|
||||
'''
|
||||
"""
|
||||
mu_t = target_img.mean(0).mean(0)
|
||||
t = target_img - mu_t
|
||||
t = t.transpose(2, 0, 1).reshape(3, -1)
|
||||
|
@ -123,6 +124,7 @@ def linear_color_transfer(target_img, source_img, mode='pca', eps=1e-5):
|
|||
matched_img[matched_img < 0] = 0
|
||||
return matched_img
|
||||
|
||||
|
||||
def lab_image_stats(image):
|
||||
# compute the mean and standard deviation of each channel
|
||||
(l, a, b) = cv2.split(image)
|
||||
|
@ -133,6 +135,7 @@ def lab_image_stats(image):
|
|||
# return the color statistics
|
||||
return (lMean, lStd, aMean, aStd, bMean, bStd)
|
||||
|
||||
|
||||
def _scale_array(arr, clip=True):
|
||||
if clip:
|
||||
return np.clip(arr, 0, 255)
|
||||
|
@ -146,6 +149,7 @@ def _scale_array(arr, clip=True):
|
|||
|
||||
return arr
|
||||
|
||||
|
||||
def channel_hist_match(source, template, hist_match_threshold=255, mask=None):
|
||||
# Code borrowed from:
|
||||
# https://stackoverflow.com/questions/32655686/histogram-matching-of-two-images-in-python-2-x
|
||||
|
@ -176,6 +180,7 @@ def channel_hist_match(source, template, hist_match_threshold=255, mask=None):
|
|||
|
||||
return interp_t_values[bin_idx].reshape(oldshape)
|
||||
|
||||
|
||||
def color_hist_match(src_im, tar_im, hist_match_threshold=255):
|
||||
h, w, c = src_im.shape
|
||||
matched_R = channel_hist_match(src_im[:, :, 0], tar_im[:, :, 0], hist_match_threshold, None)
|
||||
|
@ -186,6 +191,5 @@ def color_hist_match(src_im, tar_im, hist_match_threshold=255):
|
|||
for i in range(3, c):
|
||||
to_stack += (src_im[:, :, i],)
|
||||
|
||||
|
||||
matched = np.stack(to_stack, axis=-1).astype(src_im.dtype)
|
||||
return matched
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue