Author Topic: Script for batch adjustment of all z values?  (Read 3731 times)


  • Newbie
  • *
  • Posts: 13
    • View Profile
Script for batch adjustment of all z values?
« on: October 23, 2023, 12:44:02 PM »
Hi there,

I have over 3000 deep-sea images, all taken from 2000+ metres depth. They are exif stamped but their altitude exif stamps are positive, I.e. all images have an altitude of 2000+ metres. Is there a code to batch adjust all z values to negative, I.e. multiply all z values by -1?

Any help would be appreciated,




  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Script for batch adjustment of all z values?
« Reply #1 on: October 23, 2023, 03:51:21 PM »

yes, you can use here the "piexif" Python library to achieve this.
Here is a python script to batch, and i hope i could help you.

Code: [Select]
import piexif
import os

def adjust_altitude(image_path):

    exif_dict = piexif.load(image_path)

    if piexif.GPSIFD.GPSAltitude in exif_dict["GPS"]:
        altitude = exif_dict["GPS"][piexif.GPSIFD.GPSAltitude]

        adjusted_altitude = (altitude[0] * -1, altitude[1])

        exif_dict["GPS"][piexif.GPSIFD.GPSAltitude] = adjusted_altitude
        exif_bytes = piexif.dump(exif_dict)
        piexif.insert(exif_bytes, image_path)

def batch_adjust_altitudes(directory):
    for filename in os.listdir(directory):
        if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
            adjust_altitude(os.path.join(directory, filename))


Replace 'path' with the path to the directory containing your images.
and you have to install the piexif library.

Best Regard
« Last Edit: October 23, 2023, 08:52:04 PM by Photo »


  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Script for batch adjustment of all z values?
« Reply #2 on: October 24, 2023, 02:33:51 PM »
Hi Photo,

Thanks for that. I managed to find a code that works within the Agisoft console,

import Metashape

# Define the altitude adjustment factor (multiply by -1)
altitude_adjustment_factor = -1.0

# Access the current open project
doc =

# Loop through all the chunks in the project
for chunk in doc.chunks:
    # Loop through all the cameras in the chunk
    for camera in chunk.cameras:
        # Check if the camera is part of the "Downward_looking" group
        if "Downward_looking" in
            if not camera.reference.location:
                continue  # Skip cameras without location data

            # Get the camera's location data
            location = camera.reference.location
            # Adjust altitude by multiplying by -1
            location.z *= altitude_adjustment_factor

            # Update the camera's location
            camera.reference.location = location

# Save the modified project

print("Altitude adjustment complete.")