-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfixUnbakerAlpha.py
27 lines (20 loc) · 1.01 KB
/
fixUnbakerAlpha.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import config
import os
import sys
from tqdm import tqdm
from PIL import Image, ImageEnhance
for x in tqdm( os.listdir(f"textures/processing/upscaled/"), desc="Generating..." ):
if x.endswith(".png"):
#LightspeedOctahedralConverter.convert_dx_file_to_octahedral(f"textures/processing/normaldx/{x}", f"textures/processing/normals/{x}")
source_image = Image.open(f"textures/processing/baked/{x}")
target_image = Image.open(f"textures/processing/upscaled/{x}")
source_image = source_image.convert("RGBA")
target_image = target_image.convert("RGBA")
source_image = source_image.resize(target_image.size)
# Extract the alpha channel from the source image
alpha_channel = source_image.split()[3]
# Create a new image by combining the RGB channels from the target image
# and the extracted alpha channel from the source image
new_image = Image.merge("RGBA", (target_image.split()[:3] + (alpha_channel,)))
# Save the new image with the replaced alpha channel
new_image.save(f"textures/processing/upscaled/{x}")