91

GitHub - avidLearnerInProgress/pyCAIR: Content aware image resizing

 5 years ago
source link: https://github.com/avidLearnerInProgress/pyCAIR
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Readme.md

Content Aware Image Resizing


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

Notes:


Notes1

Notes2

Notes3

Notes4

Explanation:


File: notdoneyet.py

  • Implemented Seam Carving Algorithm
    • 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.
  • Generated grayscale and energy maps using OpenCV.
    • 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.
  • Crop Columns
    • 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.
  • Argparse library for 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. No output for seams is visible.
      • Input Image
      • Generate Sequences: Generate intermediate sequences to form a video after all the operations are performed.
  • Helpers
    • writeImage() - stores the images in results directory.
    • writeImageG() - stores intermediate generated sequence of images in sequences directory.
    • createFolder() - self explanatory
    • getFileExtension() - self explanatory

File: imgtovideos.py

  • Generate Video
    • _vid() - writes each input image to video buffer for creating a complete video
    • generateVideo() - pass each image path to _vid() for video generation
  • Helpers
    • getProcessPaths() - returns list of all sub-directories within a base path with certain conditions.
    • createFolder() - self explanatory

Remaining todos:

  1. Implement Object Oriented paradigms
  2. Optimize code: Many operations are bruteforce, if there are more better optimized methods; I would love to implement them
  3. Implement multithreading wherever possible to improve the computation speed.

In Action:


Video1

Video2

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

License:


This software is licensed under the GNU General Public License v3.0 license


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK