Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dharness/seam_carving
Python Seam Carving module
https://github.com/dharness/seam_carving
image-processing python3 retargeting seam-carving
Last synced: 3 months ago
JSON representation
Python Seam Carving module
- Host: GitHub
- URL: https://github.com/dharness/seam_carving
- Owner: dharness
- License: mit
- Created: 2017-08-22T03:03:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-02-10T21:24:45.000Z (almost 2 years ago)
- Last Synced: 2024-09-29T17:03:00.860Z (4 months ago)
- Topics: image-processing, python3, retargeting, seam-carving
- Language: Python
- Homepage:
- Size: 55.5 MB
- Stars: 12
- Watchers: 4
- Forks: 1
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# seam_carver
Python Seam Carving moduleseam_carver is a small tool for retargetting images to any dimension greater or smaller. It uses the process of seam carving as originally described by Shai Avidan & Ariel Shamir in http://perso.crans.org/frenoy/matlab2012/seamcarving.pdf
A combination of the gradient energy (determined with the sobel filter) and a simple color energy is used to determine the least important seam. Additon of seams occurs by the same mechanism as described in the paper.
### Installation
```
pip install seam_carver
```### Basic Usage
``` python
from scipy import misc
import numpy as np
from seam_carver import intelligent_resizergb_weights = [-3, 1, -3]
mask_weight = 10
cat_img = misc.imread('./demo/cat.png')
mask = np.zeros(cat_img.shape)resized_img = intelligent_resize(cat_img, 0, -20, rgb_weights, mask, mask_weight)
misc.imsave('./demo/cat_shrunk.png', resized_img)
```### Options
``` python
def intelligent_resize(img, d_rows, d_columns, rgb_weights, mask, mask_weight):
"""
Changes the size of the provided image in either the vertical or horizontal direction,
by increasing or decreasing or some combination of the two.Args:
img (n,m,3 numpy matrix): RGB image to be resized.
d_rows (int): The change (delta) in rows. Positive number indicated insertions, negative is removal.
d_columns (int): The change (delta) in columns. Positive number indicated insertions, negative is removal.
rgb_weights (1,3 numpy matrix): Additional weight paramater to be applied to pixels.
mask (n,m,3 numpy matrix): Mask matrix indicating areas to make more or less likely for removal.
mask_weight (int): Scalar multiple to be applied to mask.Returns:
n,m,3 numpy matrix: Resized RGB image.
"""
```### Examples
For more examples and details see the [demo jupyter notebook](https://github.com/dharness/seam_carving/blob/dharness/improving_docs/demo/Seam%20Carving%20Visual%20Demos.ipynb)
**Original**
![Alt text](/demo/lotr.jpg?raw=true)
**Resized**
![Alt text](/demo/lotr_out.png?raw=true)
**Original**
![Alt text](/demo/hot_dog.jpg?raw=true)
**Resized**
![Alt text](/demo/hot_dog.png?raw=true)
### Limitations
**Original**
![Alt text](/demo/cat.png?raw=true)
**Resized**
![Alt text](/demo/cat_out.png?raw=true)