Skip to content

Multi-scale Retinex with color restoration

Fact Value
Also called MSRCR, Retinex-based color enhancement
Status Implemented and tested
Family Enhancement, illumination and color
Engine Browser
Type Nonlinear, color, multi-scale log ratio with color restoration
Output Image
Operator shown as algorithm (exact)
Support radius global
Code web/src/core/filters/enhancement/retinex.ts, msrcrFilter
Operator code web/src/core/filters/enhancement/retinex.ts, msrcrFilter

Overview

Multi-scale Retinex on each channel makes colors grayer. Jobson, Rahman and Woodell added a color restoration step that multiplies each channel's Retinex by the log of that channel's share of the pixel. Strong colors get a larger factor, so some of the color comes back.

Three panels: a chart of colored and gray patches that darkens from left to right, the chart after multi-scale Retinex on each channel, and the chart after MSRCR, both much more even, with MSRCR a little more colorful. Three panels: a chart of colored and gray patches that darkens from left to right, the chart after multi-scale Retinex on each channel, and the chart after MSRCR, both much more even, with MSRCR a little more colorful.
The patch chart lit from the left, multi-scale Retinex, and MSRCR with color restoration, shown at a quarter of its size.

How it works

  1. Compute the multi-scale Retinex of each channel with the three scales.
  2. Find each channel's share of the pixel's total.
  3. Multiply the channel's Retinex by the log of alpha times that share.
  4. Stretch each channel to 0 to 255, clipping a small percent of the values at each end.

Mathematical foundation

\[ R'_c = R_c \left[\log\left(\alpha\, (I_c + 1)\right) - \log \sum_{j} (I_j + 1)\right], \qquad \alpha = 125 \]

The formula shows the default parameter values.

where

  • \(R_c\): The multi-scale Retinex of channel c
  • \(\alpha\): The constant of the color restoration
  • \(I_j\): The red, green and blue values of the pixel, 0 to 255

R_c is the multi-scale Retinex of channel c with the scales sigma_1, sigma_2 and sigma_3 and equal weights. Jobson, Rahman and Woodell multiply it by the color restoration function beta log(alpha I'_c). Here I'_c = I_c / sum_j I_j is the channel's share of the pixel. They use alpha = 125, beta = 46 and the scales 15, 80 and 250, then a gain G = 192 and an offset b = -30. Petro, Sbert and Morel found that no fixed gain and offset suits all images, and stretch each channel with Simplest Color Balance instead. That stretch removes any common factor, so beta, G and b have no effect here. They also warn that the restoration can invert colors where a channel is near 0, because both factors are then negative. PixelNexus takes the log of I + 1 so that black pixels have a finite log, and a result with no spread turns mid gray.

The factor log(alpha I_c) - log of the sum is the log of alpha times the channel's share. A gray pixel has a share of 1 / 3 in every channel, so all three get the same factor. In a red pixel, red has the largest share and the largest factor, so red stays strong after the stretch.

Petro, Sbert and Morel point out a risk. Where a channel is near 0, its Retinex is negative and so is its factor, and the product turns positive. After the stretch, that channel can come out bright, so a deep blue can turn magenta. For such images, Multi-scale Retinex on the intensity keeps the colors safely.

Kernel or operator

The Inspector shows the Retinex, the color restoration and the color balance as formulas with the current settings.

Algorithm

  1. Compute the multi-scale Retinex of each channel with the three scales.
  2. Multiply it by log(alpha (I_c + 1)) - log of the sum of the three channels plus 3.
  3. Stretch each channel to 0 to 255 with Simplest Color Balance.

Parameters

Parameter Default Values Meaning
Small scale sigma1 15 1 to 1000 px The standard deviation of the first Gaussian surround.
Middle scale sigma2 80 1 to 1000 px The standard deviation of the second Gaussian surround.
Large scale sigma3 250 1 to 1000 px The standard deviation of the third Gaussian surround.
Alpha alpha 125 1 to 500 The constant alpha inside the log of the color restoration.
Clip dark clipLow 1 0 to 20 % The percent s1 of the darkest values that the color balance sets to 0.
Clip bright clipHigh 1 0 to 20 % The percent s2 of the brightest values that the color balance sets to 255.

Implementation

msrcrFilter in web/src/core/filters/enhancement/retinex.ts computes the factor for each channel and pixel, and passes it to the same Retinex and color balance code as Multi-scale Retinex. It is a global color filter, so it always sees the whole image.

Worked example

Image Left quarter luma Right quarter luma Right / left Saturation (%)
Shaded chart 158.6 43.8 0.28 65
SSR, sigma 80 184.4 153.6 0.83 61.5
SSR, sigma 80, intensity 181.4 117.3 0.65 64.8
MSR, sigma 15, 80, 250 197.1 146.4 0.74 57.1
MSR, intensity 190 93.1 0.49 64.8
MSRCR, alpha 125 192.1 133.2 0.69 58.3

Each row is a result with its default settings, except where the row says intensity, on the chart of the figure at full size, 720 by 360 pixels, lit from the left. Luma is 0.299 R + 0.587 G + 0.114 B, averaged over the left and right quarters, which hold the same patches. Saturation is (max - min) / max per pixel, averaged over the patches with color. A right / left ratio near 1 means the light is evened out. The row "MSRCR, alpha 125" is this filter.

On this chart, MSRCR keeps a little more saturation than multi-scale Retinex on each channel, and it evens out the light a little less. Multi-scale Retinex on the intensity keeps almost all of it.

Complexity

  • Time: \(O(N log N)\)
  • Memory: \(O(N)\)

N is the number of pixels. Nine Gaussian blurs through the FFT of each row and column, three scales for each channel.

Artifacts and limitations

Limitations

  • Saturated colors can invert where a channel is near 0, as Petro, Sbert and Morel show.
  • Colors can come out stronger than in the scene.

Artifacts

  • Odd colors in pixels with a channel near 0, such as deep blue or red.
  • Mild halos along strong edges.

Tests

The fixture cases come from a NumPy reference that follows Algorithm 1 of Petro, Sbert and Morel, with the default constants and with smaller scales and another alpha. Before the cases are written, the blur is checked against scipy.ndimage.gaussian_filter with the reflect mode.

References

  • Jobson, D. J., Rahman, Z. and Woodell, G. A. A multiscale retinex for bridging the gap between color images and the human observation of scenes. IEEE Transactions on Image Processing 6(7), 965 to 976, 1997. DOI 10.1109/83.597272.
  • Petro, A. B., Sbert, C. and Morel, J.-M. Multiscale Retinex. Image Processing On Line 4, 71 to 88, 2014. DOI 10.5201/ipol.2014.107.
  • Limare, N., Lisani, J.-L., Morel, J.-M., Petro, A. B. and Sbert, C. Simplest Color Balance. Image Processing On Line 1, 297 to 315, 2011. DOI 10.5201/ipol.2011.llmps-scb.