Skip to content

Instantly share code, notes, and snippets.

@pceres
Created March 26, 2011 12:29
Show Gist options
  • Select an option

  • Save pceres/888239 to your computer and use it in GitHub Desktop.

Select an option

Save pceres/888239 to your computer and use it in GitHub Desktop.

Revisions

  1. pceres revised this gist Apr 3, 2011. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions blur_detector
    Original file line number Diff line number Diff line change
    @@ -19,9 +19,8 @@ logfile=report.txt # logfile with the list of all photos sorted by
    logfile_full=report_unsorted.txt # logfile with the list of all photos not sorted
    temp_folder=/tmp # temporary folder
    output_folder=blurry_folder # folder into which the most blurred photos are copied
    num_output_images=10 # number of most blurred images to be copied into output folder
    perc_output_images=20 # [%] percentage of most blurred images to be copied into output folder

    # num_output_images=`ls -Al /home/ceres/Desktop/work/test/*.JPG | wc -l` && echo $num_files*0.2 | bc | gawk '{printf("%d\n",int($1)+1)}'


    #
    @@ -47,23 +46,26 @@ if [ -d $input ]; then
    # blur_detector <folder_with_images>
    #


    echo "batch blur estimator..."

    touch $logfile_full
    rm $logfile_full
    find $input -name "*.$image_ext" -exec blur_detector {} >> $logfile_full \;


    # sort by blur index (from worst to best)
    cat $logfile_full | sort -d -k 8.2 > $logfile


    echo "copying blurryed photos inside output folder..."

    # copy blurred images to output folder
    num_files=`cat $logfile | wc -l` # number of image files found
    num_output_images=`echo $num_files*$perc_output_images/100.0 | bc | gawk '{printf("%d\n",int($1)+1)}'` # take a percentage

    echo "copying $num_output_images (out of $num_files) blurriest photos into output folder..."

    mkdir $output_folder
    head $logfile -n $num_output_images | gawk '{n=split($1,a,"/");filename=sprintf("%03d_%s", FNR, a[n]);print filename; system("cp " $1 " ./'$output_folder'/" filename)}'


    else
    # report on single file
    #
  2. pceres revised this gist Mar 29, 2011. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions blur_detector
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,16 @@
    #! /bin/bash

    #
    # Author: Pasquale Ceres ([email protected])
    # License: GPL ver. 3
    #
    # Script originally developed for the
    # "San Lorenzo Martire Caposele Church Records Digitalization Project"
    #
    # http://www.facebook.com/group.php?gid=188973755117&v=photos
    # http://ars.altervista.org/PhpGedView/index.php
    #

    #
    # parameters
    #
    @@ -10,6 +21,8 @@ temp_folder=/tmp # temporary folder
    output_folder=blurry_folder # folder into which the most blurred photos are copied
    num_output_images=10 # number of most blurred images to be copied into output folder

    # num_output_images=`ls -Al /home/ceres/Desktop/work/test/*.JPG | wc -l` && echo $num_files*0.2 | bc | gawk '{printf("%d\n",int($1)+1)}'


    #
    # show usage if no params in input
  3. pceres revised this gist Mar 26, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion blur_detector
    Original file line number Diff line number Diff line change
    @@ -48,7 +48,7 @@ if [ -d $input ]; then
    echo "copying blurryed photos inside output folder..."

    mkdir $output_folder
    head $logfile -n $num_output_images | gawk '{n=split($1,a,"/");filename=sprintf("%03d_%s", FNR, a[n]);print filename; system("cp " $1 " ./'$logfile'/" filename)}'
    head $logfile -n $num_output_images | gawk '{n=split($1,a,"/");filename=sprintf("%03d_%s", FNR, a[n]);print filename; system("cp " $1 " ./'$output_folder'/" filename)}'


    else
  4. pceres revised this gist Mar 26, 2011. 1 changed file with 17 additions and 9 deletions.
    26 changes: 17 additions & 9 deletions blur_detector
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,19 @@
    #! /bin/bash

    #
    # parameters
    #
    image_ext=JPG # image extension
    logfile=report.txt # logfile with the list of all photos sorted by blur level
    logfile_full=report_unsorted.txt # logfile with the list of all photos not sorted
    temp_folder=/tmp # temporary folder
    output_folder=blurry_folder # folder into which the most blurred photos are copied
    num_output_images=10 # number of most blurred images to be copied into output folder


    #
    # show usage if no params in input
    #
    if [ ! $# == 1 ]; then
    echo "Usage:"
    echo "$0 <filename> : analyse the single image, determining its blur factor"
    @@ -8,17 +22,11 @@ if [ ! $# == 1 ]; then
    fi


    #
    # calculations
    #
    input=$1


    # extension of files to be analysed
    image_ext=JPG # image extension
    logfile=report.txt # logfile with the list of all photos sorted by blur level
    logfile_full=report_unsorted.txt # logfile with the list of all photos not sorted
    temp_folder=/tmp # temporary folder
    output_folder=blurry_folder # folder into which the most blurred photos are copied
    num_output_images=10 # number of most blurred images to be copied into output folder

    if [ -d $input ]; then
    # report on the files in the folder
    #
  5. pceres revised this gist Mar 26, 2011. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions blur_detector
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    #! /bin/bash

    # head report_step0_sorted.txt -n 368 | gawk '{n=split($1,a,"/");filename=sprintf("%03d_%s", FNR, a[n]);print filename; system("cp " $1 " ./blurry/" filename)}'

    if [ ! $# == 1 ]; then
    echo "Usage:"
    echo "$0 <filename> : analyse the single image, determining its blur factor"
  6. pceres revised this gist Mar 26, 2011. 1 changed file with 20 additions and 7 deletions.
    27 changes: 20 additions & 7 deletions blur_detector
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    #! /bin/bash

    # head report_step0_sorted.txt -n 368 | gawk '{n=split($1,a,"/");filename=sprintf("%03d_%s", FNR, a[n]);print filename; system("cp " $1 " ./blurry/" filename)}'

    if [ ! $# == 1 ]; then
    echo "Usage:"
    echo "$0 <filename> : analyse the single image, determining its blur factor"
    @@ -12,9 +14,12 @@ input=$1


    # extension of files to be analysed
    image_ext=JPG
    logfile=report.txt
    temp_folder=/tmp
    image_ext=JPG # image extension
    logfile=report.txt # logfile with the list of all photos sorted by blur level
    logfile_full=report_unsorted.txt # logfile with the list of all photos not sorted
    temp_folder=/tmp # temporary folder
    output_folder=blurry_folder # folder into which the most blurred photos are copied
    num_output_images=10 # number of most blurred images to be copied into output folder

    if [ -d $input ]; then
    # report on the files in the folder
    @@ -23,14 +28,22 @@ if [ -d $input ]; then
    # blur_detector <folder_with_images>
    #


    echo "batch blur estimator..."

    touch $logfile
    rm $logfile
    find $input -name "*.$image_ext" -exec blur_detector {} >> $logfile \;
    touch $logfile_full
    rm $logfile_full
    find $input -name "*.$image_ext" -exec blur_detector {} >> $logfile_full \;

    # sort by blur index (from worst to best)
    cat $logfile | sort -d -k 8.2
    cat $logfile_full | sort -d -k 8.2 > $logfile


    echo "copying blurryed photos inside output folder..."

    mkdir $output_folder
    head $logfile -n $num_output_images | gawk '{n=split($1,a,"/");filename=sprintf("%03d_%s", FNR, a[n]);print filename; system("cp " $1 " ./'$logfile'/" filename)}'


    else
    # report on single file
  7. pceres revised this gist Mar 26, 2011. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions blur_detector
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,13 @@
    #! /bin/bash

    if [ ! $# == 1 ]; then
    echo "Usage:"
    echo "$0 <filename> : analyse the single image, determining its blur factor"
    echo "$0 <folder> : analyse the images inside the folder"
    exit
    fi


    input=$1


  8. pceres renamed this gist Mar 26, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. pceres created this gist Mar 26, 2011.
    57 changes: 57 additions & 0 deletions blurry photos detection
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,57 @@
    #! /bin/bash

    input=$1


    # extension of files to be analysed
    image_ext=JPG
    logfile=report.txt
    temp_folder=/tmp

    if [ -d $input ]; then
    # report on the files in the folder
    #
    # usage:
    # blur_detector <folder_with_images>
    #

    echo "batch blur estimator..."

    touch $logfile
    rm $logfile
    find $input -name "*.$image_ext" -exec blur_detector {} >> $logfile \;

    # sort by blur index (from worst to best)
    cat $logfile | sort -d -k 8.2

    else
    # report on single file
    #
    # usage:
    # blur_detector <image_filename>
    #

    filename=$input

    # original size
    size0=`identify $filename | gawk '{print $3}'`

    # reduce size, just take upper part of image
    convert $filename -gravity north -crop 100x20% +repage $temp_folder/check0.jpg

    size=`identify $temp_folder/check0.jpg | gawk '{print $3}'`

    # create black image
    convert -size $size xc:black $temp_folder/black.jpg

    # create check image
    convert -noise 2 -sigmoidal-contrast 6x25% -edge 2 $temp_folder/check0.jpg $temp_folder/check.jpg

    # calculate blur factor
    blur_value=`compare -metric RMSE $temp_folder/check.jpg $temp_folder/black.jpg $temp_folder/out.jpg 2>&1`

    echo "$filename : $size0 -> $size : $blur_value"

    # remove work files
    rm $temp_folder/check0.jpg $temp_folder/check.jpg $temp_folder/black.jpg $temp_folder/out.jpg
    fi