跳至正文
wyaaaattwhoAI RESEARCH & ENGINEERING
← 返回首页
Tech2024-08-02

ISP技术入门 AI+ISP

Color tutorials

Color and color spaces

The most common color space is CIE XYZ, but before we get into that, we first need a more basic view of how we perceive the colors.

Spectral power distribution (SPD)

Every color (visible spectrum) has a special combined wavelength, this can be described by a spectral power distribution (SPD) shown below. The SPD plot shows the relative amount of each wavelength reflected over the visible spectrum.
notion image
Due to the accumulation effect of the cones, two different SPDs can be perceived as the same color (such SPDs are called “metamers”).

Tristimulus color theory

People found that all color could be expressed as a linear combination of three primary color. Grassman’s Law states that a source color can be matched by a linear combination of three independent “primaries”.
notion image

Radiometry vs. photometry/colorimetry

Radiometry
  • Quantitative measurements of radiant energy.
  • Often shown as spectral power distributions (SPD).
  • Measures light coming from a source (radiance) or light falling on a surface (irradiance).
Photometry/ colorimetry (a psychophysical)
  • Quantitative measurement of perceived radiant energy based on human’s sensitivity tolight.
  • Perceived in terms of “brightness” (photometry) and color (colorimetry).
Now we face the problem to bridging up the gap between the radiometry and photometry/colorimetry. How can we do that? Well in the flicker experiments, we are finally able to measure how we perceive different color of different SPD byb their brightness.
notion image
We invert the result, and we shall get what is called CIE (1924) Photopic luminosity function
notion image
The Luminosity Function (written as y(λ) or V(λ)) shows the eye’s sensitivity to radiant energy into luminous energy (or perceived radiant energy) based on human experiments (flicker fusion test).
And finally, we can define a quantity to measure the perceived brightness of different light. That is
notion image
And now let’s figure how to go from radiometry to colorimetry. Based on tristimulus color theory, colorimetry attempts to quantify all visible colors in terms of a standard set of primaries. So by hiring “standard observers”, we can easily carry out experiments and thus set up a measurement for our purpose.
notion image
Noticeable that there are negative values in, we can apply an linear transformation to avoid this.
In 1931, the CIE met and approved defining a new canonical basis, termed XYZ that would be derived from Wright-Guild’s CIE RGB data.
  • Properties desired in this conversion:
    • Positive values only
    • Pure white light (flat SPD) to lie at X=1/3, Y=1/3, Z=1/3
    • Y would be the luminosity function (V(λ))
  • Quite a bit of freedom in selecting the XYZ basis
    • In the end, the adopted transform was:
      • notion image
notion image
To transfer from SPD to CIE 1931 XYZ we have to carry out three integrates respectively
CIE 1931 XYZ is one of the most common color space we gonna mention later.

Luminance-chromaticity space (CIE xyY)

Sometimes it is useful to discuss color in terms of luminance (perceived brightness) and chromaticity (we can think of as the hue-saturation combined). CIE xyY space is used for this purpose.
notion image
A few things you need to know about this image:

Color constancy and color temperature

Color constancy

Our visual system has an amazing ability to compensate for environmental illumination such that objects are perceived as the same color.
Color constancy (chromatic adaptation) is the ability of the human visual system to adapt to scene illumination. This ability is not perfect, but it works fairly well. Image sensors do not have this ability! We will discuss this in part 2 . . this is related to the camera’s white-balance module.
We can use The Von Kries transform to discribe this kind of adaptation
notion image
And it’s noticeable that people always adapts printed media rather than emissive media.
All we have discussed about indicates that
  • Color is intimately connected to scene illumination.
  • Even for emissive displays, we have to consider (or make assumptions) about the illumination in the viewing environment of the display.
  • Keep this in mind because it will play a role when we define color spaces used to encode our images.

Color temperature

