Package: pyCAIR
pyCAIR is a content-aware image resizing(CAIR)librarybased onSeam Carving for Content-Aware Image Resizingpaper.Table of ContentsHow CAIR worksUnderstanding the research paperProject structure and explanationInstallationUsageDemoScreenshotsTodoHow does it workAn 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.DP MatrixBacktracking with minimum energyIntutive explanation of research paperProject structure and explanationDirectory structure:pyCAIR(root directory)| - images/| - results /| - sequences/ (zipped in repository)| - videos/| -notdoneyet.py| -imgtovideos.py| -opencv_generators.py| -seam_carve.py| -helpers.pyFile:notdoneyet.pyuser_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 ImageGenerate Sequences: Generate intermediate sequences to form a video after all the operations are performed.File:imgtovideos.pygenerateVideo()- pass each image path tovid()for video generation.**vid() **- writes each input image to video buffer for creating a complete video.File:opencv_generators.pygenerateEnergyMap()- 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.pygetEnergy()- 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 tocropByColumnfunction.File:helpers.pywriteImage()- stores the images in results directory.writeImageG()- stores intermediate generated sequence of images in sequences directory.createFolder() -self explanatorygetFileExtension() -self explanatoryOther 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.InstallationSimply runpip install pyCAIRDirect download optionUsage'''It runs the entire code and returns final results'''frompyCAIRimportuser_inputuser_input(alignment,scale,seam,input_image,generate_sequences)'''It generates the energy map'''frompyCAIRimportgenerateEnergyMapgenerateEnergyMap(image_name,file_extension,file_name)'''It generates color maps'''frompyCAIRimportgenerateColorMapgenerateColorMap(image_name,file_extension,file_name)'''It converts sequence of images generated to video'''frompyCAIRimportgenerateVideogenerateVideo()'''It returns all the paths where images are present for generating video'''frompyCAIRimportgetToProcessPathsgetToProcessPaths()'''It returns seams, cropped image for an image'''frompyCAIRimportcropByColumnseam_img,crop_img=cropByColumn(image,display_seams,generate,lsit,scale_c,fromRow)'''It returns seams, cropped image for an image'''frompyCAIRimportcropByRowseam_img,crop_img=cropByRow(image,display_seams,generate,lsit,scale_c)'''It returns created folder'''frompyCAIRimportcreateFolderf=createFolder(folder_name)'''It returns extension of file'''frompyCAIRimportgetFileExtensionf=getFileExtension(file_name)'''It writes image to specified folder'''frompyCAIRimportwriteImagef=writeImage(image,args)In ActionPlaylistScreenshotsResults for Image 1:Original ImageGrayscaleEnergy MapColor Map WinterColor Map HotSeams for ColumnsColumns CroppedSeams for RowsRows CroppedResults for Image 2:Original ImageGrayscaleEnergy MapColor Map WinterColor Map HotSeams for ColumnsColumns CroppedSeams for RowsRows CroppedTodoImplement Seam AlgorithmGenerate energy maps and color maps for imageDisplay Vertical SeamsDisplay Horizontal SeamsCrop ColumnsCrop RowsUse argparse for Command Line ApplicationStore subsamples in different directories for crop and seam respectivelyGenerate video/gif from sub-samplesProvide a better ReadmeProvide examples for usageGenerate unittests for each functionsAdd Continous Integration Services(Travis, Coveralls)Add badgesProvide better project description on PyPIDocumentation using SpinxIntegrate object detection using YOLOv2Identify most important object (using probability of predicted object)Invert energy values of most important objectRe-apply Seam Carve and compare resultsLicenseThis software is licensed under theGNU General Public License v3.0©Chirag Shah