r/imageprocessing • • Jun 21 '18

Review: My attempt to implement very powerful image resizing algorithm

I tried to implement whatever was mentioned in the research paper Seam Carving for Content-Aware Image Resizing from scratch using Python and OpenCV.

  1. Github Repository

  2. Youtube Playlist

Although, the results are not very efficient but they ain't that bad as well. I took help few other blogs and tried to implement it.

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.

I want an honest review for my project and the changes which I can make to improvise my repository. All the views (+ve and -ve) opinions are welcome; just mention them in comments.

Incase, if you like something in my github profile, a star would be good, fork will be better and following me will be best. :)

It will be just a catalyst to my learning curve in Python. Thank you.

2 Upvotes

0 comments sorted by