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:
Normalize values \( v_{norm} = \frac{v-v_{min}}{v_{max}-v_{min}} \) with \(v_{max}\) the maximum lightness value
Apply contrast change
Apply gamma correction
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
isNULL
, elseout
- Parameters
tensor
: image tensor in \( (N,C,H,W) \) formatgammagrays
: tensor of \( N \) gamma gray valuesgammacolors
: 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 imagesvmax
: maximum lightness value in imagesout
: output tensor (may beNULL
)