To better describe color of different illuminant, we introduce color temperature. In the photography and display communities, an illumination’s “color” is described using a correlated color temperature (CCT). This is an excellent example of where metamers are used.
As mentioned, illuminants are often described by their “color temperature.” This mapping is based on theoretical blackbody radiators that produce SPDs for a given temperature expressed in Kelvin (K). We map light sources (both real and synthetic) to their closest color temperature.
notion image
notion image
We can plot visible SPDs in CIE xy chromaticity
notion image
How to check the CCT of a given illuminant is simple, just do as the following steps:
  • Find the light sources SPD mapping to CIE XYZ using the CIE 1931 mapping functions.
  • Project the CIE xyY value to the Planckian locus line.
An example of an OLED light is here
notion image
Where the projection falls is the Correlated Color Temperature (CCT) of this light source. So, in this example, the OLED light source is roughly 4500K. While we often say "color temperature", we should say "correlated color temperature.” The concept is not always related to the physical temperature of the light source, but its correlation with the black body radiator's color temperature.
After we defined the CCT, we can easily define the White point. A white point is a color defined in CIE xyY that we want to be considered “white” (or achromatic/neutral). This is essentially an illuminant’s SPD in terms of CIE XYZ/CIE xyY. Think of it as CIE Yxy value of a white piece of paper under some illumination.
notion image
🚨
Summary
Color constancy is our ability to adapt to illumination in the scene.
Correlated Color Temperature (CCT) — or just color temperature — is a system used to describe scene illumination.
Note: we must factor in the scene illumination when capturing and displaying color images.

Color model versus color space

A color model is a mathematical system for describing a color as a tuple of numbers (RGB, HSV, HSL, more. . . )
A color space is a specific range of colors within a color model. The range of color (gamut) can be expressed in CIE XYZ. Color spaces typically also define the viewing environment and, therefore, the “white point” of the space
notion image
We must understood that no specific color model can fully cover up the CIE XYZ, but just part of it, and we must realize that different definition of white point define a different color model, which implies the existence of a vast range different color models.
In 1996, Microsoft and HP defined a set of “standard” RGB primaries. R=CIE xyY (0.64, 0.33, 0.2126) G=CIE xyY (0.30, 0.60, 0.7153) B=CIE xyY (0.15, 0.06, 0.0721). This was considered an RGB space achievable by most devices at the time. The white point was set to the D65 illuminant. This is an important to note. It means sRGB has built in the assumed viewing condition (6500K daylight).
A matrix decides the transformation from CIE XYZ to the sRGB, which is
notion image
Before introducing someting new, let’s grab a look at Stevens' power law
notion image
That tells us, if we want our color seemed more natural, we need it to be in-linear, that’s why we have our gamma curve
notion image
The actual formula is a bit complicated, but effectively this is gamma () where I’ is the output intensity and I is the linear sRGB ranged 0-1, with a small linear transfer for linearized sRGB values close to 0 (not shown in this plot). This is known as “perceptual encoding” and is intended to allocate more bits based on our nonlinear response to radiant power.
A huge difference between linear and in-linear sRGB
A huge difference between linear and in-linear sRGB
Generally speaking, the relation is like a clan of color spaces
notion image
At last we introduce a little more common color spaces.
  • CIE Lab
    • CIE Lab transforms CIE to a new space where color (and brightness) differences are more uniform.
      notion image
      notion image
      And in CIE Lab it’s safe to define Color error metric – CIE 2000 Delta E (ΔE). Delta E is a color metric based on Lab space. Since Lab is more uniformly perceptual, distances (e.g., Euclidean distance) in L*ab have more meaning than in CIE XYZ. Delta E values have an interpretation as follows.
      notion image
  • Others to be aware of
    • Adobe RGB
      • Medium gamut color space
      • Used for photo-editing
    • Display P3
      • Medium gamut color space
      • Used by Apple devices to accommodate better display technology
      • Similar to Adobe RGB
    • ProPhoto (ROMM)
      • Developed by Kodak
      • Intended to encode a wide range of colors and dynamic range
notion image

In-camera rending pipeline

notion image

Camera

The image directly captured from the camera’s sensor needs to be processed. We can call this process “rendering,” as the goal is to render a digital image suitable for viewing.
notion image

Image signal processor (ISP)

