Skip to content

FocalChord/orient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

orient

Detect and fix image orientation using a deep learning model (Deep-OAD ViT).

Install

pip install orient-img

Usage

import orient

# Detect orientation
result = orient.detect("photo.jpg")
result.orientation      # orient.Orientation.CW_90
result.confidence       # 0.93
result.angle            # 82.4
result.needs_rotation   # True
result.is_correct       # False

# Batch detection
results = orient.detect(["a.jpg", "b.jpg"])

# Folder detection — finds all JPEGs recursively
results = orient.detect("photos/")
for r in results:
    print(f"{r.path.name}: {r.orientation.label}")

# Folder options
orient.detect("photos/", batch_size=16, recursive=False)

# PIL Image input
from PIL import Image
result = orient.detect(Image.open("photo.jpg"))

# Detect + fix orientation
orient.fix("photo.jpg")                       # set EXIF tag (default, lossless)
orient.fix("photo.jpg", method="transpose")   # rotate pixels via Pillow
orient.fix(["a.jpg", "b.jpg"])

# Fix an entire folder
orient.fix("photos/")

How it works

Uses a fine-tuned ViT model to predict the rotation angle of an image. For 90/270 degree predictions, a verification pass rotates the image both ways and picks the direction that looks most upright.

Model weights (~990 MB) are automatically downloaded from Hugging Face on first use.

Rotation methods

  • exif (default) — Sets the EXIF Orientation tag via piexif. Truly lossless (metadata only). No external tools needed.
  • transpose — Rotates pixels using Pillow. Re-encodes JPEG but works everywhere. No external tools needed.

See also

  • auto-orient - CLI tool for bulk processing
  • Deep-OAD - The underlying orientation angle detection model

About

Detect and fix image orientation using deep learning

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages