MCPcopy Create free account
hub / github.com/Francis-Rings/FlashPortrait / color_transfer

Function color_transfer

wan/utils/utils.py:31–57  ·  view source on GitHub ↗

Transfer color distribution from of sc, referred to dc. Args: sc (numpy.ndarray): input image to be transfered. dc (numpy.ndarray): reference image Returns: numpy.ndarray: Transferred color distribution on the sc.

(sc, dc)

Source from the content-addressed store, hash-verified

29 return height_slider, width_slider
30
31def color_transfer(sc, dc):
32 """
33 Transfer color distribution from of sc, referred to dc.
34
35 Args:
36 sc (numpy.ndarray): input image to be transfered.
37 dc (numpy.ndarray): reference image
38
39 Returns:
40 numpy.ndarray: Transferred color distribution on the sc.
41 """
42
43 def get_mean_and_std(img):
44 x_mean, x_std = cv2.meanStdDev(img)
45 x_mean = np.hstack(np.around(x_mean, 2))
46 x_std = np.hstack(np.around(x_std, 2))
47 return x_mean, x_std
48
49 sc = cv2.cvtColor(sc, cv2.COLOR_RGB2LAB)
50 s_mean, s_std = get_mean_and_std(sc)
51 dc = cv2.cvtColor(dc, cv2.COLOR_RGB2LAB)
52 t_mean, t_std = get_mean_and_std(dc)
53 img_n = ((sc - s_mean) * (t_std / s_std)) + t_mean
54 np.putmask(img_n, img_n > 255, 255)
55 np.putmask(img_n, img_n < 0, 0)
56 dst = cv2.cvtColor(cv2.convertScaleAbs(img_n), cv2.COLOR_LAB2RGB)
57 return dst
58
59def save_videos_grid(videos: torch.Tensor, path: str, rescale=False, n_rows=6, fps=12, imageio_backend=True, color_transfer_post_process=False):
60 videos = rearrange(videos, "b c t h w -> t b c h w")

Callers 1

save_videos_gridFunction · 0.85

Calls 1

get_mean_and_stdFunction · 0.85

Tested by

no test coverage detected