Algosim documentation: AdjustRGB

AdjustRGB

Performs an RGB adjustment operation on a pixmap and returns the result.

Syntax

Description

If pm is a pixmap and A an RGB adjustment matrix, then AdjustRGB(pm, A) returns the pixmap obtained by applying A to pm.

An RGB adjustment matrix is a real 3×5 matrix of the form

    ⎛ rc   rr   rg   rb   ro   ⎞
A = ⎜ gc   gr   gg   gb   go   ⎟
    ⎝ bc   br   bg   bb   bo   ⎠

Each pixel in pm is transformed in the same way. If a pixel has colour rgb(r, g, b), then its new RGB coordinates are obtained first by multiplying the four first columns of A by the vector ❨1, r, g, b❩:

                              ⎛1⎞
⎛r'⎞   ⎛ rc   rr   rg   rb   ⎞⎜r⎟
⎜g'⎟ = ⎜ gc   gr   gg   gb   ⎟⎜g⎟
⎝b'⎠   ⎝ bc   br   bg   bb   ⎠⎝b⎠.

The final column of A decides how the vector ❨r', g', b'❩ is made into a valid RGB coordinate vector, in which each component is restricted to [0, 1]. If ro is 0, then r' is moved into [0, 1] by clamping; otherwise, r' is moved into [0, 1] by wrapping. The green and blue coordinates are treated similarly depending on go and bo, respectively.

Notice that this function can be used to alter the intensity of each component, to swap components, and to mix components.

Examples

A ≔ ❨❨0, 0, 0, 0, 0❩, ❨0, 0, 1, 0, 0❩, ❨0, 0, 1, 0, 0❩❩
⎛0  0  0  0  0⎞
⎜0  0  1  0  0⎟
⎝0  0  1  0  0⎠
AdjustRGB(ExampleData("harvestman"), A)

Image 1

A ≔ ❨❨−.5, 1, 1, 1, 0❩, ❨−.4, 0, 1, 1, 0❩, ❨−.4, 0, 0, 1, 0❩❩
⎛−0.5     1     1     1     0⎞
⎜−0.4     0     1     1     0⎟
⎝−0.4     0     0     1     0⎠
AdjustRGB(ExampleData("harvestman"), A)

Image 2

A ≔ ❨❨.2, 1, −.5, 1, 0❩, ❨−1, 1, 1.5, .2, 0❩, ❨.5, 0, −.4, 0.7, 0❩❩
⎛ 0.2     1  −0.5     1     0⎞
⎜  −1     1   1.5   0.2     0⎟
⎝ 0.5     0  −0.4   0.7     0⎠
AdjustRGB(ExampleData("harvestman"), A)

Image 3

See also