import os
from PIL import Image

def convert_indexed_to_rgb(parent_folder):
    for root, dirs, files in os.walk(parent_folder):
        for file in files:
            file_path = os.path.join(root, file)
            try:
                with Image.open(file_path) as img:
                    if img.mode == 'P':
                        img = img.convert('RGB')
                        img.save(file_path)
                        print(f"Converted {file_path} to RGB mode.")
            except Exception as e:
                print(f"Failed to convert {file_path}: {e}")

parent_folder = '_n'

convert_indexed_to_rgb(parent_folder)
