bin/phisto.pl
changeset 8 9ed02f081b72
equal deleted inserted replaced
7:f0aa5e41ede2 8:9ed02f081b72
       
     1 #!/usr/bin/perl
       
     2 #
       
     3 # Compute foveal histogram for picture set
       
     4 #
       
     5 # This is a re-write of Greg's phisto.csh with no functionality
       
     6 # added or removed.
       
     7 #
       
     8 # Axel, Oct 2010
       
     9 
       
    10 use strict;
       
    11 use warnings;
       
    12 
       
    13 use File::Temp qw/ tempdir /;
       
    14 my $td = tempdir( CLEANUP => 1 );
       
    15 
       
    16 if ($#ARGV < 0) {
       
    17 	# Input is from STDIN: Capture to file
       
    18 	open(FH, ">$td/stdin.rad");
       
    19 	while (<>) {
       
    20 		print FH;
       
    21 	}
       
    22 	close FH;
       
    23 	# Pretend stdin.rad was passed as a filename
       
    24 	@ARGV = ("$td/stdin.rad");
       
    25 }
       
    26 
       
    27 my $tf = "$td/phisto.dat";
       
    28 open(FH, ">$tf") or
       
    29 		die("$0: Unable to write to temporary file $tf\n");
       
    30 close(FH);
       
    31 
       
    32 foreach (@ARGV) {
       
    33 	system("pfilt -1 -x 128 -y 128 -p 1 $_ |pvalue -o -h -H -d -b >> $tf") == 0
       
    34 			or die("$0: Error running pfilt|pvalue on file $_\n");
       
    35 }
       
    36 
       
    37 # Get log10 of upper and lower image luminance
       
    38 my $Lmin = `total -l $tf | rcalc -e 'L=\$1*179;\$1=if(L-1e-7,log10(L)-.01,-7)'`;
       
    39 chomp($Lmin);
       
    40 my $Lmax = `total -u $tf | rcalc -e '\$1=log10(\$1*179)+.01'`;
       
    41 chomp($Lmax);
       
    42 
       
    43 # Output to STDOUT histogram data of log10(luminance)
       
    44 my $cmd = "rcalc -e 'L=\$1*179;cond=L-1e-7;\$1=log10(L)' $tf";
       
    45 $cmd .= " |histo $Lmin $Lmax 100";
       
    46 system("$cmd");
       
    47 
       
    48 #EOF