91
GitHub - avidLearnerInProgress/pyCAIR: Content aware image resizing
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:
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.
- Parameters:
- 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:
- Implement Object Oriented paradigms
- Optimize code: Many operations are bruteforce, if there are more better optimized methods; I would love to implement them
- Implement multithreading wherever possible to improve the computation speed.
In Action:
Screenshots:
Results for Image 1:
Original Image Grayscale Energy Map Color Map Winter Color Map Hot Seams for Columns Columns Cropped Seams for Rows Rows CroppedResults for Image 2:
Original Image Grayscale Energy Map Color Map Winter Color Map Hot Seams for Columns Columns Cropped Seams for Rows Rows CroppedLicense:
This software is licensed under the GNU General Public License v3.0 license
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK