avidLearnerInProgress / Pycair

Licence: gpl-3.0
Content aware image resizing

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pycair

Computer Vision Guide
📖 This guide is to help you understand the basics of the computerized image and develop computer vision projects with OpenCV. Includes Python, Java, JavaScript, C# and C++ examples.
Stars: ✭ 244 (-42.59%)
Mutual labels:  opencv, image-processing
Opencv Python Blueprints
M. Beyeler (2015). OpenCV with Python Blueprints: Design and develop advanced computer vision projects using OpenCV with Python, Packt Publishing Ltd., ISBN 978-178528269-0.
Stars: ✭ 262 (-38.35%)
Mutual labels:  opencv, image-processing
Buildopencvtx2
Build and install OpenCV for the NVIDIA Jetson TX2
Stars: ✭ 249 (-41.41%)
Mutual labels:  opencv, image-processing
Marvel
Marvel - Face Recognition With Android & OpenCV
Stars: ✭ 199 (-53.18%)
Mutual labels:  opencv, image-processing
Opencvsharp
OpenCV wrapper for .NET
Stars: ✭ 3,598 (+746.59%)
Mutual labels:  opencv, image-processing
Superpixels Revisited
Library containing 7 state-of-the-art superpixel algorithms with a total of 9 implementations used for evaluation purposes in [1] utilizing an extended version of the Berkeley Segmentation Benchmark.
Stars: ✭ 222 (-47.76%)
Mutual labels:  opencv, image-processing
Ai Job Notes
AI算法岗求职攻略(涵盖准备攻略、刷题指南、内推和AI公司清单等资料)
Stars: ✭ 3,191 (+650.82%)
Mutual labels:  opencv, image-processing
Scene Text Recognition
Scene text detection and recognition based on Extremal Region(ER)
Stars: ✭ 146 (-65.65%)
Mutual labels:  opencv, image-processing
Harvesters
🌈 Friendly Image Acquisition Library for Computer Vision People
Stars: ✭ 274 (-35.53%)
Mutual labels:  opencv, image-processing
Opencv Androidsamples
OpenCv samples for Android from OpenCV SDK using Android Studio and Gradle System
Stars: ✭ 278 (-34.59%)
Mutual labels:  opencv, image-processing
Omrchecker
Grade exams fast and accurately using a scanner 🖨 or your phone 🤳.
Stars: ✭ 189 (-55.53%)
Mutual labels:  opencv, image-processing
Pythonsift
A clean and concise Python implementation of SIFT (Scale-Invariant Feature Transform)
Stars: ✭ 374 (-12%)
Mutual labels:  opencv, image-processing
Opencv Python Tutorial
📖 OpenCV-Python image processing tutorial for beginners
Stars: ✭ 2,425 (+470.59%)
Mutual labels:  opencv, image-processing
Thug Memes
Command line Thug Meme generator written in Python
Stars: ✭ 224 (-47.29%)
Mutual labels:  opencv, image-processing
Invisibility cloak
This is a fun application of image processing which enables you to experience the magic of an invisibility cloak. Let's make our childhood fantasy of using an invisibility cloak come true.
Stars: ✭ 176 (-58.59%)
Mutual labels:  opencv, image-processing
Opencv
Open Source Computer Vision Library
Stars: ✭ 58,652 (+13700.47%)
Mutual labels:  opencv, image-processing
Color Tracker
Color tracking with OpenCV
Stars: ✭ 128 (-69.88%)
Mutual labels:  opencv, image-processing
Haskell Opencv
Haskell binding to OpenCV-3.x
Stars: ✭ 145 (-65.88%)
Mutual labels:  opencv, image-processing
Androiddocumentscanner
This library helps to scan a document like CamScanner.
Stars: ✭ 264 (-37.88%)
Mutual labels:  opencv, image-processing
Curvaturefilter
Curvature Filters are efficient solvers for Variational Models
Stars: ✭ 291 (-31.53%)
Mutual labels:  opencv, image-processing

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

  • [x] Implement Seam Algorithm
  • [x] Generate energy maps and color maps for image
  • [x] Display Vertical Seams
  • [x] Display Horizontal Seams
  • [x] Crop Columns
  • [x] Crop Rows
  • [x] Use argparse for Command Line Application
  • [x] Store subsamples in different directories for crop and seam respectively
  • [x] Generate video/gif from sub-samples
  • [x] Provide a better Readme
  • [x] Provide examples for usage
  • [x] Add badges
  • [x] Provide better project description on PyPI
  • [x] 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

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