Created
March 19, 2025 17:29
-
-
Save NomadWithoutAHome/3f1f9c212eb4b318686968a4e816d04f to your computer and use it in GitHub Desktop.
simple script that splits RGB channels in combined textures. specifically for MRAO textures.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tkinter as tk | |
| from tkinter import filedialog, messagebox | |
| from PIL import Image | |
| import os | |
| class ImageSplitterApp: | |
| def __init__(self, root): | |
| self.root = root | |
| self.root.title("Image Channel Splitter") | |
| self.root.geometry("400x200") | |
| # Create and pack widgets | |
| self.create_widgets() | |
| def create_widgets(self): | |
| # Select file button | |
| self.select_btn = tk.Button( | |
| self.root, | |
| text="Select Image", | |
| command=self.select_image, | |
| height=2, | |
| width=20 | |
| ) | |
| self.select_btn.pack(pady=20) | |
| # Status label | |
| self.status_label = tk.Label( | |
| self.root, | |
| text="No image selected", | |
| wraplength=350 | |
| ) | |
| self.status_label.pack(pady=10) | |
| def select_image(self): | |
| file_path = filedialog.askopenfilename( | |
| filetypes=[("Image files", "*.png *.jpg *.jpeg *.bmp *.gif")] | |
| ) | |
| if file_path: | |
| try: | |
| # Open the image | |
| img = Image.open(file_path) | |
| # Split the image into channels | |
| r, g, b = img.split() | |
| # Get the directory and filename | |
| directory = os.path.dirname(file_path) | |
| filename = os.path.splitext(os.path.basename(file_path))[0] | |
| # Save each channel | |
| r.save(os.path.join(directory, f"{filename}_Metal.png")) | |
| g.save(os.path.join(directory, f"{filename}_Rightness.png")) | |
| b.save(os.path.join(directory, f"{filename}_AO.png")) | |
| self.status_label.config( | |
| text=f"Successfully split image into channels!\nSaved in: {directory}" | |
| ) | |
| messagebox.showinfo("Success", "Image channels have been split and saved!") | |
| except Exception as e: | |
| self.status_label.config(text=f"Error: {str(e)}") | |
| messagebox.showerror("Error", f"Failed to process image: {str(e)}") | |
| if __name__ == "__main__": | |
| root = tk.Tk() | |
| app = ImageSplitterApp(root) | |
| root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment