Skip to main content

SeamOp

CI License: MIT

seamop is a Python library and command-line tool for content-aware image resizing. It shrinks images by removing connected paths of low-energy pixels instead of scaling every pixel or cropping a fixed region.

Original (1428 × 968) Resized (1000 × 900)
Original castle image Content-aware resized castle image

The current beta supports shrinking by seam removal. Enlargement and seam insertion are not implemented.

Installation

Install from PyPI:

python -m pip install seamop

For development, use the locked uv environment:

uv sync --extra dev --frozen

Command line

Resize the smaller example to 400 by 240 pixels:

seamop resize examples/medium.jpg 400 240

This writes medium_resized_400x240.jpg in the current directory. Use --output to choose another path. Existing image outputs are not overwritten.

Preview the pixels that the same resize would remove:

seamop highlight examples/medium.jpg 400 240

Remove ten vertical seams:

seamop remove examples/medium.jpg --direction vertical --count 10

The default backward strategy uses gradient energy. Select pure forward energy with --strategy forward; do not combine it with --energy.

Other commands and options are available through the built-in help:

seamop --help
seamop resize --help
seamop remove --help
seamop highlight --help

CLI dimensions use WIDTH HEIGHT.

Python

resize() accepts a filesystem path, Pillow image, RGB uint8 NumPy array, or nested RGB integer list. It returns a new RGB uint8 NumPy array without mutating the input.

from PIL import Image
import seamop

result = seamop.resize(
    "examples/medium.jpg",
    width=400,
    height=240,
)

Image.fromarray(result).save("medium_resized_400x240.jpg")

Use plan() when the carved result and preview must use the same seam decisions:

resize_plan = seamop.plan(
    "examples/medium.jpg",
    width=400,
    height=240,
)

preview = resize_plan.preview()
result = resize_plan.result()

Both output methods return independent arrays. Calling either method does not change the plan.

The default strategy is backward seam carving with GradientEnergy. The forward strategy can be selected explicitly:

from seamop import CarvingStrategy

result = seamop.resize(
    "examples/medium.jpg",
    width=400,
    height=240,
    strategy=CarvingStrategy.FORWARD,
)

Backward carving also accepts built-in or custom energy callables through energy=. Pure forward carving does not accept an energy callable.

See the Python API guide for input rules, custom energy methods, errors, and the advanced seam-calculation interface.

Documentation

Development

Run the repository checks from the project root:

uv run --frozen ruff check src tests benchmarks
uv run --frozen ruff format --check src tests benchmarks
uv run --frozen mypy
uv run --frozen pytest --cov
uv run --frozen pytest --doctest-modules src/seamop

Benchmarks run separately:

uv run --frozen pytest benchmarks

Limitations

  • Only shrinking is supported.
  • Width is reduced before height when both dimensions change.
  • Results depend on the image and selected carving strategy and energy method.
  • Large reductions can distort important content.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

seamop-0.4.0.tar.gz (36.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

seamop-0.4.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

Details for the file seamop-0.4.0.tar.gz.

File metadata

  • Download URL: seamop-0.4.0.tar.gz
  • Upload date:
  • Size: 36.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for seamop-0.4.0.tar.gz
Algorithm Hash digest
SHA256 c6740b0ed03af249f63418df8ba6609ff6a45f1fb5a6c8de2df198b70182f8a6
MD5 7bdbdc1c353b4de65009072839cf3a9f
BLAKE2b-256 c758f031418d52879a94e0447e37ddb064a3ead9769f2a6a67ba56e3854dc3bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for seamop-0.4.0.tar.gz:

Publisher: release.yml on okinealb/seamop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file seamop-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: seamop-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 20.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for seamop-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce4b4a1d95e5a9527278f6440cdfb24bf1481f008638f521152aa99b47dcd828
MD5 5569a40e6b01586d141542092c772298
BLAKE2b-256 941aae80902e7f0a2ee8a3d9b0faa457ec2b77b229468b0d83420dcc59872608

See more details on using hashes here.

Provenance

The following attestation bundles were made for seamop-0.4.0-py3-none-any.whl:

Publisher: release.yml on okinealb/seamop

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.4.1

5 files

This release

0.4.0 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page