All Projects → axu2 → Improved Seam Carving

axu2 / Improved Seam Carving

A numpy implementation of forward energy from the paper “Improved Seam Carving for Video Retargeting" (2008)

Projects that are alternatives of or similar to Improved Seam Carving

Intro stat modeling 2017
Introduction to Statistical Modeling with Python (PyCon 2017)
Stars: ✭ 151 (-0.66%)
Mutual labels:  jupyter-notebook
Ipyplot
IPyPlot is a small python package offering fast and efficient plotting of images inside Python Notebooks. It's using IPython with HTML for faster, richer and more interactive way of displaying big numbers of images.
Stars: ✭ 152 (+0%)
Mutual labels:  jupyter-notebook
Artificial Intelligence Projects
Collection of Artificial Intelligence projects.
Stars: ✭ 152 (+0%)
Mutual labels:  jupyter-notebook
Pytorch Gan
A minimal implementaion (less than 150 lines of code with visualization) of DCGAN/WGAN in PyTorch with jupyter notebooks
Stars: ✭ 150 (-1.32%)
Mutual labels:  jupyter-notebook
Pydata2015
Stars: ✭ 151 (-0.66%)
Mutual labels:  jupyter-notebook
Covid 19 Data Science
Welcome to Glacier Data Project. A post-wuhan2020 project for data science
Stars: ✭ 152 (+0%)
Mutual labels:  jupyter-notebook
Fast Neural Style
Pytorch Implementation of Perceptual Losses for Real-Time Style Transfer and Super-Resolution
Stars: ✭ 151 (-0.66%)
Mutual labels:  jupyter-notebook
Stanford Cs229
Python solutions to the problem sets of Stanford's graduate course on Machine Learning, taught by Prof. Andrew Ng
Stars: ✭ 151 (-0.66%)
Mutual labels:  jupyter-notebook
Pyrevolution
Python tutorials and puzzles to share with the world!
Stars: ✭ 151 (-0.66%)
Mutual labels:  jupyter-notebook
Amitt framework
Repo replaced by cogsec-collaborative/AMITT
Stars: ✭ 152 (+0%)
Mutual labels:  jupyter-notebook
Rl Stock
📈 如何用深度强化学习自动炒股
Stars: ✭ 2,090 (+1275%)
Mutual labels:  jupyter-notebook
Nbviewer
nbconvert as a web service: Render Jupyter Notebooks as static web pages
Stars: ✭ 1,954 (+1185.53%)
Mutual labels:  jupyter-notebook
Rethinking Tensorflow Probability
Statistical Rethinking (2nd Ed) with Tensorflow Probability
Stars: ✭ 152 (+0%)
Mutual labels:  jupyter-notebook
Asap
ASAP: Prioritizing Attention via Time Series Smoothing
Stars: ✭ 151 (-0.66%)
Mutual labels:  jupyter-notebook
Santander Customer Transaction Prediction
2nd Place Solution 💰🥈
Stars: ✭ 152 (+0%)
Mutual labels:  jupyter-notebook
Chinese Novel Generation
DEPRECATED 尝试使用中文文本训练RNN来产生中文小说。(No longer under maintanance.)
Stars: ✭ 151 (-0.66%)
Mutual labels:  jupyter-notebook
Competition baselines
开源的各大比赛baseline
Stars: ✭ 150 (-1.32%)
Mutual labels:  jupyter-notebook
Netgan
Implementation of the paper "NetGAN: Generating Graphs via Random Walks".
Stars: ✭ 152 (+0%)
Mutual labels:  jupyter-notebook
Mine pytorch
MINE: Mutual Information Neural Estimation in pytorch (unofficial)
Stars: ✭ 152 (+0%)
Mutual labels:  jupyter-notebook
Simfin Tutorials
Tutorials for SimFin - Simple financial data for Python
Stars: ✭ 150 (-1.32%)
Mutual labels:  jupyter-notebook

TLDR: In class, I learned the most basic version of seam carving. Then I read about the improved seam carving algorithm by the same author. I implemented both methods using numpy and hope to add them to scikit-image.

Was No. 1 on Show | Hacker News for a day.

Implementation:

https://nbviewer.jupyter.org/github/axu2/improved-seam-carving/blob/master/Improved%20Seam%20Carving.ipynb

Improved Seam Carving Using Forward Energy

Seam-carving is a content-aware image resizing technique where the image is reduced in size by one pixel of height (or width) at a time. A vertical seam in an image is a path of pixels connected from the top to the bottom with one pixel in each row. Unlike standard content-agnostic resizing techniques (such as cropping and scaling), seam carving preserves the most interesting features (aspect ratio, set of objects present, etc.) of the image.

tower

Above left is the original 714-by-186 pixel image; above middle are the vertical seams; above right is the result after removing 554 vertical seams.

This technique is taught in many Data Structures courses such as:

But these classes neglect to mention the improved seam carving algorithm, published the year after the original.

The difference between the original and the improved can be seen below after carving 200 seams on a 512-by-342 bench image.

The left is the original seam carving algorithm and the right is the improved algorithm:

seam

It took 3 seconds using the original seam carving method and 8 seconds using the improved method, tested on a cheap Windows laptop using Anaconda Python 3.6.

The improved method preserves the gradient of the water and the bench supports much better, and the result is similar to what happens in Adobe Photoshop.

In this notebook, I will be implementing both methods using numpy and scikit-image.

I believe my implementation of the second method is more optimal than any other Python implementation I've seen on Google or GitHub, though I note more potential optimizations in the notebook that could potentially make forward energy just as fast or even faster than backwards energy as its implemented right now in scikit-image.

Implementation Details

For more details, read the original seam carving paper and the Improved Seam Carving paper, where the above photo is from.

Both papers introduce different ways to "calculate the energy of a pixel, which is a measure of its importance—the higher the energy, the less likely that the pixel will be included as part of a seam."

The first paper determined the energy of a pixel by looking at its 4 surrounding neighbors. (e.g. dual gradient.)

The second paper determined the energy of a pixel by looking

forward at the resulting image instead of backward at the image before removing the seam. At each step, we search for the seam whose removal inserts the minimal amount of energy into the image. These are seams that are not necessarily minimal in their energy, but will leave less artifacts in the resulting image, after removal. This coincides with the assumption that natural images are piece-wise smooth intensity surfaces, which is a popular assumption in the literature.

Calculating the three possible vertical seam step costs for pixel pi,j using forward energy. After removing the seam, new neighbors (in gray) and new pixel edges (in red) are created. In each case the cost is defined by the forward difference in the newly created pixel edges. Note that the new edges created in row i − 1 were accounted for in the cost of the previous row pixel.

The two resulting energy maps of the bench image using the two methods look like this, where higher energy pixels are brighter:

eimg

As you can see, seams will not want to pass through the bench using backwards energy, which causes severe artifacts.

Here is an image of the resulting seams and accumulated energy matrices from the paper:

seam

Examples

examples

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].