When I first started exploring image processing and color science, I implemented a CVPR 2016 paper in MATLAB: Do It Yourself Hyperspectral Imaging with Everyday Digital Cameras.

A recent conversation about Hongfeng and Danxia brought that old, hand-written code back to mind.

I do not know whether those products actually reconstruct SPD or SRD. What caught my attention was the changing way we acquire additional spectral measurements. It made me want to dust off this paper and read it again. Being an older piece of work, it tackles the problem without a neural network.

Let us start with the most basic question: if we already have RGB, why would we want the spectrum? (If you are familiar with this area, feel free to jump straight to Sections 4, 5, and 6.)

1. Starting with metamerism

RGB gives us just three numbers; a spectrum describes how energy is distributed across wavelengths. Those three numbers can capture a color response, but they cannot preserve every detail of the spectrum.

This gives rise to metamerism: different spectra producing the same color response under specified viewing conditions.

For example, two materials with different reflectance spectra may look identical under one illuminant, yet no longer match under another. Cameras face a similar problem: different incident spectra may produce the same RGB values in one camera, but different readings in another camera with different spectral sensitivities.

It is important to distinguish the human eye from a camera here. Identical RGB values in a particular camera do not necessarily imply an identical appearance to a human observer. A claim of metamerism needs to specify both the illumination and the responses of the observer or sensor.

The implication for spectral reconstruction is straightforward: if a camera has already collapsed two different spectra into the same RGB values, those values alone cannot tell us which spectrum was originally there.

That is what makes spectral reconstruction interesting to me. It can provide a richer basis than three current readings for predicting color when the viewing conditions change.

2. How do SPD, SRD, and RGB relate?

Here, SPD means the illuminant's spectral power distribution, and SRD means the object's spectral reflectance distribution. The former describes the energy present at each wavelength in the illumination; the latter describes how much light the object reflects at each wavelength.

Consider a simplified scene: predominantly diffuse surfaces, uniform illumination, and a sensor operating in its linear range. After appropriately accounting for exposure, geometry, and related factors, the reading in one channel can be written as:

$$ p_k(x) = \int_{\Omega} E(\lambda)\,\rho(x,\lambda)\,c_k(\lambda)\,\mathrm{d}\lambda $$

Here, E(λ) is the illuminant SPD, ρ(x, λ) is the SRD at position x, and ck(λ) is the spectral sensitivity of the camera's kth channel.

We can read this equation by following the light: the source emits it, the object selectively reflects it, and the camera integrates the light reaching the sensor, weighted by the response of each channel. R, G, and B each perform their own version of this calculation.

An object's RGB values, then, are not determined by the object alone. The illumination and the camera's spectral sensitivities also shape the result.

If we can estimate SRD, we can substitute a different illuminant SPD into the model and calculate the object's response under that new illumination, within the model's range of validity. This is one foundation of relighting. Estimating the illuminant SPD, in turn, helps us understand how the current illumination contributes to image formation.

Relit images under different illuminants compared with real photographs from the original paper

Figure 1 | The original paper's relighting experiment. Once reflectance has been recovered, different illuminants are substituted to calculate the object's colors under new lighting. The left column shows the spectra of four illuminants, the middle column the calculated results (Relit), and the right column photographs taken under the corresponding illumination (Groundtruth). Source: [1], Figure 8; an excerpt showing one object.

Working backward from RGB to these two quantities, however, is difficult.

Sampling a spectrum from 400 to 700 nm at 10 nm intervals gives 31 values. For a single pixel, we have three camera readings but want to determine a high-dimensional spectrum—typically an underdetermined problem. Estimating the illuminant and reflectance together introduces further ambiguity because the two are multiplied in the image-formation model.

The simplest example is scale. Provided the reflectance remains physically valid, multiplying the illuminant intensity by a positive constant and dividing the reflectance by the same constant leaves their product unchanged. The camera readings therefore stay unchanged as well. Without additional calibration or constraints, those readings alone cannot determine the absolute scale of both quantities.

The difficulty lies in insufficient measurements and ambiguities in the image-formation model. Writing down a higher-dimensional output does not automatically put more information into the input.

3. Different cameras, different measurements

The paper's key idea is to exploit differences in spectral sensitivity between cameras.[1]

Although the channels may all be called R, G, and B, their response curves differ from camera to camera. The same light undergoes a different weighted integration in each device. Two spectra that one camera cannot distinguish may therefore become distinguishable when measured with another set of responses.