An ISP is dedicated hardware that renders the sensor image to produce the final output.
Companies such as Qualcomm, HiSilicon, Intel (and more) sell ISP chips (often as part of a System on a Chip – SoC). Companies can customize the ISP. Many ISPs now have neural processing units (NPUs).

Camera sensor

Almost all consumer camera sensors are based on complementary metaloxide-semiconductor (CMOS) technology. We generally describe sensors in terms of number of pixels and size. The larger the sensor, the better the noise performance as more light can fall on each pixel. Smart phones have small sensors!
Camera uses a certain pattern of sensors to catch photons.
notion image
The color filter array (CFA) on the camera filters the light into three sensor-specific RGB primaries.
Remember: physical world is measured by radiometric spectral power distributions. Your camera sensor RGB filter is sensitive to different regions of the incoming SPD. Raw-RGB represents the physical world's SPD "projected" onto the sensor's spectral filters.
Note that Sensors are linear to irradiance, if you double the amount of light hitting a sensor's pixel, the digital value output of that pixel will double.
Digital value I is a linear function of irradiate i and exposure t.
🚨
IMPORTANT: raw-RGB sensor images are not in a standard color space.
notion image
So if you try to display a raw-RGB pic it would be weird(like what you see before in your “pixeliser” )

ISO gain and raw-image processing

ISO signal amplification (gain)

Imaging sensor signal is amplified and digitized. Amplification to assist A/D conversion. You need to get the voltage to the range required for the desired digital output. This gain is used to accommodate camera ISO settings. Gain to signal applied on the sensor. Note that gaining the signal also gains image noise.

Black light subtraction

And let’s talk about the pixel intensity. We often talk about a pixel's intensity, however, a pixel's numerical value has no unit.
The digital value of a pixel is based on several factors.
  • Exposure (which is a function of both shutter speed and exposure)
  • Gain (ISO setting on the camera)
  • Camera hardware that digitizes the signal.
That’s why we use relative digital values in the image and not the absolute digital values.
Sensor values for pixels with “no light” should be zero. However, this is not the case due to sensor noise, the black level often changes as the sensor heats up. This can be corrected by capturing a set of pixels that do not see light. Place a dark shield around the sensor. Subtract the level from the “black” pixels.
notion image

Defective pixel mask

In CMOS (complementary metal-oxide-semiconductor) image sensors, defective pixels are a common issue. Here’s a breakdown of the process you mentioned for handling defective pixels:
1. Dead Pixel Masks: Dead pixel masks are used to identify and manage defective pixels in CMOS sensors. These masks are pre-calibrated at the factory to ensure that the sensor performs optimally when deployed.
2. Dark Current Calibration: Dark current refers to the small amount of current that flows through a pixel even when it is not exposed to light. To create a dead pixel mask, a “dark current” calibration is performed. This involves taking an image of the sensor with no light exposure, effectively capturing the dark current levels.
3. Recording Values: During the dark current calibration, the sensor’s output is recorded. Pixels that report values significantly different from their neighbors are identified as defective or bad.
4. Creating the Mask: The recorded values are used to create a mask that identifies which pixels are defective. This mask is essentially a map that indicates which pixels should be considered faulty.
5. Interpolating Bad Pixels: After creating the mask, any data from defective pixels are interpolated. This means that the values from these bad pixels are replaced with values calculated based on neighboring pixels. This interpolation helps to ensure that the image sensor’s output remains accurate and usable despite the presence of defective pixels.
notion image

Flat-field correction

notion image

RGB demoasicing

You’ve already know some part of this

CFA/Bayer pattern demosaicing

Color filter array (CFA) pattern placed over pixel sensors. We want an RGB value at each pixel, so we need to perform interpolation.
Most simply, we just simply interpolation with average values, yet it’s more intuitive that if we use a weight mask.
notion image
There are newer CFAs such as Quad/Tetra (2x2) and Nona (3x3), they aer common on smart phones.
notion image

Noise reduction (NR)

