Lighting

The following functions change the lighting of 2D images. Both input and output must be contiguous and in channel-first format \((C,H,W)\) (channel, height, width). All dtypes and an arbitrary number of channels is supported.

Output tensor out may be NULL, in which case a new tensor of the same shape and dtype as the input is returned. Output tensor must be same shape and dtype as the input. If output is given NULL is returned.

CudaTensor *augpy::lighting(CudaTensor *tensor, CudaTensor *gammagrays, CudaTensor *gammacolors, CudaTensor *contrasts, double vmin, double vmax, CudaTensor *out)

Apply lighting augmentation to a batch of images. This is a four-step process:

  1. Normalize values \( v_{norm} = \frac{v-v_{min}}{v_{max}-v_{min}} \) with \(v_{max}\) the maximum lightness value

  2. Apply contrast change

  3. Apply gamma correction

  4. Denormalize values \( v' = v_{norm} * (v_{max}-v_{min}) + v_{min} \)

To change contrast two reference functions are used. With contrast \( \mathcal{c} \ge 0 \), i.e., increased contrast, the following function is used:

\[ f_{pos}(v) = \frac{1.0037575963899724}{1 + exp(6.279 + v \cdot 12.558)} - 0.0018787981949862 \]

With contrast \( \mathcal{c} < 0 \), i.e., decreased contrast, the following function is used:

\[ f_{neg}(v) = 0.1755606108304832 \cdot atanh(v \cdot 1.986608 - 0.993304) + 0.5 \]

The final value is \( v' = (1-\mathcal{c}) \cdot v + \mathcal{c} \cdot f(v) \).

Brightness and color changes are done via gamma correction.

\[ v' = v^{\gamma_{gray} \cdot \gamma_c} \]

with \(\gamma_{gray}\) the gamma for overall lightness and \(\gamma_{c}\) the per-channel gamma.

Return

new tensor if out is NULL, else out

Parameters
  • tensor: image tensor in \( (N,C,H,W) \) format

  • gammagrays: tensor of \( N \) gamma gray values

  • gammacolors: tensor of \( C\cdot N \) gamma values in the format \( \gamma_{1,1}, \gamma_{1,2}, ..., \gamma_{1,C}, \gamma_{2,1}, \gamma_{2,2}, ... \)

  • contrasts: tensor of \( N \) contrast values in \( [-1, 1] \)

  • vmin: minimum lightness value in images

  • vmax: maximum lightness value in images

  • out: output tensor (may be NULL)