Red-channel spectral sensitivities of six cameras

Green-channel spectral sensitivities of six cameras

Blue-channel spectral sensitivities of six cameras

Figure 2 | R, G, and B channel responses, from top to bottom. Different curve colors represent different cameras; the legend is in the top, red-channel plot. Even channels with the same name do not respond identically across wavelengths. The horizontal axis is wavelength, and the vertical axis is relative spectral sensitivity. Source: [1], Figure 3, separated into a vertical arrangement.

Three cameras can provide nine channel readings for the same scene point. The crucial phrase is “different spectral sensitivities.” Taking three photographs with the same camera under identical conditions may help reduce random noise, but it does not give us three different sets of spectral responses.

Camera count is not the only consideration, either. If all three cameras have very similar responses, much of the added information is redundant. The paper therefore analyzes differences between camera responses and uses them to select camera combinations.

Of course, nine readings are still not enough to recover arbitrary illuminant and reflectance spectra without further assumptions. The paper takes another step: it uses statistical regularities in real spectra to reduce the number of unknowns.

Specifically, the authors approximate spectra as linear combinations of a small number of basis functions. Think of these as a set of basic curves describing spectral shape. Instead of estimating a separate value at every wavelength, the solver estimates how much of each curve is needed. The paper uses eight basis functions for reflectance, four for outdoor illumination, and six for indoor illumination, together with smoothness and nonnegativity constraints.

How well these approximations work depends on the spectra being measured and the data used to construct the model. A small basis that describes a collection of common materials does not necessarily describe every material and every light source accurately.

The solution uses alternating least squares: hold reflectance fixed and estimate the illuminant, then hold the illuminant fixed and estimate reflectance, repeating the updates. Multiple pixels share the same illumination, allowing measurements at different positions to contribute to a joint illuminant estimate.

To reduce computation, the paper first jointly estimates illumination and reflectance at a small number of positions. It then fixes the illumination and solves for reflectance at the remaining pixels.

In the paper's experiments, three cameras offered a useful balance between performance and cost. That conclusion belongs to a particular set of cameras, data, and modeling assumptions. It does not mean that “three RGB images can uniquely recover any spectrum.”

Illuminant and reflectance reconstruction errors versus camera count in the original paper

Figure 3 | Simulation results from the original paper. The horizontal axis shows the number of cameras and the vertical axis reconstruction error. Green represents illumination; blue represents reflectance. In these experiments, the reflectance-error curve is already fairly flat by three cameras, while the illumination error continues to decrease. Source: [1], Figure 4.

4. My MATLAB implementation back then

My code is still on GitHub.[2] As the repository explains, this was an implementation based on my own understanding. Its data and implementation details do not match the original paper exactly.

Alternating least squares estimates illumination and reflectance from two sets of RGB observations

Figure 4 | Two sets of RGB observations, spectral basis functions, and known camera responses are used to alternately estimate the illuminant SPD and the object's SRD. Rearranged from the repository's original illustration, this is only a schematic of the workflow. The Mona Lisa shown here is not the test data used below.

I constructed low-dimensional bases from publicly available illumination and reflectance data, then tested the method on a hyperspectral image from the CAVE dataset. The current code uses two sets of camera spectral sensitivities to project the original 31-channel image into six channels, simulating two RGB cameras observing the same scene.

It then randomly samples 30 pixels and alternately estimates illumination and reflectance at those positions. Once the illumination has been estimated, the code solves across the entire image and compares the result with the input hyperspectral image.[3]

This implementation retains eight basis functions for illumination and ten for reflectance, unlike the original paper. It includes a smoothness regularizer but does not fully implement the paper's nonnegativity constraints; some outputs also undergo absolute-value and normalization operations. It therefore illustrates how I understood and implemented the workflow at the time, rather than reproducing the paper's reported accuracy.

There is another distinction worth keeping clear: a reconstructed hyperspectral image that closely matches the input does not, by itself, demonstrate that the illuminant SPD and the object's SRD have each been estimated accurately. Their product may agree with the observations even when the individual estimates remain biased. Evaluating their separation requires corresponding ground-truth illuminant and reflectance data.

Looking back, this exercise connected several ideas I had previously understood in isolation: how spectra produce camera readings, how low-dimensional representations reduce the unknowns, and how a problem that looks hard to solve directly can be broken into subproblems that are updated in turn.

The method combines data-driven basis functions with an explicit physical model and numerical optimization. It uses no CNN, yet still demands attention to whether the data are representative, whether the assumptions hold, and what the resulting estimates actually demonstrate.

