#!/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=show: # format output, gnuplot image size, and scaling for tic marks format=png size=160 scale=4 # we want the graph to be 120x120 #format=png size=120 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 'set size square' #echo "set bmargin 0.0" # Magins are normally calcualted basied #echo "set tmargin 1.0" # on tics, this removes them #echo "set lmargin 0.0" # I can't seem to remove margins completely #echo "set rmargin 1.0" echo "set xtics ( 30, 60, 90 ) scale $scale" echo "set ytics ( 0.25, 0.5, 0.75 ) scale $scale" echo 'unset key' # remove function/data plot key echo 'set format ""' # remove tic mark labeling #echo 'unset xlabel' #echo 'unset ylabel' #echo 'unset title' #echo 'unset label' echo 'set xrange [0:119]' echo 'set yrange [0:1]' echo -n 'plot "-" 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 - -write info: show:; exit # DEBUGGING 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 \ -bordercolor black -border 1x1 -chop 0x1+0+0 \ \( +size -background white - -trim +repage \) +insert -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"