Most cameras apply additional NR after A/D conversion
Analog-to-Digital Converte(ADC)
Analog-to-Digital Converte(ADC)
Two main sources of image noise:
  1. The quantum nature of light (photon noise/shot noise); unrelated to the imaging sensor. Follows a Poisson distribution.
  1. Electronic sources associated with the imaging sensor circuitry (dark current and dark noise). Often follows a Normal distribution.
Gain factor g amplifies noise.
Blur the image based on the ISO setting (higher ISO = more blur). Blurring will reduce noise, but also remove detail. Add image detail back for regions that have a high signal. We can even boost some parts of the signal to enhance detail (i.e. "sharpening")
notion image

White-balance & color space transform(CIE XYZ)

Color mapping/colorimetric stage

This step in the IPS converts the sensor raw-RGB values to a device-independent color space. It’s a two step procedure, first apply a white-balance correction to the raw-RGB values, then map the white-balanced raw-RGB values to CIE XYZ.
notion image
How do white balance (computational color constancy) work? We have a special matrix
notion image
Users can manually set the white balance, otherwise auto white balance (AWB) is performed. In computer vision, we often refer to AWB as "illumination estimation". Since the hard part is trying to determine what the illumination in the scene is. AWB is not easy and this remains an open research problem.
WB manual
WB manual

AWB

Given an arbitrary raw-RGB image, determine what is the camera's response to the illumination. The idea is that something that is white* is a natural reflector of the scene's illuminations SPD. So, if we can identify what is "white" in the raw-RGB image, we are observing the sensor's RGB response to the illumination.
First we introduce "Gray world" algorithm.
notion image
notion image
Also we have "White patch" algorithm.
notion image
notion image
🚨
you can actually think of two different pool NN in PyTorch
Gray world and white patch are very basic algorithms. These both tend to fail when the image is dominated by large regions of a single color (e.g. a sky image).

Color space transform

notion image
notion image
notion image

Color manipulation (Photo-finishing)

This is the stage where a camera applies its "secret sauce" to make the images look good.
  • This procedure is called by many names:
    • Color manipulation
    • Photo-finishing
    • Color rendering or selective color rendering
    • Yuv processing engine
  • DSLR will often allow the user to select various photo-finishing styles.
  • Smartphones often compute this per-image.
  • Photo-finishing may also tied to geographical regions!
Color manipulation can be implemented using a 3D look up table (LUT) and a 1D LUT tone-curve. The 3D LUT table acts like a 3D function: 𝑓 (𝑅, 𝐺, 𝐵) → 𝑅′, 𝐺′, 𝐵′ The 1D LUT table is applied per channel: g (𝑅) → 𝑅′, 𝑔 (𝐺) → 𝐺′, 𝑔 (𝐵) → 𝐵′ The 3D and 1D LUT can change based on picture style
notion image
There’s also Local tone mapping (LTM) compared to the Global tone mapping (GTM)
🚨
On many cameras, esp smartphones, a local tone map is applied as part of the photo-finishing. This helps bring out highlights in the image.
Selective color manipulation, "Select" colors can be manipulated, especially skin tone, sometimes called preferred color correction (PCC)

Image rescaling (or up-scaling)

Re-scaling image and sRGB conversion, often, the entire image is processed by the ISP and then rescaled for the view-finder or to fit the requested output resolution.
notion image

Mapping to output color space

notion image

JPEG/HEIC compression

notion image
The amount of quantization applied on the DCT coefficients amounts to a “quality” factor.
  • More quantization = better compression (smaller file size)
  • More quantization = lower quality
🚨
Note that both sRGB and JPEG are being slowly replaced

Save to file

Circular buffer for ZSL(Zero Shutter Lag) and multi-frame processing

  • Many ISPs store the last few RAW images in memory (i.e., a circular buffer).
  • These images can be used for many purposes (image stabilization, temporal noise reduction, etc.).
  • Another purpose is to ensure “Zero Shutter Lag” (ZSL).
    • There is often a delay between when a person presses the “capture” and the camera capturing the image. This is called “shutter lag”.
    • So, a previous image in the buffer can saved instead.
notion image
 
🚨
Again, it is important to stress that the exact steps mentioned in these notes only serve as a guide to what takes place in a camera
notion image

RELATED ARTICLES

相关文章