ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rcode2bmp.pl
Revision: 2.4
Committed: Fri Jan 5 18:23:53 2024 UTC (3 months, 2 weeks ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.3: +5 -1 lines
Log Message:
feat(rcode2bmp): Added support for hyperspectral images

File Contents

# User Rev Content
1 greg 2.1 #!/usr/bin/perl
2 greg 2.4 # RCSid $Id: rcode2bmp.pl,v 2.3 2022/11/15 23:47:50 greg Exp $
3 greg 2.1 #
4     # Convert one or more rtpict outputs into BMP for convenient viewing
5     #
6    
7     use strict;
8     use warnings;
9    
10     my $xres=0;
11     my $yres=0;
12     my $pfilt="";
13    
14     # Get options, which must precede input maps
15     while ($#ARGV >= 0 && "$ARGV[0]" =~ /^-[a-zA-Z]/) {
16     if ("$ARGV[0]" eq '-x') {
17     shift @ARGV;
18     $xres = shift(@ARGV);
19     } elsif ("$ARGV[0]" eq '-y') {
20     shift @ARGV;
21     $yres = shift(@ARGV);
22     } else {
23     die "Bad option: $ARGV[0]\n";
24     }
25     }
26     # Set up resizing operation if requested
27     if ($xres > 0 && $yres > 0) {
28     $pfilt = "pfilt -x $xres -y $yres -pa 1 -1 -r .6";
29     }
30     # Load/convert each file
31     INPUT_MAP:
32     while ($#ARGV >= 0) {
33     if ("$ARGV[0]" =~ /\.bmp$/i) {
34     print STDERR "Skipping file '$ARGV[0]' already in BMP format\n";
35     shift @ARGV;
36     next INPUT_MAP;
37     }
38     my $format = `getinfo < '$ARGV[0]' | sed -n 's/^FORMAT= *//p'`;
39     chomp $format;
40     die "Cannot get format from $ARGV[0]\n" if ( $? || ! $format );
41     my ($dest) = ("$ARGV[0]" =~ /^([^.]+)/);
42     $dest .= ".bmp";
43     my $cmd="";
44 greg 2.3 if ("$format" =~ /^32-bit_rle_(rgb|xyz)e *$/) {
45 greg 2.1 if ($pfilt) {
46     $cmd = $pfilt . " '$ARGV[0]' | ra_bmp -e auto - '$dest'";
47     } else {
48     $cmd = "ra_bmp -e auto '$ARGV[0]' '$dest'";
49     }
50 greg 2.4 } elsif ("$format" =~ /^Radiance_spectra *$/) {
51     $cmd = "rcomb -fc -c RGB '$ARGV[0]' ";
52     $cmd .= "| $pfilt " if ($pfilt);
53     $cmd .= "| ra_bmp -e auto - '$dest'";
54 greg 2.3 } elsif ("$format" =~ /^16-bit_encoded_depth *$/) {
55 greg 2.1 $cmd = "rcode_depth -r -ff -ho -Ho '$ARGV[0]' ";
56     $cmd .= q{| rcalc -if -of -e 'cond=9e9-$1;$1=$1' | total -if -u};
57     my $dmax=`$cmd`;
58     $dmax = 2**(int(log($dmax)/log(2))+1);
59 greg 2.2 my $unit=`getinfo < '$ARGV[0]' | sed -n 's/^REFDEPTH= *[0-9.]*[^a-zA-Z]*//p'`;
60 greg 2.1 chomp $unit;
61     $unit="Depth" if ( ! $unit );
62     $cmd = "rcode_depth -r -ff '$ARGV[0]' | pvalue -r -df -b ";
63     $cmd .= "| $pfilt " if ($pfilt);
64     $cmd .= "| falsecolor -l '$unit' -m 1 -s $dmax | ra_bmp - '$dest'";
65 greg 2.3 } elsif ("$format" =~ /^[1-9][0-9]*-bit_indexed_name *$/) {
66 greg 2.1 $cmd = "rcode_ident -r -n '$ARGV[0]' " .
67     "| getinfo +d -c rcalc -e 'cc(x):(.1+.8*rand(x))^2' " .
68     q{-e '$1=cc(.398*$1-11.2);$2=cc(-1.152*$1+41.7);$3=cc(8.571*$1-8.15)' } .
69     "| pvalue -r -d ";
70     $cmd .= "| $pfilt " if ($pfilt);
71     $cmd .= "| ra_bmp - '$dest'";
72 greg 2.3 } elsif ("$format" =~ /^32-bit_encoded_normal *$/) {
73 greg 2.1 $cmd = "rcode_norm -r -ff '$ARGV[0]' | getinfo +d -c " .
74     "rcalc -if3 -of -e `vwright v < '$ARGV[0]'` " .
75     q{-e 'dot(vx,vy,vz)=vx*$1+vy*$2+vz*$3' } .
76     "-e 'h=dot(vhx,vhy,vhz)' " .
77     "-e 'v=dot(vvx,vvy,vvz)' " .
78     "-e 'n=-dot(vdx,vdy,vdz)' " .
79     "-f hsv_rgb.cal -e 'hue=mod(180/PI*atan2(v,h),360)' " .
80     "-e 'sat=sqrt(h*h+v*v)' -e 'val=if(n,1,1+n)' " .
81     q{-e '$1=R(hue,sat,val);$2=G(hue,sat,val);$3=B(hue,sat,val)' } .
82     "| pvalue -r -df ";
83     $cmd .= "| $pfilt " if ($pfilt);
84     $cmd .= "| ra_bmp - '$dest'";
85     }
86     if ($cmd) {
87     system $cmd;
88     die "Cannot convert $ARGV[0]\n" if ( $? );
89     print "Converted $ARGV[0] to $dest\n";
90     } else {
91     print STDERR "Skipping unsupported format '$format' for input '$ARGV[0]'\n";
92     }
93     shift @ARGV;
94     }
95     # EOF