-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRMA_Texture_Splitter.py
More file actions
60 lines (47 loc) · 1.96 KB
/
RMA_Texture_Splitter.py
File metadata and controls
60 lines (47 loc) · 1.96 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from PIL import Image
import os
import shutil
def split_and_save_channels(image_path, target_folder):
# Open the image using Pillow
image = Image.open(image_path)
# Split the image into separate channels
r, g, b = image.split()
# Create a list of channel images and their corresponding names
channel_images = [
(r, "Roughness"),
(g, "Metallic"),
(b, "AO")
]
# Get the directory path and filename
image_dir, image_filename = os.path.split(image_path)
image_name, _ = os.path.splitext(image_filename)
# Create the "converted" folder if it doesn't exist
converted_folder = os.path.join(target_folder, "converted")
os.makedirs(converted_folder, exist_ok=True)
# Save each channel as a separate file in the "converted" folder
for channel, channel_name in channel_images:
channel_image = Image.new("L", image.size)
channel_image.putdata(channel.getdata())
channel_path = os.path.join(converted_folder, f"{image_name}_{channel_name}.png")
channel_image.save(channel_path)
print(f"Channels split and saved for {image_filename}.")
# Delete the original image file
os.remove(image_path)
print("Original image file deleted.")
def find_image_files(directory):
# Get a list of all files in the directory
files = os.listdir(directory)
# Find image files (PNG or JPG)
image_files = []
for file in files:
if file.lower().endswith((".png", ".jpg", ".jpeg", ".tga")):
image_files.append(os.path.join(directory, file))
return image_files
if __name__ == "__main__":
target_folder = r"C:\Users\Kamal Khanal\Desktop\RMA Splitter"
image_files = find_image_files(target_folder)
if image_files:
for image_path in image_files:
split_and_save_channels(image_path, target_folder)
else:
print("No image files found in the specified folder.")