Seam Carving is a content-aware image resizing algorithm introduced in this paper. Unlike traditional resizing methods that distort images by scaling them uniformly, seam carving selectively adds or removes "seams"—paths of least importance—to preserve the image’s perceptual quality.
For a more detailed explanation, you can refer to the original paper. This repository was inspired by this awesome project, which provides a CPU-based implementation available as a Python package (pip). In contrast, our implementation uses CUDA to take advantage of the massive parallel processing power of GPUs for faster performance.
Currently, this repository supports only image downsizing. However, additional features such as image upsizing, auxiliary energy addition, and other enhancements mentioned in the paper will be introduced in future updates.
We also plan to optimize the CUDA kernels further to improve performance. That said, once the upsizing feature is implemented, our next priority will likely be adding extensive tests—debugging CUDA kernels without them can be quite tedious.
For now, if your use case involves image downsizing, this repository provides a fast and efficient solution.
- Clone the repository:
git clone https://github.com/soulsharp/Seam-Carving-CUDA- Install dependencies using pip:
pip install -r requirements.txt- Run the main file:
python main.py --img_path path_of_your_image --resized_width reduced_width --resized_height reduced_heightpython main.py --img_path path_of_your_image --reduced_width 1000 --reduced_height 1000Note that all parameters, ie img_path, reduced_width and reduced_height are mandatory. Results are saved to the examples/results folder.You will need to modify the code(the save_image function), to change the save_path of the resized image.
In the future, additional arguments pertaining to adding auxilliary image masks and image removal will be added.
The CPU-based project mentioned earlier provides a benchmark for measuring the algorithm’s speed: resizing castle.jpg (407x600) by 200 pixels. Since our repository currently supports only downsizing, here’s a performance comparison for reducing the image’s width by 200 pixels (new size: 407×400).
CPU-based implementation (Google Colab, server-grade CPU): ~1.7 seconds on average Our CUDA implementation (Google Colab, Tesla T4 GPU): ~0.38 seconds on average
For reducing both the image height and width by 200 pixels:
CPU-based implementation: ~2.9 seconds on average Our CUDA implementation: ~0.64 seconds on average
For reducing image height by 500 pixels and image width by 500 pixels for this Photo by Paolo Nicolello on Unsplash :
CPU-based implementation: ~370 seconds on average Our CUDA implementation: ~45 seconds on average
This demonstrates a significant speedup using GPU acceleration(around 4.5x - 8x). Below, you’ll find a few results, including a standard cv2.resize for comparison to visualize distortions and content preservation.
Photo by Paolo Nicolello on Unsplash
Comparisons of resizing the above original images via Seam Carving vs cv2.resize:
Width reduced by 500 pixels:
Left: Resized using CUDA implementation | Right: Resized using OpenCV (cv2.resize)
Width reduced by 200 pixels:
Left: Resized using CUDA implementation | Right: Resized using OpenCV (cv2.resize)
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.





