Skip to content

Instantly share code, notes, and snippets.

@awestley
Last active March 7, 2025 21:56
Show Gist options
  • Save awestley/82791cad7eee7ac9d287b3f56339ce12 to your computer and use it in GitHub Desktop.
Save awestley/82791cad7eee7ac9d287b3f56339ce12 to your computer and use it in GitHub Desktop.
North-Up Image Correction for DJI Drone Photos

Overview

This script automatically rotates DJI drone images so that North is at the top, based on the Gimbal Yaw Degree stored in the image metadata.

How It Works

  • Extracts Gimbal Yaw Degree (the camera's direction when the photo was taken).
  • Computes the correct rotation using the formula:

Rotation Angle = 180 - Gimbal Yaw Degree

  • Rotates the image accordingly so that North is correctly up.

⠀Requirements Ensure you have the following installed: ExifTool (for extracting metadata)

brew install exiftool # macOS

sudo apt install libimage-exiftool-perl # Linux

ImageMagick (for rotating images)

brew install imagemagick # macOS

sudo apt install imagemagick # Linux

Usage

Rotate a Single Image

exiftool -GimbalYawDegree -s3 "input.jpg"
ROTATION_ANGLE=$(exiftool -GimbalYawDegree -s3 "input.jpg" | awk '{print 180 - $1}')
convert "input.jpg" -rotate "$ROTATION_ANGLE" "output_NorthUp.jpg"

Batch Process All DJI Images in a Directory

for img in DJI_*.jpg; do
     ROTATION_ANGLE=$(exiftool -GimbalYawDegree -s3 "$img" | awk '{print 180 - $1}')
     convert "$img" -rotate "$ROTATION_ANGLE" "${img%.*}_NorthUp.jpg"
     echo "Processed: $img${img%.*}_NorthUp.jpg"
done

Notes

  • Works for DJI drone images that contain Gimbal Yaw Degree metadata.
  • If GimbalYawDegree is missing, the script will not rotate the image.
  • The script assumes no extreme camera tilt; it only corrects rotation based on yaw.

Example Output

Before correction:

  • Gimbal Yaw Degree: -65.3° (Camera was pointing ~WNW)

⠀After correction:

  • Image rotated 65.3° counterclockwise to align North at the top.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment