View source: R/colorSpec.emulate.R
emulate | R Documentation |
The two possible modifications are:
pre-multiplication by a transmitting filter
post-multiplication by a matrix
Both of these are optional.
If neither of these modifications is enabled, the original x
is returned.
## S3 method for class 'colorSpec'
emulate( x, y, filter=FALSE, matrix=TRUE )
x |
a colorSpec responder with M spectra, to be modified.
The |
y |
a colorSpec responder with N spectra, to be emulated by a modified |
filter |
enable filter pre-multiplication. |
matrix |
enable matrix post-multiplication.
If |
If filter=FALSE
and matrix=TRUE
then
the returned value is multiply(x,A)
,
where the matrix A
is computed to minimize the difference with
y
, in the least squares sense (Frobenius matrix norm).
The function ginv()
is used here.
If filter=TRUE
and matrix=FALSE
then
the returned value is product(filter,x)
,
where the object filter
is computed to minimize the difference with
y
, in the least squares sense (Frobenius matrix norm).
This calculation is fairly straightforward,
but requires that the responsivity of x
does not vanish at any wavelength.
It also requires that M=N
.
The computed filter may be unrealistic, i.e. the transmittance may be > 1.
If this happens a WARN
message is issued.
If filter=TRUE
and matrix=TRUE
then
the returned value is product(filter,multiply(x,A))
,
where (filter,A)
are chosen with the above minimization criterion.
If N=1
then we must have M=1
as well;
the calculation is trivial and the emulation is exact.
If N
\ge
2
,
the calculation is iterative - solving alternatively for
filter
and A
until convergence.
The function ginv()
is used on each iteration.
This is a bilinear optimization.
If convergence fails, it is an error and the function returns NULL
.
If convergence succeeds, there is 1 degree of freedom in the (filter,A)
pair.
If one is scaled by a positive constant, the other can be scaled by the inverse,
and the returned object is the same.
The filter is scaled so the maximum transmittance is 1.
If filter=FALSE
and matrix=FALSE
then
the original x
is returned, with a WARN
message.
a colorSpec object close to y
, as in Details.
The quantity
is the same as y
.
The specnames()
are the same as those of y
,
except that ".em"
is appended to each one.
The function attaches attribute "emulate"
,
whose value is a list containing filter
and/or A
as appropriate.
see the vignette Emulation of one Camera by another Camera
wavelength
,
type
,
quantity
,
multiply
,
product
,
specnames
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.