1 |
.\" RCSid "$Id: rcomb.1,v 1.7 2024/05/07 17:15:31 greg Exp $" |
2 |
.TH RCOMB 12/5/2023 RADIANCE |
3 |
.SH NAME |
4 |
rcomb - combine and convert matrices a row at a time |
5 |
.SH SYNOPSIS |
6 |
.B rcomb |
7 |
[ |
8 |
.B \-h |
9 |
][ |
10 |
.B \-w |
11 |
][ |
12 |
.B \-f[afdc] |
13 |
][ |
14 |
.B "\-n nproc" |
15 |
][ |
16 |
.B "\-f file" |
17 |
][ |
18 |
.B "\-e expr" |
19 |
][ |
20 |
.B "\-C {symbols|file}" |
21 |
][ |
22 |
.B "\-c ce .." |
23 |
][ |
24 |
.B "\-s sf .." |
25 |
] |
26 |
.B "m1 .." |
27 |
[ |
28 |
.B "\-m mcat" |
29 |
] |
30 |
.SH DESCRIPTION |
31 |
.I Rcomb |
32 |
combines inputs given on the command line, |
33 |
one matrix row or picture scanline at a time. |
34 |
By default, the result is a linear combination of |
35 |
the matrix elements or pixels transformed by |
36 |
.I \-c |
37 |
specifications and scaled by |
38 |
.I \-s |
39 |
coefficients, but an arbitrary mapping can be assigned with the |
40 |
.I \-e |
41 |
and |
42 |
.I \-f |
43 |
options, similar to the |
44 |
.I pcomb(1) |
45 |
and |
46 |
.I rcalc(1) |
47 |
commands. |
48 |
(The definitions in each |
49 |
.I \-f source |
50 |
file are read and compiled from the RADIANCE library where it is found.)\0 |
51 |
.PP |
52 |
If any |
53 |
.I \-c |
54 |
or |
55 |
.I \-s |
56 |
options follow the last input matrix, output results will be transformed |
57 |
and/or scaled accordingly. |
58 |
These operations are discussed in greater detail below. |
59 |
A single concatenation matrix may be applied after element operations |
60 |
using the |
61 |
.I \-m |
62 |
option. |
63 |
Matrix concatenation will happen before or after any trailing |
64 |
operations, depending on relative command line placement. |
65 |
.PP |
66 |
Each input file must have a header containing the following metadata: |
67 |
.sp |
68 |
.nf |
69 |
NROWS={number of rows} |
70 |
NCOLS={number of columns} |
71 |
NCOMP={number of components} |
72 |
FORMAT={ascii|float|double|32-bit_rle_rgbe|32-bit_rle_xyze|Radiance_spectra} |
73 |
.fi |
74 |
.sp |
75 |
The number of components indicates that each matrix element is actually |
76 |
composed of multiple channels, most commonly an RGB triple. |
77 |
This is essentially dividing the matrix into planes, where each component |
78 |
participates in a separate calculation. |
79 |
If an appropriate header is not present, it may be added with a call to |
80 |
.I rcollate(1). |
81 |
A matrix may be read from the standard input using a hyphen by itself ('-') |
82 |
in the appropriate place on the command line. |
83 |
Similarly, any of the inputs may be read from a command |
84 |
instead of a file by |
85 |
using quotes and a beginning exclamation point ('!'). |
86 |
.PP |
87 |
In the case of Radiance picture files, |
88 |
the number of columns is the X-dimension of the picture, and |
89 |
the number of rows is the Y-dimension. |
90 |
The picture must be in standard pixel ordering, and the zeroeth row |
91 |
is at the top with the zeroeth column on the left. |
92 |
Any exposure changes that were applied to the pictures before |
93 |
.I rcomb |
94 |
will be undone, similar to the |
95 |
.I "pcomb \-o" |
96 |
option. |
97 |
Radiance spectral pictures with more than 3 components are also supported. |
98 |
These are typically produced by |
99 |
.I rtpict(1) |
100 |
or |
101 |
.I rfluxmtx(1). |
102 |
.PP |
103 |
Before each input, the |
104 |
.I \-c |
105 |
and/or |
106 |
.I \-s |
107 |
options may be used to modify the matrix elements. |
108 |
The |
109 |
.I \-c |
110 |
option can "transform" the element values, possibly changing |
111 |
the number of components in the matrix. |
112 |
For example, a 3-component matrix can be transformed into a single-component |
113 |
matrix by using |
114 |
.I \-c |
115 |
with three coefficients. |
116 |
A four-component matrix can be turned into a two-component matrix using 8 |
117 |
coefficients, where the first four coefficients will be used to compute |
118 |
the first new component, and the second four coefficients |
119 |
yield the second new component. |
120 |
Note that the number of coefficients must be an even multiple of the number |
121 |
of original components. |
122 |
.PP |
123 |
Alternatively, a set of symbolic output components may be given to the |
124 |
.I \-c |
125 |
option, with the following definitions: |
126 |
.sp |
127 |
.nf |
128 |
R - red channel |
129 |
G - green channel |
130 |
B - blue channel |
131 |
X - CIE X channel |
132 |
Y - CIE Y channel (aka., luminance or illuminance) |
133 |
Z - CIE Z channel |
134 |
S - scotopic luminance or illuminance |
135 |
M - melanopic luminance or illuminance |
136 |
A - average component value |
137 |
.fi |
138 |
.sp |
139 |
These letters may be given in any order as a single string, and if |
140 |
.I "-c RGB" |
141 |
or |
142 |
.I "-c XYZ" |
143 |
is specified for an input picture or the |
144 |
.I "-fc" |
145 |
option is given, the output will be written as a RGBE or XYZE picture. |
146 |
Note that conversion from a float or RGBE color space applies a conversion |
147 |
of 179 lumens/watt (for CIE or melanopic output) or 412 (for scotopic output), |
148 |
and the reverse happens for conversion from XYZE input to RGB or RGBE output. |
149 |
Lower case versions of all these components are also supported, the only |
150 |
difference is that the aforementioned efficacy factors |
151 |
will be left out of the conversion. |
152 |
.PP |
153 |
If a matrix or picture file path is given to the |
154 |
.I \-c |
155 |
option, then the color space of that file will be used, instead. |
156 |
.PP |
157 |
The |
158 |
.I \-C |
159 |
option takes either a symbolic color space or an input file, and will be |
160 |
applied to all subsequent matrices that do not have their own associated |
161 |
.I \-c |
162 |
option. |
163 |
.PP |
164 |
Additionally, the |
165 |
.I \-s |
166 |
option applies the given scalar factor(s) to the elements of the matrix. |
167 |
If only one factor is provided, |
168 |
it will be used for all components. |
169 |
If multiple factors are given, their number must match the number of matrix |
170 |
components |
171 |
.I after |
172 |
application of any |
173 |
.I \-c |
174 |
option for this input matrix or picture, even if the |
175 |
.I \-s |
176 |
option appears first. |
177 |
.PP |
178 |
The number of components in all input |
179 |
matrices after applying any |
180 |
.I -c |
181 |
transform must agree. |
182 |
Similarly, the number of rows and columns of all results must match |
183 |
exactly. |
184 |
(The |
185 |
.I rcrop(1) |
186 |
utility may be used to trim inputs if necessary.)\0 |
187 |
.PP |
188 |
If the |
189 |
.I \-e |
190 |
or |
191 |
.I \-f |
192 |
options are used to define a "co" variable or "co(p)" function, |
193 |
which will be evaluated for each output |
194 |
component from the current element. |
195 |
The "co" variable defines identical operations for all components, |
196 |
whereas "co(p)" may specify different operations for each component. |
197 |
The element position is defined |
198 |
by the "r" and "c" variables, where |
199 |
.I r |
200 |
goes from 0 to "nrows" minus one, and |
201 |
.I c |
202 |
goes from 0 to "ncols" minus one. |
203 |
(Note that "nrows" may be zero if unspecified in inputs, and this |
204 |
is a unique capability of |
205 |
.I rcomb |
206 |
to handle these.)\0 |
207 |
Component p from input i is accessed with the "ci(i,p)" function, |
208 |
and the number of components is defined by the "ncomp" constant. |
209 |
If given as "ci(i)", the function returns the current component |
210 |
being evaluated by |
211 |
.I rcomb. |
212 |
A different component may be referenced using the second argument. |
213 |
For example, "ci(1,2)" accesses |
214 |
the second component from the first input. |
215 |
If the input is a picture, the the constants "R", "G", and "B" |
216 |
are conveniently defined as the channel numbers 1, 2, and 3, |
217 |
respectively. |
218 |
For color or spectral inputs, the function "wl(p)" gives the |
219 |
central wavelength for channel |
220 |
.I p |
221 |
in nanometers. |
222 |
For convenience and compatibility with |
223 |
.I pcomb, |
224 |
the functions "ri(i)", "gi(i)", and "bi(i)" are predefined as |
225 |
"ci(i,R)", "ci(i,G)", and "ci(i,B)", respectively. |
226 |
Accordingly, the "ro", "go", and "bo" |
227 |
variables may be used in place of "co(R)", "co(G)", and "co(B)", |
228 |
but all three must be defined for this substitution to take place. |
229 |
Finally, the total number of input files is set in the constant "nfiles". |
230 |
.PP |
231 |
Results are sent to the standard output. |
232 |
By default, the values will be written in the lowest precision format |
233 |
among the inputs, but the |
234 |
.I \-f[adfc] |
235 |
option may be used to explicitly output components |
236 |
as ASCII (-fa), binary doubles (-fd), floats (-ff), or common-exponent |
237 |
colors/spectra (-fc). |
238 |
In the latter case, the actual matrix dimensions are written in the resolution string rather than the header. |
239 |
Also, matrix results will be written as standard |
240 |
Radiance pictures if they have either one |
241 |
or three components. |
242 |
In the one-component case, the output is written as grayscale. |
243 |
If more than 3 components are in the final matrix and |
244 |
.I -fc |
245 |
is specified, the output will be a Radiance spectral picture. |
246 |
.PP |
247 |
The |
248 |
.I \-h |
249 |
option may be used to reduce the information header size, which |
250 |
can grow disproportionately, otherwise. |
251 |
The |
252 |
.I \-w |
253 |
option turns off warnings about divide-by-zero and other non-fatal |
254 |
calculation errors. |
255 |
.PP |
256 |
The |
257 |
.I \-n |
258 |
option specifies how many execution processes to employ, |
259 |
which may improve performance on multi-core architectures, |
260 |
especially for matrix multiplication |
261 |
and complex operations on long input rows. |
262 |
.SH EXAMPLES |
263 |
To convert two hyperspectral inputs to RGB color space, |
264 |
average them together, and write them out as a RADIANCE picture: |
265 |
.IP "" .2i |
266 |
rcomb -C RGB -s .5 img1.spc -s .5 img2.spc > avg.hdr |
267 |
.PP |
268 |
Divide one set of matrix elements by the Euclidean sum of two others: |
269 |
.IP "" .2i |
270 |
rcomb -e "co=ci(1)/sqrt(ci(2)^2+ci(3)^2)" inp1.mtx |
271 |
inp2.mtx inp3.mtx > out.mtx |
272 |
.PP |
273 |
Compute the absolute and relative differences between melanopic and photopic values |
274 |
in a spectral image: |
275 |
.IP "" .2i |
276 |
rcomb -fa -C MY -e "abs(x):if(x,x,-x)" |
277 |
-e "co(p)=select(p,abs(ci(1,1)-ci(1,2)),(ci(1,1)-ci(1,2))/ci(1,2))" |
278 |
input_spec.hsr > compare.mtx |
279 |
.PP |
280 |
Concatenate a spectral flux coefficient matrix with a spectral sky |
281 |
matrix to compute a set of melanopic lux values: |
282 |
.IP "" .2i |
283 |
rcomb view_spec.mtx -m sky_spec.mtx -c M > melux.mtx |
284 |
.SH NOTES |
285 |
The |
286 |
.I rcomb |
287 |
tool was created to overcome some limitations of |
288 |
.I rmtxop |
289 |
and |
290 |
.I pcomb, |
291 |
whose capabilities somewhat overlap. |
292 |
The former loads each matrix into memory before operations, |
293 |
and element components are stored as double-precision. |
294 |
Very large matrices therefore present a problem with that tool. |
295 |
Furthermore, |
296 |
.I rmtxop |
297 |
does not allow arbitrary expressions, limiting |
298 |
what can be accomplished easily on the command-line. |
299 |
In contrast, |
300 |
.I pcomb |
301 |
is fully programmable and operates on its input using a |
302 |
scanline window, so it can handle much larger input dimensions. |
303 |
It also handles single- and three-component float matrices on |
304 |
input and output, but unlike |
305 |
.I rmtxop, |
306 |
.I pcomb |
307 |
has not been extended to handle RADIANCE hyperspectral images |
308 |
or more general matrix data. |
309 |
.PP |
310 |
The |
311 |
.I rcomb |
312 |
tool is a compromise that exceeds the capabilities of either of |
313 |
its predecessors in certain circumstances. |
314 |
In particular, very large matrices may be combined using |
315 |
arbitrary, user-defined operations, and the convenient |
316 |
color conversions of |
317 |
.I rmtxop |
318 |
are supported for both input and output. |
319 |
Finally, a single matrix may be concatenated after operations, |
320 |
permitting a flux transfer matrix with millions of rows to |
321 |
pass through. |
322 |
Generally speaking, |
323 |
.I rcomb |
324 |
should be preferred over |
325 |
.I rmtxop |
326 |
for any operations it can handle, which is everything except |
327 |
multiple matrix concatenations and transpose |
328 |
operations. |
329 |
The latter may be handled more efficiently by |
330 |
.I rcollate(1). |
331 |
That said, there is no significant difference for |
332 |
simple operations on small matrices, and only |
333 |
.I rmtxop |
334 |
and |
335 |
.I dctimestep(1) |
336 |
accept XML files as inputs. |
337 |
Also note that the resizing function of |
338 |
.I pcomb |
339 |
is not supported in |
340 |
.I rcomb, |
341 |
and should instead be handled by |
342 |
.I pfilt(1). |
343 |
.SH BUGS |
344 |
The |
345 |
.I rcomb |
346 |
command currently ignores the "PRIMARIES" setting in input |
347 |
headers, and does not produce any on output, even in |
348 |
circumstances where it would make sense to. |
349 |
.SH AUTHOR |
350 |
Greg Ward |
351 |
.SH "SEE ALSO" |
352 |
dctimestep(1), icalc(1), getinfo(1), pcomb(1), pfilt(1), |
353 |
ra_xyze(1), rcalc(1), |
354 |
rcollate(1), rcontrib(1), rcrop(1), rfluxmtx(1), |
355 |
rmtxop(1), rtpict(1), rtrace(1), vwrays(1) |