mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-08-21 05:53:24 -07:00
refactoring
This commit is contained in:
parent
79950c6c0e
commit
b03b147bae
18 changed files with 452 additions and 447 deletions
14
imagelib/reduce_colors.py
Normal file
14
imagelib/reduce_colors.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
import numpy as np
|
||||
import cv2
|
||||
from PIL import Image
|
||||
|
||||
#n_colors = [0..256]
|
||||
def reduce_colors (img_bgr, n_colors):
|
||||
img_rgb = (cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB) * 255.0).astype(np.uint8)
|
||||
img_rgb_pil = Image.fromarray(img_rgb)
|
||||
img_rgb_pil_p = img_rgb_pil.convert('P', palette=Image.ADAPTIVE, colors=n_colors)
|
||||
|
||||
img_rgb_p = img_rgb_pil_p.convert('RGB')
|
||||
img_bgr = cv2.cvtColor( np.array(img_rgb_p, dtype=np.float32) / 255.0, cv2.COLOR_RGB2BGR )
|
||||
|
||||
return img_bgr
|
Loading…
Add table
Add a link
Reference in a new issue