mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-08-22 14:24:40 -07:00
re-enable clipping, enable preserve paper
This commit is contained in:
parent
c24d6a87ea
commit
0e68ed0056
2 changed files with 13 additions and 11 deletions
|
@ -76,7 +76,7 @@ def reinhard_color_transfer(target, source, clip=False, preserve_paper=False, ta
|
|||
a += aMeanSrc
|
||||
b += bMeanSrc
|
||||
|
||||
# clip/scale the pixel intensities to [0, 255] if they fall
|
||||
# clip/scale the pixel intensities to [0, 1] if they fall
|
||||
# outside this range
|
||||
l = _scale_array(l, clip=clip)
|
||||
a = _scale_array(a, clip=clip)
|
||||
|
@ -156,15 +156,15 @@ def _scale_array(arr, clip=True):
|
|||
if clip:
|
||||
return np.clip(arr, 0, 1)
|
||||
|
||||
return (arr - np.min(arr)) / np.ptp(arr)
|
||||
# mn = arr.min()
|
||||
# mx = arr.max()
|
||||
# scale_range = (max([mn, 0]), min([mx, 1]))
|
||||
#
|
||||
# if mn < scale_range[0] or mx > scale_range[1]:
|
||||
# return (scale_range[1] - scale_range[0]) * (arr - mn) / (mx - mn) + scale_range[0]
|
||||
#
|
||||
# return arr
|
||||
# return (arr - np.min(arr)) / np.ptp(arr)
|
||||
mn = arr.min()
|
||||
mx = arr.max()
|
||||
scale_range = (max([mn, 0]), min([mx, 1]))
|
||||
|
||||
if mn < scale_range[0] or mx > scale_range[1]:
|
||||
return (scale_range[1] - scale_range[0]) * (arr - mn) / (mx - mn) + scale_range[0]
|
||||
|
||||
return arr
|
||||
|
||||
|
||||
def channel_hist_match(source, template, hist_match_threshold=255, mask=None):
|
||||
|
|
|
@ -235,13 +235,15 @@ class SampleProcessor(object):
|
|||
img_bgr = imagelib.linear_color_transfer(img_bgr, ct_sample_bgr)
|
||||
|
||||
elif apply_ct == ColorTransferMode.RCT:
|
||||
img_bgr = imagelib.reinhard_color_transfer(img_bgr, ct_sample_bgr)
|
||||
img_bgr = imagelib.reinhard_color_transfer(img_bgr, ct_sample_bgr, clip=True, preserve_paper=True)
|
||||
|
||||
elif apply_ct == ColorTransferMode.RCT_MASKED and ct_sample_mask is None:
|
||||
ct_sample_mask = ct_sample.load_fanseg_mask() or \
|
||||
LandmarksProcessor.get_image_hull_mask(ct_sample_bgr.shape, ct_sample.landmarks)
|
||||
img_bgr = imagelib.reinhard_color_transfer(img_bgr,
|
||||
ct_sample_bgr,
|
||||
clip=True,
|
||||
preserve_paper=True,
|
||||
target_mask=img_mask,
|
||||
source_mask=ct_sample_mask)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue