replace current seam carving implementation (#334) - #801
Open
Rynoxx wants to merge 2 commits into
Open
Conversation
Rynoxx
force-pushed
the
feature/improved-seam-carving
branch
from
July 16, 2026 15:50
f02e286 to
e338cee
Compare
Finds and removes multiple seams at a time using the algorithms from https://web.archive.org/web/20120404113111/https://users.cs.cf.ac.uk/Paul.Rosin/resources/papers/seam-carving-ChinaF.pdf
Rynoxx
force-pushed
the
feature/improved-seam-carving
branch
from
July 17, 2026 21:13
e338cee to
c47bfc8
Compare
Rynoxx
force-pushed
the
feature/improved-seam-carving
branch
from
July 18, 2026 16:07
4544151 to
7b51446
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #334
For the past few months I've been working on-and-off on a seam carving implementation based on the suggested paper
https://web.archive.org/web/20120404113111/https://users.cs.cf.ac.uk/Paul.Rosin/resources/papers/seam-carving-ChinaF.pdf
Since the new algorithm allows for finding and removing all seams simultanioulsy I chose to adjust the public API to deprecate the old find_vertical_seam and remove_vertical_seam, while adding two new equivalents (
find_vertical_seams,remove_vertical_seams) forVerticalSeams. It might make sense to makeremove_vertical_seamnon-deprecated, because I've keptVerticalSeamanddraw_vertical_seamin case people want to do anything with the individual seams.The signature for
shrink_widthstays the same.Most design choices here have been led by an intention to optimize performance while keeping accuracy.
Where benchmarks found it beneficial sections have been made into branchless and zip:ed iterators instead of indexing into a vec/slice.
This has also led to some parts which might be slightly overkill/overengineered.
AI Disclaimer:
I've been using AI quite extensively to help me understand the research paper, how to implement the algorithms described and create tests.
All of the generated code has been reviewed by me, refactored, tested and benchmarked.
Benchmarks:
Benchmarks were ran on Linux with a Ryzen 9 5900XT and 32GB of RAM.
Compared to imagemagick it's significantly faster (37x?) when removing 500px from a 4080x3072, and 7.5x faster when removing 50px from a 300x188 image.
Almost unnecessary to compare to old implementation for larger sizes.
The
catbench suite is using the same image as my manual runs, which is the comparison image attached below.Comparison images:

Original:
Imagemagick:



Old imageproc implementation:
This implementation: