A Python library and CLI for content-aware image resizing using seam carving.
Project description
SeamOp
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) |
|---|---|
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
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.
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 energy method.
- Large reductions can distort important content.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file seamop-0.1.0.tar.gz.
File metadata
- Download URL: seamop-0.1.0.tar.gz
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60ae6abcef58debb35ba3d3d55954befaee2a5dd28e0dc06ed5e6024aff5234b
|
|
| MD5 |
785eb971dd2d7a98002e4034b7dbdfed
|
|
| BLAKE2b-256 |
6e2591df86029fdbd8a2acfe1536a7345573f65ded4d75730d18538a6df4505b
|
File details
Details for the file seamop-0.1.0-py3-none-any.whl.
File metadata
- Download URL: seamop-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8d0ec19747e2b29773831792649d3745e0691e8b98bcce9f5827200e37fa397
|
|
| MD5 |
7f821bbe965b580f7021c574bb4b6eb7
|
|
| BLAKE2b-256 |
19fb482ec673dd7c47d874eda3529b3ca0866181a48e416e9cf31da02aa3f36b
|