bin/falsecolor.pl
changeset 75 e02e199c8c71
parent 34 b32315c3402e
child 77 9b1ffdf784be
equal deleted inserted replaced
74:196d637b14b5 75:e02e199c8c71
     1 #!/usr/bin/perl -w
     1 #!/usr/bin/perl -w
     2 # RCSid $Id: falsecolor.pl,v 2.4 2011/03/23 21:57:11 greg Exp $
     2 # RCSid $Id: falsecolor.pl,v 2.9 2013/04/04 02:59:20 greg Exp $
     3 
     3 
     4 ######################################################################
     4 use warnings;
     5 #
       
     6 # Please don't tinker with falsecolor.pl
       
     7 # This is an old version. The most recent version is in Radiance HEAD.
       
     8 #
       
     9 # Axel, Dec 2011
       
    10 #
       
    11 ######################################################################
       
    12 
       
    13 use strict;
     5 use strict;
    14 use File::Temp qw/ tempdir /;
     6 use File::Temp qw/ tempdir /;
    15 use POSIX qw/ floor /;
     7 use POSIX qw/ floor /;
    16 
     8 
    17 my $mult = 179.0;    # Multiplier. Default W/sr/m2 -> cd/m2
     9 my @palettes = ('def', 'spec', 'pm3d', 'hot', 'eco');
    18 my $label = 'cd/m2';    # Units shown in legend
    10 
    19 my $scale = 1000;    # Top of the scale
    11 my $mult = 179.0;              # Multiplier. Default W/sr/m2 -> cd/m2
    20 my $decades = 0;    # Default is linear mapping
    12 my $label = 'cd/m2';           # Units shown in legend
    21 my $redv = 'def_red(v)';    # Mapping function for R,G,B
    13 my $scale = 1000;              # Top of the scale
    22 my $grnv = 'def_grn(v)';
    14 my $decades = 0;               # Default is linear mapping
    23 my $bluv = 'def_blu(v)';
    15 my $pal = 'def';               # Palette
    24 my $ndivs = 8;    # Number of lines in legend
    16 my $redv = "${pal}_red(v)";    # Mapping functions for R,G,B
       
    17 my $grnv = "${pal}_grn(v)";
       
    18 my $bluv = "${pal}_blu(v)";
       
    19 my $ndivs = 8;                 # Number of lines in legend
    25 my $picture = '-';
    20 my $picture = '-';
    26 my $cpict = '';
    21 my $cpict = '';
    27 my $legwidth = 100;   # Legend width and height
    22 my $legwidth = 100;            # Legend width and height
    28 my $legheight = 200;
    23 my $legheight = 200;
    29 my $docont = '';    # Contours
    24 my $docont = '';               # Contours: -cl and -cb
    30 my $loff = 0;    # Offset to align with values
    25 my $doposter = 0;              # Posterization: -cp
    31 my $doextrem = 0;    # Don't mark extrema
    26 my $loff = 0;                  # Offset to align with values
       
    27 my $doextrem = 0;              # Don't mark extrema
    32 my $needfile = 0;
    28 my $needfile = 0;
       
    29 my $showpal = 0;               # Show availabel colour palettes
    33 
    30 
    34 while ($#ARGV >= 0) {
    31 while ($#ARGV >= 0) {
    35 	# Options with qualifiers
    32     $_ = shift;
    36     if ("$ARGV[0]" eq '-lw') {    # Legend width
    33     # Options with qualifiers
    37         $legwidth = $ARGV[1];
    34     if (m/-lw/) {              # Legend width
    38         shift @ARGV;
    35         $legwidth = shift;
    39     } elsif ("$ARGV[0]" eq '-lh') {    # Legend height
    36     } elsif (m/-lh/) {         # Legend height
    40         $legheight = $ARGV[1];
    37         $legheight = shift;
    41         shift @ARGV;
    38     } elsif (m/-m/) {          # Multiplier
    42     } elsif ("$ARGV[0]" eq '-m') {    # Multiplier
    39         $mult = shift;
    43         $mult = $ARGV[1];
    40     } elsif (m/-spec/) {
    44         shift @ARGV;
    41         die("depricated option '-spec'. Please use '-pal spec' instead.");
    45     } elsif ("$ARGV[0]" eq '-s') {    # Scale
    42     } elsif (m/-s/) {          # Scale
    46         $scale = $ARGV[1];
    43         $scale = shift;
    47         shift @ARGV;
       
    48         if ($scale =~ m/[aA].*/) {
    44         if ($scale =~ m/[aA].*/) {
    49             $needfile = 1;
    45             $needfile = 1;
    50         }
    46         }
    51     } elsif ("$ARGV[0]" eq '-l') {    # Label
    47     } elsif (m/-l$/) {         # Label
    52         $label = $ARGV[1];
    48         $label = shift;
    53         shift @ARGV;
    49     } elsif (m/-log/) {        # Logarithmic mapping
    54     } elsif ("$ARGV[0]" eq '-log') {    # Logarithmic mapping
    50         $decades = shift;
    55         $decades = $ARGV[1];
    51     } elsif (m/-r/) {          # Custom palette functions for R,G,B
    56         shift @ARGV;
    52         $redv = shift;
    57     } elsif ("$ARGV[0]" eq '-r') {
    53     } elsif (m/-g/) {
    58         $redv = $ARGV[1];
    54         $grnv = shift;
    59         shift @ARGV;
    55     } elsif (m/-b/) {
    60     } elsif ("$ARGV[0]" eq '-g') {
    56         $bluv = shift;
    61         $grnv = $ARGV[1];
    57     } elsif (m/-pal$/) {        # Color palette
    62         shift @ARGV;
    58         $pal = shift;
    63     } elsif ("$ARGV[0]" eq '-b') {
    59         if (! grep $_ eq $pal, @palettes) {
    64         $bluv = $ARGV[1];
    60             die("invalid palette '$pal'.\n");
    65         shift @ARGV;
    61         }
    66     } elsif ("$ARGV[0]" eq '-pal') {
    62         $redv = "${pal}_red(v)";
    67 	$redv = "$ARGV[1]_red(v)";
    63         $grnv = "${pal}_grn(v)";
    68 	$grnv = "$ARGV[1]_grn(v)";
    64         $bluv = "${pal}_blu(v)";
    69 	$bluv = "$ARGV[1]_blu(v)";
    65     } elsif (m/-i$/) {          # Image for intensity mapping
    70 	shift @ARGV;
    66         $picture = shift;
    71     } elsif ("$ARGV[0]" eq '-i') {    # Image for intensity mapping
    67     } elsif (m/-p$/) {         # Image for background
    72         $picture = $ARGV[1];
    68         $cpict = shift;
    73         shift @ARGV;
    69     } elsif (m/-ip/ || m/-pi/) {
    74     } elsif ("$ARGV[0]" eq '-p') {    # Image for background
    70         $picture = shift;
    75         $cpict = $ARGV[1];
    71         $cpict = $picture;
    76         shift @ARGV;
    72     } elsif (m/-n/) {          # Number of contour lines
    77     } elsif ("$ARGV[0]" eq '-ip' || "$ARGV[0]" eq '-pi') {
    73         $ndivs = shift;
    78         $picture = $ARGV[1];
    74 
    79         $cpict = $ARGV[1];
    75     # Switches
    80         shift @ARGV;
    76     } elsif (m/-cl/) {         # Contour lines
    81     } elsif ("$ARGV[0]" eq '-n') {    # Number of contour lines
       
    82         $ndivs = $ARGV[1];
       
    83         shift @ARGV;
       
    84 
       
    85 	# Switches
       
    86     } elsif ("$ARGV[0]" eq '-cl') {    # Contour lines
       
    87         $docont = 'a';
    77         $docont = 'a';
    88         $loff = 0.48;
    78         $loff = 0.48;
    89     } elsif ("$ARGV[0]" eq '-cb') {    # Contour bands
    79     } elsif (m/-cb/) {         # Contour bands
    90         $docont = 'b';
    80         $docont = 'b';
    91         $loff = 0.52;
    81         $loff = 0.52;
    92     } elsif ("$ARGV[0]" eq '-e') {
    82     } elsif (m/-cp/) {              # Posterize
       
    83         $doposter = 1;
       
    84     } elsif (m/-palettes/) {        # Show all available palettes
       
    85         $scale   = 45824;           # 256 * 179
       
    86         $showpal = 1;
       
    87     } elsif (m/-e/) {
    93         $doextrem = 1;
    88         $doextrem = 1;
    94         $needfile = 1;
    89         $needfile = 1;
    95 
    90 
    96 	# Oops! Illegal option
    91     # Oops! Illegal option
    97     } else {
    92     } else {
    98         die("bad option \"$ARGV[0]\"\n");
    93         die("bad option \"$_\"\n");
    99     }
    94     }
   100     shift @ARGV;
       
   101 }
    95 }
   102 
    96 
   103 # Temporary directory. Will be removed upon successful program exit.
    97 # Temporary directory. Will be removed upon successful program exit.
   104 my $td = tempdir( CLEANUP => 1 );
    98 my $td = tempdir( CLEANUP => 1 );
   105 
    99 
   106 if ($needfile == 1 && $picture eq '-') {
   100 if ($needfile == 1 && $picture eq '-') {
   107 	# Pretend that $td/stdin.rad is the actual filename.
   101     # Pretend that $td/stdin.rad is the actual filename.
   108     $picture = "$td/stdin.hdr";
   102     $picture = "$td/stdin.hdr";
   109     open(FHpic, ">$picture") or
   103     open(FHpic, ">$picture") or
   110             die("Unable to write to file $picture\n");
   104             die("Unable to write to file $picture\n");
   111 	# Input is from STDIN: Capture to file.
   105     # Input is from STDIN: Capture to file.
   112 	while (<>) {
   106     while (<>) {
   113 		print FHpic;
   107         print FHpic;
   114 	}
   108     }
   115     close(FHpic);
   109     close(FHpic);
   116 
   110 
   117 	if ($cpict eq '-') {
   111     if ($cpict eq '-') {
   118 		$cpict =  "$td/stdin.hdr";
   112         $cpict = "$td/stdin.hdr";
   119 	}
   113     }
   120 }
   114 }
   121 
   115 
   122 # Find a good scale for auto mode.
   116 # Find a good scale for auto mode.
   123 if ($scale =~ m/[aA].*/) {
   117 if ($scale =~ m/[aA].*/) {
   124 	my @histo = split(/\s/, `phisto $picture| tail -2`);
   118     my @histo = split(/\s/, `phisto $picture| tail -2`);
   125 	# e.g. $ phisto tests/richmond.hdr| tail -2
   119     # e.g. $ phisto tests/richmond.hdr| tail -2
   126 	# 3.91267	14
   120     # 3.91267	14
   127 	# 3.94282	6
   121     # 3.94282	6
   128 	my $LogLmax = $histo[0];
   122     my $LogLmax = $histo[0];
   129     $scale = $mult / 179 * 10**$LogLmax;
   123     $scale = $mult / 179 * 10**$LogLmax;
   130 }
   124 }
   131 
   125 
   132 my $pc0 = "$td/pc0.cal";
   126 my $pc0 = "$td/pc0.cal";
   133 open(FHpc0, ">$pc0");
   127 open(FHpc0, ">$pc0");
   149 spec_red(x) = 1.6*x - .6;
   143 spec_red(x) = 1.6*x - .6;
   150 spec_grn(x) = if(x-.375, 1.6-1.6*x, 8/3*x);
   144 spec_grn(x) = if(x-.375, 1.6-1.6*x, 8/3*x);
   151 spec_blu(x) = 1 - 8/3*x;
   145 spec_blu(x) = 1 - 8/3*x;
   152 
   146 
   153 pm3d_red(x) = sqrt(x) ^ gamma;
   147 pm3d_red(x) = sqrt(x) ^ gamma;
   154 pm3d_grn(x) = x*x*x ^ gamma;
   148 pm3d_grn(x) = (x*x*x) ^ gamma;
   155 pm3d_blu(x) = clip(sin(2*PI*x)) ^ gamma;
   149 pm3d_blu(x) = clip(sin(2*PI*clip(x))) ^ gamma;
   156 
   150 
   157 hot_red(x) = clip(3*x) ^ gamma;
   151 hot_red(x) = clip(3*x) ^ gamma;
   158 hot_grn(x) = clip(3*x - 1) ^ gamma;
   152 hot_grn(x) = clip(3*x - 1) ^ gamma;
   159 hot_blu(x) = clip(3*x - 2) ^ gamma;
   153 hot_blu(x) = clip(3*x - 2) ^ gamma;
       
   154 
       
   155 eco_red(x) = clip(2*x) ^ gamma;
       
   156 eco_grn(x) = clip(2*(x-0.5)) ^ gamma;
       
   157 eco_blu(x) = clip(2*(0.5-x)) ^ gamma;
   160 
   158 
   161 interp_arr2(i,x,f):(i+1-x)*f(i)+(x-i)*f(i+1);
   159 interp_arr2(i,x,f):(i+1-x)*f(i)+(x-i)*f(i+1);
   162 interp_arr(x,f):if(x-1,if(f(0)-x,interp_arr2(floor(x),x,f),f(f(0))),f(1));
   160 interp_arr(x,f):if(x-1,if(f(0)-x,interp_arr2(floor(x),x,f),f(f(0))),f(1));
   163 
   161 
   164 def_redp(i):select(i,0.18848,0.05468174,
   162 def_redp(i):select(i,0.18848,0.05468174,
   193 
   191 
   194 ro = if(in,clip($redv),ra);
   192 ro = if(in,clip($redv),ra);
   195 go = if(in,clip($grnv),ga);
   193 go = if(in,clip($grnv),ga);
   196 bo = if(in,clip($bluv),ba);
   194 bo = if(in,clip($bluv),ba);
   197 EndOfPC0
   195 EndOfPC0
       
   196 close FHpc0;
   198 
   197 
   199 my $pc1 = "$td/pc1.cal";
   198 my $pc1 = "$td/pc1.cal";
   200 open(FHpc1, ">$pc1");
   199 open(FHpc1, ">$pc1");
   201 print FHpc1 <<EndOfPC1;
   200 print FHpc1 <<EndOfPC1;
   202 norm : mult/scale/le(1);
   201 norm : mult/scale/le(1);
   212 
   211 
   213 ra = ri(nfiles);
   212 ra = ri(nfiles);
   214 ga = gi(nfiles);
   213 ga = gi(nfiles);
   215 ba = bi(nfiles);
   214 ba = bi(nfiles);
   216 EndOfPC1
   215 EndOfPC1
       
   216 close FHpc1;
   217 
   217 
   218 my $pc0args = "-f $pc0";
   218 my $pc0args = "-f $pc0";
   219 my $pc1args = "-f $pc1";
   219 my $pc1args = "-f $pc1";
   220 
   220 
   221 # Contour lines or bands
   221 if ($showpal == 1) {
       
   222     my $pc = "pcompos -a 1";
       
   223     foreach my $pal (@palettes) {
       
   224         my $fcimg = "$td/$pal.hdr";
       
   225         my $lbimg = "$td/${pal}_label.hdr";
       
   226         system "psign -cb 0 0 0 -cf 1 1 1 -h 20 $pal > $lbimg";
       
   227 
       
   228         my $cmd = qq[pcomb $pc0args -e "v=x/256"];
       
   229         $cmd .= qq[ -e "ro=clip(${pal}_red(v));go=clip(${pal}_grn(v));bo=clip(${pal}_blu(v))"];
       
   230         $cmd .= qq[ -x 256 -y 30 > $fcimg];
       
   231         system "$cmd";
       
   232         $pc .= " $fcimg $lbimg";
       
   233     }
       
   234     system "$pc";
       
   235     exit 0;
       
   236 }
       
   237 
       
   238 # Contours
   222 if ($docont ne '') {
   239 if ($docont ne '') {
   223     $pc0args .= " -e 'in=iscont$docont'";
   240     # -cl -> $docont = a
       
   241     # -cb -> $docont = b
       
   242     $pc0args .= qq[ -e "in=iscont$docont"];
       
   243 } elsif ($doposter == 1) {
       
   244     # -cp -> $doposter = 1
       
   245     $pc0args .= qq[ -e "ro=${pal}_red(seg(v));go=${pal}_grn(seg(v));bo=${pal}_blu(seg(v))"];
       
   246     $pc0args .= q[ -e "seg(x)=(floor(v*ndivs)+.5)/ndivs"];
   224 }
   247 }
   225 
   248 
   226 if ($cpict eq '') {
   249 if ($cpict eq '') {
   227     $pc1args .= " -e 'ra=0;ga=0;ba=0'";
   250     $pc1args .= qq[ -e "ra=0;ga=0;ba=0"];
   228 } elsif ($cpict eq $picture) {
   251 } elsif ($cpict eq $picture) {
   229     $cpict = '';
   252     $cpict = '';
   230 }
   253 }
   231 
   254 
   232 # Logarithmic mapping
   255 # Logarithmic mapping
   233 if ($decades > 0) {
   256 if ($decades > 0) {
   234     $pc1args .= " -e 'map(x)=if(x-10^-$decades,log10(x)/$decades+1,0)'";
   257     $pc1args .= qq[ -e "map(x)=if(x-10^-$decades,log10(x)/$decades+1,0)"];
   235 }
   258 }
   236 
   259 
   237 # Colours in the legend
   260 # Colours in the legend
   238 my $scolpic = "$td/scol.hdr";
   261 my $scolpic = "$td/scol.hdr";
       
   262 
   239 # Labels in the legend
   263 # Labels in the legend
   240 my $slabpic = "$td/slab.hdr";
   264 my $slabpic = "$td/slab.hdr";
   241 my $cmd;
   265 my $cmd;
   242 
   266 
   243 if (($legwidth > 20) && ($legheight > 40)) {
   267 if (($legwidth > 20) && ($legheight > 40)) {
   244 	# Legend: Create the text labels
   268     # Legend: Create the text labels
   245     my $sheight = floor($legheight / $ndivs + 0.5);
   269     my $sheight = floor($legheight / $ndivs + 0.5);
   246     $legheight = $sheight * $ndivs;
   270     $legheight = $sheight * $ndivs;
   247     $loff = floor($loff * $sheight + 0.5);
   271     $loff = floor($loff * $sheight + 0.5);
   248     my $text = "$label";
   272     my $text = "$label";
   249     for (my $i=0; $i<$ndivs; $i++) {
   273     for (my $i=0; $i<$ndivs; $i++) {
   250         my $imap = ($ndivs - 0.5 - $i) / $ndivs;
   274         my $imap = ($ndivs - 0.5 - $i) / $ndivs;
   251 		my $value = $scale;
   275         my $value = $scale;
   252         if ($decades > 0) {
   276         if ($decades > 0) {
   253             $value *= 10**(($imap - 1) * $decades);
   277             $value *= 10**(($imap - 1) * $decades);
   254         } else {
   278         } else {
   255             $value *= $imap;
   279             $value *= $imap;
   256         }
   280         }
       
   281 
   257         # Have no more than 3 decimal places
   282         # Have no more than 3 decimal places
   258         $value =~ s/(\.[0-9]{3})[0-9]*/$1/;
   283         $value =~ s/(\.[0-9]{3})[0-9]*/$1/;
   259         $text .= "\n$value";
   284         $text .= "\n$value";
   260     }
   285     }
   261     $cmd = "echo '$text' | psign -s -.15 -cf 1 1 1 -cb 0 0 0";
   286     open PSIGN, "| psign -s -.15 -cf 1 1 1 -cb 0 0 0 -h $sheight > $slabpic";
   262     $cmd .= " -h $sheight > $slabpic";
   287     print PSIGN "$text\n";
   263     system $cmd;
   288     close PSIGN;
   264 
   289 
   265 	# Legend: Create the background colours
   290     # Legend: Create the background colours
   266     $cmd = "pcomb $pc0args -e 'v=(y+.5)/yres;vleft=v;vright=v'";
   291     $cmd = qq[pcomb $pc0args];
   267     $cmd .= " -e 'vbelow=(y-.5)/yres;vabove=(y+1.5)/yres'";
   292     $cmd .= q[ -e "v=(y+.5)/yres;vleft=v;vright=v"];
   268     $cmd .= " -x $legwidth -y $legheight > $scolpic";
   293     $cmd .= q[ -e "vbelow=(y-.5)/yres;vabove=(y+1.5)/yres"];
       
   294     $cmd .= qq[ -x $legwidth -y $legheight > $scolpic];
   269     system $cmd;
   295     system $cmd;
   270 } else {
   296 } else {
   271 	# Legend is too small to be legible. Don't bother doing one.
   297     # Legend is too small to be legible. Don't bother doing one.
   272     $legwidth = 0;
   298     $legwidth = 0;
   273     $legheight = 0;
   299     $legheight = 0;
   274     $loff = 0;
   300     $loff = 0;
   275 	# Create dummy colour scale and legend labels so we don't
   301 
   276 	# need to change the final command line.
   302     # Create dummy colour scale and legend labels so we don't
       
   303     # need to change the final command line.
   277     open(FHscolpic, ">$scolpic");
   304     open(FHscolpic, ">$scolpic");
   278     print FHscolpic "\n-Y 1 +X 1\naaa\n";
   305     print FHscolpic "\n-Y 1 +X 1\naaa\n";
   279     close(FHscolpic);
   306     close(FHscolpic);
   280     open(FHslabpic, ">$slabpic");
   307     open(FHslabpic, ">$slabpic");
   281     print FHslabpic "\n-Y 1 +X 1\naaa\n";
   308     print FHslabpic "\n-Y 1 +X 1\naaa\n";
   282     close(FHslabpic);
   309     close(FHslabpic);
   283 }
   310 }
   284 
   311 
   285 # Legend: Invert the text labels (for dropshadow)
   312 # Legend: Invert the text labels (for dropshadow)
   286 my $slabinvpic = "$td/slabinv.hdr";
   313 my $slabinvpic = "$td/slabinv.hdr";
   287 $cmd = "pcomb -e 'lo=1-gi(1)' $slabpic > $slabinvpic";
   314 $cmd = qq[pcomb -e "lo=1-gi(1)" $slabpic > $slabinvpic];
   288 system $cmd;
   315 system $cmd;
   289 
   316 
   290 my $loff1 = $loff - 1;
   317 my $loff1 = $loff - 1;
       
   318 
   291 # Command line without extrema
   319 # Command line without extrema
   292 $cmd = "pcomb $pc0args $pc1args $picture $cpict";
   320 $cmd = qq[pcomb $pc0args $pc1args $picture $cpict];
   293 $cmd .= "| pcompos $scolpic 0 0 +t .1 $slabinvpic 2 $loff1";
   321 $cmd .= qq[ | pcompos $scolpic 0 0 +t .1 $slabinvpic 2 $loff1];
   294 $cmd .= " -t .5 $slabpic 0 $loff - $legwidth 0";
   322 $cmd .= qq[ -t .5 $slabpic 0 $loff - $legwidth 0];
   295 
   323 
   296 if ($doextrem == 1) {
   324 if ($doextrem == 1) {
   297 	# Get min/max image luminance
   325     # Get min/max image luminance
   298     my $cmd1 = 'pextrem -o ' . $picture;
   326     my $cmd1 = 'pextrem -o ' . $picture;
   299     my $retval = `$cmd1`;
   327     my $retval = `$cmd1`;
   300     # e.g.
   328     # e.g.
   301     # x   y   r            g            b
   329     # x   y   r            g            b
   302     # 193 207 3.070068e-02 3.118896e-02 1.995850e-02
   330     # 193 207 3.070068e-02 3.118896e-02 1.995850e-02
   303     # 211 202 1.292969e+00 1.308594e+00 1.300781e+00
   331     # 211 202 1.292969e+00 1.308594e+00 1.300781e+00
   304 
   332 
   305     my @extrema = split(/\s/, $retval);
   333     my @extrema = split(/\s/, $retval);
   306     my ($lxmin, $ymin, $rmin, $gmin, $bmin, $lxmax, $ymax, $rmax, $gmax, $bmax) = @extrema;
   334     my ($lxmin, $ymin, $rmin, $gmin, $bmin, $lxmax, $ymax, $rmax, $gmax, $bmax) = @extrema;
   307 	$lxmin += $legwidth;
   335     $lxmin += $legwidth;
   308 	$lxmax += $legwidth;
   336     $lxmax += $legwidth;
   309 
   337 
   310 	# Weighted average of R,G,B
   338     # Weighted average of R,G,B
   311     my $minpos = "$lxmin $ymin";
   339     my $minpos = "$lxmin $ymin";
   312     my $minval = ($rmin * .27 + $gmin * .67 + $bmin * .06) * $mult;
   340     my $minval = ($rmin * .27 + $gmin * .67 + $bmin * .06) * $mult;
   313     $minval =~ s/(\.[0-9]{3})[0-9]*/$1/;
   341     $minval =~ s/(\.[0-9]{3})[0-9]*/$1/;
   314     my $maxpos = "$lxmax $ymax";
       
   315     my $maxval = ($rmax * .27 + $gmax * .67 + $bmax * .06) * $mult;
   342     my $maxval = ($rmax * .27 + $gmax * .67 + $bmax * .06) * $mult;
   316     $maxval =~ s/(\.[0-9]{3})[0-9]*/$1/;
   343     $maxval =~ s/(\.[0-9]{3})[0-9]*/$1/;
   317 
   344 
   318 	# Create the labels for min/max intensity
   345     # Create the labels for min/max intensity
   319     my $minvpic = "$td/minv.hdr";
   346     my $minvpic = "$td/minv.hdr";
   320     $cmd1 = "psign -s -.15 -a 2 -h 16 $minval > $minvpic";
   347     system "psign -s -.15 -a 2 -h 16 $minval > $minvpic";
   321     system $cmd1;
       
   322     my $maxvpic = "$td/maxv.hdr";
   348     my $maxvpic = "$td/maxv.hdr";
   323     $cmd1 = "psign -s -.15 -a 2 -h 16 $maxval > $maxvpic";
   349     system "psign -s -.15 -a 2 -h 16 $maxval > $maxvpic";
   324     system $cmd1;
   350 
   325 
   351     # Add extrema labels to command line
   326 	# Add extrema labels to command line
   352     $cmd .= qq[ $minvpic $minpos $maxvpic $lxmax $ymax];
   327     $cmd .= " $minvpic $minpos $maxvpic $maxpos";
       
   328 }
   353 }
   329 
   354 
   330 # Process image and combine with legend
   355 # Process image and combine with legend
   331 system "$cmd";
   356 system "$cmd";
   332 
   357