All Projects → andrewdcampbell → seam-carving

andrewdcampbell / seam-carving

Licence: GPL-3.0 license
A fast Python implementation of Seam Carving for Content-Aware Image Resizing.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to seam-carving

seam-carving
An implementation of the seam carving algorithm, designed to resize images while preventing distortion.
Stars: ✭ 30 (-83.52%)
Mutual labels:  seam-carving, image-resizing
smartImgProcess
手工实现的智能图片处理系统 包含基础的图片处理功能 各类滤波 seam carving算法 以及结合精细语义分割信息 实现智能去除目标的功能
Stars: ✭ 22 (-87.91%)
Mutual labels:  seam-carving
js-image-carver
🌅 Content-aware image resizer and object remover based on Seam Carving algorithm
Stars: ✭ 1,467 (+706.04%)
Mutual labels:  seam-carving
Caire
Content aware image resize library
Stars: ✭ 9,783 (+5275.27%)
Mutual labels:  seam-carving
Bicubic-interpolation
Bicubic interpolation for images (Python)
Stars: ✭ 88 (-51.65%)
Mutual labels:  image-resizing
docker-imgproxy
🌐 An ultra fast, production-grade on-the-fly image processing web server. Designed for high throughput with Nginx caching. Powered by imgproxy.
Stars: ✭ 45 (-75.27%)
Mutual labels:  image-resizing
reImage
Fast image resizing backend based on libvips, mozjpeg and pngquant
Stars: ✭ 107 (-41.21%)
Mutual labels:  image-resizing
rszr
Fast image resizer for Ruby
Stars: ✭ 21 (-88.46%)
Mutual labels:  image-resizing
tensorflow-bicubic-downsample
tf.image.resize_images has aliasing when downsampling and does not have gradients for bicubic mode. This implementation fixes those problems.
Stars: ✭ 23 (-87.36%)
Mutual labels:  image-resizing
Video Object Removal
Just draw a bounding box and you can remove the object you want to remove.
Stars: ✭ 2,283 (+1154.4%)
Mutual labels:  object-removal
Deep-Object-Removal
Using cGANs to remove objects from a photo
Stars: ✭ 82 (-54.95%)
Mutual labels:  object-removal
Implicit-Internal-Video-Inpainting
[ICCV 2021]: IIVI: Internal Video Inpainting by Implicit Long-range Propagation
Stars: ✭ 190 (+4.4%)
Mutual labels:  object-removal
Depth-Guided-Inpainting
Code for ECCV 2020 "DVI: Depth Guided Video Inpainting for Autonomous Driving"
Stars: ✭ 50 (-72.53%)
Mutual labels:  object-removal

seam-carving

A fast Python implementation of Seam Carving for Content-Aware Image Resizing (2007), including the improved energy algorithm described in Improved Seam Carving for Video Retargeting (2008).

Requirements

  • OpenCV
  • scipy
  • numba
  • numpy

Usage

python seam_carving.py (-resize | -remove) -im <IM_PATH> -out <OUTPUT_IM_NAME> 
                       [-mask <MASK_PATH>] [-rmask <REMOVAL_MASK_PATH>] [-dy <DY>] [-dx <DX>] 
                       [-vis] [-hremove] [-backward_energy]

The program is run via the command-line. There are two modes of operations: resize or remove. The former is for resizing an image vertically or horizontally and the latter is for removing an object as specified by a mask.

For both modes:

  • -im: The path to the image to be processed.
  • -out: The name for the output image.
  • -mask: (Optional) The path to the protective mask. The mask should be binary and have the same size as the input image. White areas represent regions where no seams should be carved (e.g. faces).
  • -vis: If present, display a window while the algorithm runs showing the seams as they are removed.
  • -backward_energy: If present, use the backward energy function (i.e. gradient magnitude) instead of the forward energy function (default).

For resizing:

  • -dy: Number of horizontal seams to add (if positive) or subtract (if negative). Default is 0.
  • -dx: Number of vertical seams to add (if positive) or subtract (if negative). Default is 0.

For object removal:

  • -rmask: The path to the removal mask. The mask should be binary and have the same size as the input image. White areas represent regions to be removed.
  • -hremove: If present, perform seam removal horizontally rather than vertically. This will be more appropriate in certain contexts.

Additional Parameters

There are some additional constants defined at the top of the code seam_carving.py that may be modified.

  • The code currently downsizes any images with width larger than 500 pixels to 500 pixels for super fast carving. To change this, change the value of DOWNSIZE_WIDTH, or set SHOULD_DOWNSIZE to False to disable downsizing completely.
  • Seams are visualized as a bluish-white color; change the color by changing the SEAM_COLOR array (in BGR format).

Example Results

The input image is on the left and the result of the algorithm is on the right.

Vertical Seam Removal

Horizontal Seam Removal

Seam Removal with Protective Masks

Seam Insertion

Object Removal with Protective Masks

Object Removal with Seam Insertion

Animated gif:

Comparison between Energy Functions

In general, forward energy gives better results than backward energy. The result of resizing using backward energy (left) and forward energy (right) is shown below.


For more information on how the algorithm works, see my blog post.

Acknowledgements

Many parts of the code are adapted/optimized versions of functionality from other implementations:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].