5. In real capture, registration is a hurdle

My simulation enjoys one convenient condition: all six channels come from the same hyperspectral image, so their spatial positions already correspond.

Real capture is less forgiving. For three cameras to jointly estimate the spectrum at a point, their readings must actually come from the same scene location. If a pixel in one camera sees clothing while a pixel in another sees the background, combining those values into one observation vector breaks the image-formation model.

Planar objects are relatively straightforward: a homography can align them. In complex three-dimensional scenes, differences in depth introduce parallax, while occlusion makes some points visible to only a subset of the cameras. Motion or unsynchronized capture further changes the correspondences.

The original paper goes beyond simulation. It photographs planar objects with three real cameras, registers the images using homographies, and uses hyperspectral-camera data as a reference. The authors also explicitly acknowledge that nonplanar scenes require more sophisticated dense registration; the paper does not go on to solve that challenge.[1, §3.4, §4.3]

The method has therefore been validated on real data under constrained conditions, but there is still a gap to everyday photography. A reconstruction algorithm can only do its job when the practical system reliably supplies the inputs its model requires.

Registration is not the only condition. The method also needs known camera spectral sensitivities and data consistent with a linear model—for example, measurements extracted from RAW and appropriately corrected for exposure and other relevant factors. A few JPEGs that have already undergone white balance, color transforms, and tone processing generally cannot be plugged into the same model. The uniform-illumination assumption also limits its direct applicability to complex scenes with mixed lighting.

6. Why revisit this work in the age of multispectral hardware?

Approaches such as Hongfeng and Danxia brought me back to this paper largely because of the additional spectral observations they introduce. Huawei's official descriptions present Hongfeng as a way to capture more information about ambient colors and improve the colors in the final image. OPPO's public materials also describe Danxia's regional color processing and coordination across multiple sensors.

From a measurement perspective, this suggests a direction worth investigating: a purpose-built multispectral imaging module that measures the same scene through several distinct spectral responses could reduce the need for multiple separate RGB cameras. Measurements once assembled across several devices might become available in a more compact setup.

This could ease some of the acquisition and cross-camera registration burden, although the extent depends on the hardware architecture. With a spectral filter array, different channels often sample interleaved spatial positions. An auxiliary module and the main camera may still differ in viewpoint and resolution. Integration into one module does not mean that every channel automatically samples exactly the same spatial locations.

Beyond channel count, we need to ask whether the response curves provide sufficiently distinct information, and whether noise, calibration, and the operating spectral range are appropriate. Assessing whether a particular sensor can support this kind of reconstruction still requires its actual responses and raw measurement data.

Metamerism does not disappear, either. A finite set of channels still provides only a finite set of measurements of an arbitrary spectrum. More channels with well-chosen responses can help separate cases that were previously indistinguishable, but they do not guarantee a unique answer.

Nor does better color reproduction necessarily require reconstructing a complete hyperspectral image first. A system could instead use the extra measurements to estimate illumination characteristics or directly assist color mapping. The paper offers a reconstruction approach worth understanding; individual products may follow different processing paths.

That is what interests me on returning to this work: measurements that once required several cameras now have new possibilities for hardware implementation. The old algorithm cannot simply be carried over unchanged, but its account of the relationship between observations, illumination, and reflectance remains useful.

Back then, writing the MATLAB code was mostly an attempt to bring the paper's calculations to life. Today, the questions I want to investigate are different: with a real multispectral sensor, which conditions improve, which ambiguities remain, and can we ultimately predict colors under changing illumination more reliably?

References

1. Seoung Wug Oh, Michael S. Brown, Marc Pollefeys, Seon Joo Kim. Do It Yourself Hyperspectral Imaging with Everyday Digital Cameras. CVPR 2016, pp. 2461–2469.
https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Oh_Do_It_Yourself_CVPR_2016_paper.pdf

2. My MATLAB implementation: Replay-DoItYourselfHSIwithDigitalCamera.
https://github.com/Hurricane-k/Replay-DoItYourselfHSIwithDigitalCamera

3. Implementation files: HSI_Recovery.m and PCA_SPD_SRD.m.
https://github.com/Hurricane-k/Replay-DoItYourselfHSIwithDigitalCamera/blob/main/HSI_Recovery.m
https://github.com/Hurricane-k/Replay-DoItYourselfHSIwithDigitalCamera/blob/main/PCA_SPD_SRD.m