#!/bin/bash # # im_graph 'im_function' image_file # # Plot a graph the grayscale modification function given on the command line, # using gnuplot outpuing a GIF image of the adjustment made to a linear # greyscale image. # #### # # WARNING: Input arguments are NOT tested for correctness. # This script represents a security risk if used ONLINE. # I accept no responsiblity for misuse. Use at own risk. # # Anthony Thyssen, 29 June 2008 # PROGNAME=`type $0 | awk '{print $3}'` # search for executable on path PROGDIR=`dirname $PROGNAME` # extract directory of program PROGNAME=`basename $PROGNAME` # base name of program Usage() { # output the script comments as docs echo >&2 "$PROGNAME:" "$@" sed >&2 -n '/^###/q; /^#/!q; s/^#//; s/^ //; 3s/^/Usage: /; 2,$ p' \ "$PROGDIR/$PROGNAME" exit 10; } # while [ $# -gt 0 ]; do # case "$1" in # --help|--doc*) Usage ;; # Documentation # -l) line=true ;; # -t) shift; title=$1 ;; # --) shift; break ;; # end of user options # -*) Usage "Unknown option \"$1\"" ;; # *) break ;; # end of user options # esac # shift # next option # done [ $# -eq 0 ] && Usage "Missing im_function" [ $# -eq 1 ] && Usage "Missing output filename" [ $# -gt 2 ] && Usage "Too many arguments" im_func=$1 output=$2 #im_func='-sigmoidal-contrast 8x50%' #output=x: format=png size=160 scale=4 # we want the graph to be 120x120 #format=svg size=170 scale=.5 # 3/4 for png but svg is trial_n_error # --------------------------------------------- # Get the background color to use... [ -f ./generate_options ] && source ./generate_options [ -f ../generate_options ] && source ../generate_options [ -f ../../generate_options ] && source ../../generate_options [ "$page_bg_color" ] || page_bg_color=LightSteelBlue # Gnuplot of a Level function #exec 2>/dev/null # just ignore the SVG error output ( echo "set terminal $format size $size,$size" echo 'unset key' echo 'set format ""' echo 'set size square' echo "set ytics ( 0.25, 0.5, 0.75 ) scale $scale" echo "set xtics ( 30, 60, 90 ) scale $scale" echo -n 'plot [0:119][0:1] "-" binary format="%ushort" endian=big' echo ' array=120 using ($1/65535) with lines' convert -size 1x120 gradient: -rotate 90 $im_func \ -depth 16 -endian MSB gray:- ) | gnuplot | \ convert -background $page_bg_color -bordercolor $page_bg_color \ label:"0 ½ 1" \ -resize 120x -unsharp 0x.5 -write mpr:label +delete \ -size 5x118 gradient: +size -rotate 90 -write mpr:gradient \ $im_func \ mpr:gradient +swap \ -size 118x1 xc:black \( +clone \) -insert 1 -append \ -size 1x12 xc:black \( +clone \) -insert 0 +append \ \( +size -background white - -trim +repage \) +swap -append \ \( mpr:label \) -append \ \( mpr:label -rotate -90 \) +swap -background $page_bg_color +append \ -gravity NorthEast -splice 2x2 $output # old label generator #-size 500x -fill black -font ArialB \ #label:"0 ½ 1" \ #-fuzz 20% -trim +repage -border 0x2 \ [ -f $output ] && chmod 644 $output