• Stars
    star
    454
  • Rank 92,965 (Top 2 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created almost 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Content aware image resizing

pyCAIR Logo

pyCAIR is a content-aware image resizing(CAIR) library based on Seam Carving for Content-Aware Image Resizing paper.


                                          PyPI version License: GPL v3 Documentation Status PyPI - Python Version Code Health


Table of Contents

  1. How CAIR works
  2. Understanding the research paper
  3. Project structure and explanation
  4. Installation
  5. Usage
  6. Demo
  7. Screenshots
  8. Todo

How does it work

  • An energy map and a grayscale format of image is generated from the provided image.

  • Seam Carving algorithm tries to find the not so useful regions in image by picking up the lowest energy values from energy map.

  • With the help of Dynamic Programming coupled with backtracking, seam carving algorithm generates individual seams over the image using top-down approach or left-right approach.(depending on vertical or horizontal resizing)

  • By traversing the image matrix row-wise, the cumulative minimum energy is computed for all possible connected seams for each entry. The minimum energy level is calculated by summing up the current pixel with the lowest value of the neighboring pixels from the previous row.

  • Find the lowest cost seam from the energy matrix starting from the last row and remove it.

  • Repeat the process iteratively until the image is resized depending on user specified ratio.

Result7 Result8
DP Matrix Backtracking with minimum energy

Intutive explanation of research paper

Notes1

Notes2

Notes3

Notes4

Project structure and explanation

Directory structure:

pyCAIR (root directory)
  | - images/
  | - results /
  | - sequences/ (zipped in repository)
  | - videos/
  | - notdoneyet.py
  | - imgtovideos.py
  | - opencv_generators.py
  | - seam_carve.py
  | - helpers.py

File: notdoneyet.py

  • user_input() -
    Parameters:
    • Alignment: Specify on which axis the resizing operation has to be performed.
    • Scale Ratio: Floating point operation between 0 and 1 to scale the output image.
    • Display Seam: If this option isn't selected, the image is only seamed in background.
    • Input Image
    • Generate Sequences: Generate intermediate sequences to form a video after all the operations are performed.

File: imgtovideos.py

  • generateVideo() - pass each image path to vid() for video generation.

  • vid()- writes each input image to video buffer for creating a complete video.

File: opencv_generators.py

  • generateEnergyMap() - utilised OpenCV inbuilt functions for obtaining energies and converting image to grayscale.

  • generateColorMap() - utilised OpenCV inbuilt functions to superimpose heatmaps on the given image.

File: seam_carve.py

  • getEnergy() - generated energy map using sobel operators and convolve function.

  • getMaps() - implemented the function to get seams using Dynamic Programming. Also, stored results of minimum seam in seperate list for backtracking.

  • drawSeam() - Plot seams(vertical and horizontal) using red color on image.

  • carve() - reshape and crop image.

  • cropByColumn() - Implements cropping on both axes, i.e. vertical and horizontal.

  • cropByRow() - Rotate image to ignore repeated computations and provide the rotated image as an input to cropByColumn function.

File: helpers.py

  • writeImage() - stores the images in results directory.

  • writeImageG() - stores intermediate generated sequence of images in sequences directory.

  • createFolder() - self explanatory

  • getFileExtension() - self explanatory

Other folders:

  • images/ - stores the input images for testing.

  • videos/ - stores the videos generated from the intermediate sequences.

  • results/ - stores the final results.

  • sequences/ - stores the intermediate sequences generated.

Installation

Usage

'''
It runs the entire code and returns final results
'''
from pyCAIR import user_input
user_input(alignment, scale, seam, input_image, generate_sequences)

'''
It generates the energy map
'''
from pyCAIR import generateEnergyMap
generateEnergyMap(image_name, file_extension, file_name)

'''
It generates color maps
'''
from pyCAIR import generateColorMap
generateColorMap(image_name, file_extension, file_name)

'''
It converts sequence of images generated to video
'''
from pyCAIR import generateVideo
generateVideo()

'''
It returns all the paths where images are present for generating video
'''
from pyCAIR import getToProcessPaths
getToProcessPaths()

'''
It returns seams, cropped image for an image
'''
from pyCAIR import cropByColumn
seam_img, crop_img = cropByColumn(image, display_seams, generate, lsit, scale_c, fromRow)

'''
It returns seams, cropped image for an image
'''
from pyCAIR import cropByRow
seam_img, crop_img = cropByRow(image, display_seams, generate, lsit, scale_c)

'''
It returns created folder
'''
from pyCAIR import createFolder
f = createFolder(folder_name)

'''
It returns extension of file
'''
from pyCAIR import getFileExtension
f = getFileExtension(file_name)

'''
It writes image to specified folder
'''
from pyCAIR import writeImage
f = writeImage(image, args)

In Action

Gif1

Gif2

Video Playlist

Screenshots

Results for Image 1:

Result0 Result1 Result2
Original Image Grayscale Energy Map
Result3 Result4
Color Map Winter Color Map Hot
Result5 Result6
Seams for Columns Columns Cropped
Result7 Result8
Seams for Rows Rows Cropped

Results for Image 2:

Result0 Result1 Result2
Original Image Grayscale Energy Map
Result3 Result4
Color Map Winter Color Map Hot
Result5 Result6
Seams for Columns Columns Cropped
Result7 Result8
Seams for Rows Rows Cropped

Todo

  • Implement Seam Algorithm
  • Generate energy maps and color maps for image
  • Display Vertical Seams
  • Display Horizontal Seams
  • Crop Columns
  • Crop Rows
  • Use argparse for Command Line Application
  • Store subsamples in different directories for crop and seam respectively
  • Generate video/gif from sub-samples
  • Provide a better Readme
  • Provide examples for usage
  • Add badges
  • Provide better project description on PyPI
  • Documentation
  • Integrate object detection using YOLOv2 (work in progress.)
  • Identify most important object (using probability of predicted object)
  • Invert energy values of most important object
  • Re-apply Seam Carve and compare results

License

This software is licensed under the GNU General Public License v3.0 © Chirag Shah

More Repositories

1

python-automation-scripts

Simple yet powerful automation stuffs.
Python
439
star
2

design-patterns

Grokking design patterns in python
Python
24
star
3

designing-data-intensive-applications-notes

Notes on book designing data-intensive applications (ongoing)
23
star
4

distributed-systems-notes

101's of Distributed Systems and Scalability
22
star
5

avidLearnerInProgress.github.io_old

Portfolio Page
HTML
17
star
6

leetcode-solutions

Problem solving on Leetcode
C++
13
star
7

design-pattern-notes

Notes for the book - Head First Design Patterns
Java
10
star
8

hand-gesture-recognition

Gesture recognition using OpenCV and Python
Python
9
star
9

sudoku-solver-openCV-python

Sudoku Solver Using OpenCV and Python
Python
8
star
10

_AntiVirus_

Minimal, customisable & powerful antivirus project
C++
7
star
11

new-york-crime-data-analysis

Exploratory data analysis on New York Crime Complaint Data
Jupyter Notebook
7
star
12

placementPreparation

Collection of programs implemented by me from geeksforgeeks.com
C++
5
star
13

EPI_solutions

My solutions to the problems from book "Elements of Programming Interviews" - work in progress
C++
5
star
14

angularjs-practice-codes

angular basics
JavaScript
4
star
15

neural-network-practice

Lab experiments of Soft Computing Techniques
Python
4
star
16

Tensorflow-basics

101's regarding Tensorflow
Jupyter Notebook
4
star
17

advanced-machine-learning-labs

Coursework solutions to AML Labs
Jupyter Notebook
4
star
18

abswp-solutions

Just another repo for solution of the book "Automating boring stuff with Python"
Python
3
star
19

Pandas-NumPy-101

Everything about Pandas, NumPy you wanted to know
Jupyter Notebook
3
star
20

avidLearnerInProgress.github.io

Updated personal portfolio
CSS
3
star
21

CTCI-solutions

C++ and Python Solutions from the book "Cracking the coding interviews"
C++
3
star
22

mit-6.006

Notes for the course => Introduction to Algorithms MIT 6.006
C++
3
star
23

url-shortener-api

URL Shortener written in python which shortens any given url using few shortener api's like goo.gl, bit.ly, tinyurl and is.gd
Python
3
star
24

markdown-editor

Markdown editor written in NodeJS
JavaScript
3
star
25

docker-devops-test

CI/CD test
JavaScript
2
star
26

cpp-projects

Mini-projects for exploring modern CPP
C++
2
star
27

cf-octo-journey

Solutions to problems on codeforces.com
C++
2
star
28

AlgorithmicToolbox-UCSD

Coursework solutions to UCSD DSA specialization
C++
2
star
29

project_euler_hackerrank

Solutions to Project Euler on Hackerrank
C++
2
star
30

ml-stanford

Exercise solutions to Stanford ML course
MATLAB
2
star
31

notes-app

Minimal Command Line Notes Application written in Node.js
JavaScript
2
star
32

pomodoro-clock

Pomodoro Timer built using Javascript
JavaScript
2
star
33

multilabel-classification-yeast-data

Implementing multi-label classification algorithms from scratch in Python
Jupyter Notebook
2
star
34

node-contacts-app

Minimal nodejs application used to store user contacts
JavaScript
2
star
35

DataStructures-UCSD

Coursework solutions to UCSD DSA Specialization
C++
2
star
36

Weather-app

Minimal weather app written using javascript to get weather details of your location
JavaScript
2
star
37

malloc-free-implementation

malloc() and free() implementation in C
C
2
star
38

freeCodeCampProjects

Projects from freecodecamp
HTML
2
star
39

amazon-apparel-recommendation

Recommendation Engine
Python
2
star
40

plotly-flask

Flask coupled with plotlyjs to render barchart on webpage
Python
1
star
41

OpenCV-practice

Simple OpenCV programs
Python
1
star
42

text_analytics_101

Coursework solutions for the course COMP47600 - Text Analytics
Jupyter Notebook
1
star
43

data-visualisation-using-vegalite

Coursework solutions
HTML
1
star
44

MaterialDesignCaclulator

Just another javascript calculator inspired by material design
HTML
1
star
45

cui

progress tracker for cui
C++
1
star
46

PyCon-snippets

PyCon Talks code snippets
Python
1
star
47

randomQuoteGenerator

Random Quote Generator written in javascript
JavaScript
1
star
48

NCT_Ireland_analysis

Data analysis and visualisations for National Car Test Ireland
HTML
1
star
49

minimal-TodoList

Just another javascript TodoList with material design theme
CSS
1
star
50

dl-nse

Coursework assignments
Jupyter Notebook
1
star
51

node-weather-app

Minimal Command Line Weather Application written in Node.js
JavaScript
1
star
52

keras_basic

Keras
Python
1
star
53

data-structures-and-algorithms-nanodegree-udacity

Nanodegree solutions for the udacity course
Jupyter Notebook
1
star
54

todo-notes-api

Minimal todo notes api built using Node.js and Mongodb
JavaScript
1
star
55

drowsiness-detection

Python
1
star
56

node-web-server

Simple web server built using node.js
JavaScript
1
star
57

twitch-status-viewer

Javascript app to get status of channels on twitch.tv
JavaScript
1
star
58

TicTacToeAI

Simple Tic-Tac-Toe simulation with automated opposite player control.
JavaScript
1
star
59

shakespeare-poetry-generation-lstm

Shakespeare poetry generation using LSTM's
Jupyter Notebook
1
star