write a python 3.9 script that can transform equirectangular map to 6 faces of cubemap.…
- User
write a python 3.9 script that can transform equirectangular map to 6 faces of cubemap. user needs to type path for input (png) and output. Add that on output all 6 faces are joined into one image (png) horizontally without spaces. in that order: X+, X-, Y+, Y-, Z+, Z-
- Assistant
Sure! Here's a Python script that can transform an equirectangular map to the six faces of a cubemap:
import os import sys from PIL import Image def equirectangular_to_cubemap(input_path, output_path): # Load the input equirectangular image input_image = Image.open(input_path) width, height = input_image.size # Create an output image for each face of the cubemap face_width = width // 4 face_height = height // 3 # Create a blank image for the cubemap output_image = Image.new('RGB', (face_width * 4, face_height * 3)) # Create mappings between direction and face index face_mappings = { 'X+': 0, 'X-': 1, 'Y+': 2, 'Y-': 3, 'Z+': 4, 'Z-': 5, } for face, index in face_mappings.items(): # Calculate the crop region for each face left = face_width * index top = 0 if 'Z' in face else face_height right = left + face_width bottom = top + face_height # Crop the input image to the face region face_image = input_image.crop((left, top, right, bottom)) # Paste the face image onto the output image output_image.paste(face_image, (left, top)) # Save the resulting cubemap image output_image.save(output_path, 'PNG') if __name__ == '__main__': # Get input and output paths from the user input_path = input("Enter the path to the input image (PNG): ") output_path = input("Enter the path to save the output cubemap image (PNG): ") # Check if the input file exists if not os.path.exists(input_path): print("Input file does not exist!") sys.exit(1) # Transform the equirectangular map to cubemap equirectangular_to_cubemap(input_path, output_path) print("Cubemap conversion completed successfully!")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.