On this page

Pixel math reference

Use Pixel math to calculate a new color or decide where a layer applies. For each pixel, Studio can read the stretched value of a named input such as Ha. An adjustment can also read the color already assembled beneath it. Once you apply an expression, changing an input stretch or a contributing layer automatically updates the result. Compare all eleven templates or follow a worked edit.

Apply an expression

  1. For a color change, select a layer under Combine and choose Adjustment, then Pixel math. The new layer starts with One for RGB and the expression t, which passes each channel through. Choose Split when red, green and blue need different calculations. Studio keeps the expressions you enter in each mode.
    Adjustment menu with Adjustment and Pixel math outlined.
    Open Adjustment. Pixel math is the last item in the menu.
  2. For a mask, select the layer you want to limit. Under Computed from inputs, choose New mask for this layer. Studio assigns the mask and opens its inspector. Select Mask to inspect the coverage or Picture to see its effect.
    Computed from inputs controls with New mask for this layer outlined.
    Choose the marked button on the layer you want the mask to control.
  3. Click the expression in the inspector. Enter a formula or select a suggested name as you type. Apply the expression to refresh the canvas. If Studio finds an error, the editor stays open with the reason and the picture keeps its last applied expression.
    Iris Pixel math inspector in One for RGB mode with the applied expression mtf(0.4, t) marked.
    This applied expression lifts each channel’s midtones. Click the marked field to edit it.
Keys in the expression editor
ActionKey
Select a suggestion↑ or ↓
Insert the selected suggestionTab
Start a new lineShift + Enter
Apply the expressionEnter
Discard the current text editEsc

Choose which pixels to read

t or $T · current channel
On an adjustment, Studio reads the channel it is calculating from the picture beneath the layer. In One for RGB, t * 0.8 multiplies red, green and blue separately by 0.8. In the Green field under Split, t reads green.
r, g, b · color beneath the adjustment
These read red, green and blue at the same pixel. All three output expressions read the same incoming picture. Editing the red expression cannot change the value of r read by the green expression.
l · luminance beneath the adjustment
Studio weights the incoming red, green and blue using the picture’s working color space. Enter l in One for RGB to put that brightness into all three channels and produce a grayscale picture.
Input name · stretched input
In an adjustment or mask, use an input from the open document, such as red, Ha, OIII or SII. Each value comes from that input after its own Stretch, wherever it appears in the layers. In an adjustment, red reads the red input while r reads the composite red beneath the layer. For a separated stars input, the editor may offer a name such as ha@stars.

A computed mask reads named inputs and constants. The adjustment variables for the picture beneath have no special meaning in a mask. A mask can read eight distinct inputs. An adjustment can also read eight, counted across its active channel expressions together. Repeating an input uses one place.

Write numbers, operators and named values

Enter decimal numbers such as 2, 0.35 or .5. Scientific notation such as 1e-3 means 0.001. Names are case-insensitive. Start a name with a letter or underscore. The rest may include letters, digits, underscores, periods and @, as in red.2. Use the editor’s suggestion to insert the exact role name of an input.

Studio evaluates the following groups from top to bottom. Parentheses override this order. Within a group, binary operators evaluate from left to right, except for powers.

OperatorsResult at this pixel
+x, -x, ~x, !xKeep the sign, negate, invert as 1 - x, or test for zero. ~0.25 gives 0.75. !0.25 gives 0.
a ^ bRaise a to the power b. Powers group from the right, so 2 ^ 3 ^ 2 gives 512. A leading minus binds first, so -2 ^ 2 gives 4. Write -(2 ^ 2) for −4.
a * b, a / bMultiply or divide. Write the multiplication sign explicitly.
a + b, a - bAdd or subtract.
<, <=, >, >=, ==, !=Compare two values. Each comparison gives 1 for true and 0 for false. Use == for equality.
a && bGive 1 when both values are nonzero. To test an interval, write both comparisons, as in Ha > 0.1 && Ha < 0.8.
a || bGive 1 when either value is nonzero. Otherwise give 0.

Give an intermediate value a name with =. Write the result last. Each assignment ends at a line break or a semicolon. A final semicolon is optional. Choose a distinct name so a local value cannot hide an input you need later. A later assignment can update a local value. Function names are reserved.

overlap = Ha * OIII
weight = overlap ^ ~overlap
weight * Ha + ~weight * OIII

Here overlap is the product of the two inputs at one pixel. The final line blends between H-alpha and oxygen using the local weight. Each new pixel gets its own values. If Studio reports that an expression is too deep, give a nested calculation a name. Each expression allows 256 compiled instructions and space for 32 simultaneous values, including local names.

Look up a function

Use parentheses and separate arguments with commas. Each argument can be a number, an input or another expression. The examples use numbers you can replace with pixel values. All functions work at one pixel. For example, mean(r, g, b) averages three channels at that position.

Combine or select values

FunctionArguments and result
min(a, …)The smallest of one or more values. min(0.2, 0.8) gives 0.2.
max(a, …)The largest of one or more values. max(0.2, 0.8) gives 0.8.
sum(a, …)The sum of one or more values. sum(0.4, 0.8) gives 1.2, above SDR white.
mean(a, …)The arithmetic mean of one or more values. mean(0.2, 0.5, 0.8) gives 0.5.
avg(a, …)An alias for mean with the same arguments. avg(0.2, 0.8) gives 0.5.
iif(condition, yes, no)Select yes when the condition is nonzero or no when it is zero. iif(0.3 > 0.2, 1, 0) gives 1. All three arguments are evaluated.

Control range and contrast

FunctionArguments and result
range(x, low, high)Hold x between the limits. range(0.8, 0.1, 0.6) gives 0.6. Values inside stay where they are. Put the lower bound first. With reversed bounds the result is high.
rescale(x, low, high)Map low to 0 and high to 1, with linear interpolation and clipping to that interval. rescale(0.3, 0.1, 0.5) gives 0.5. Reversing the bounds reverses the ramp. Equal bounds give 0.
mtf(m, x)Midtones transfer. Choose a midtone m between 0 and 1 to map it to 0.5. mtf(0.25, 0.25) gives 0.5. Values of x at or below 0 give 0, and values at or above 1 give 1. Choose m below 0.5 to brighten midtones or above 0.5 to darken them.

Powers, roots and logarithms

FunctionArguments and result
abs(x)Magnitude of x. abs(-0.2) gives 0.2. Use it on a difference to see the size of a change in either direction.
sqrt(x)Square root. Use a nonnegative argument. sqrt(0.25) gives 0.5.
pow(x, y)Raise base x to exponent y, equivalent to x ^ y. pow(0.5, 2) gives 0.25. Use a nonnegative base for fractional powers.
exp(x)Raise the natural base e to x. exp(0) gives 1.
ln(x)Natural logarithm of a positive value. ln(1) gives 0.
log(x)Base-10 logarithm of a positive value. log(100) gives 2.
log2(x)Base-2 logarithm of a positive value. log2(8) gives 3. A doubling adds 1 to this result.

Keep or fit the result

As computed passes the adjustment’s result on to the layers above it. In SDR, 1 is white. In HDR, a result above 1 can use the available headroom. In a stretched picture, a neutral result of about 1.35 corresponds to twice the light of SDR white. Compare pixel values and stops of headroom. Use Clipping in Final picture to check the finished output. A function such as mtf that caps its own output at 1 will already have discarded values above white.

Choose Rescale under Result to fit out-of-range colors into the picture. Studio measures the lowest and highest values across all three channels at full resolution in the area the inputs cover together. Studio measures the expression at full opacity before this layer’s mask and uses one linear scale for all three channels. In SDR, if the minimum is 0.1 and the maximum is 2, Studio halves the values, including the minimum. If the result already fits between black and the picture’s peak, it stays as computed. Edits to the layer or the picture beneath trigger a new measurement. The canvas shows the unscaled result until the measurement finishes.

The expression is t * 2 in both views of the starless Iris group. In SDR, the doubled core reaches white. After Studio measures the full picture, Rescale brings the peak back into range. In this crop the median red value falls from 0.562 to 0.268.

The rescale(x, low, high) function uses the two bounds you supply at each pixel. Use it when a particular input brightness should always map to a particular amount of coverage. A computed mask always limits its expression result to 0–1 before applying Reach, Smoothing and touch-ups. With Strong selected on the layer, white applies the layer fully, gray partly and black leaves it out. Weak reverses that coverage.

Calculations use floating-point values. A final result that is NaN, for example from sqrt(-1), becomes 0. Division by zero or a log of zero can produce an infinite value. Keep denominators away from zero and logs positive. For a nonnegative input such as oxygen, Ha / max(OIII, 0.01) limits the denominator to at least 0.01. The ratio may still exceed 1.

Start with a template

Select a Pixel math adjustment. Under Templates, click a name to apply it. Studio selects One for RGB or Split and replaces the expressions in that mode. Hover over a button for its description.

Studio’s Templates section with eleven buttons, from Exposure through OIII into green and blue.
SNR G132 has H-alpha, OIII and SII, so all eleven templates appear. Iris has the seven general templates. Gulf of Mexico also offers the three line templates that use H-alpha or OIII.
Jump to a template

Each pair follows the same document pixels through one adjustment at full opacity. You can try any template independently. On Iris, the adjustment sits in the starless Color group below the returned stars.

Exposure

Increase every stretched channel by a factor of about 1.41. Change 0.5 to set the exponent.

One for RGB t * 2 ^ 0.5

The dust and the dark sky both brighten. Check the pale core as well as the faint folds when raising all three channels.

Midtones

A channel value of 0.4 moves to 0.5. Move the first argument toward 0.5 for a gentler lift.

One for RGB mtf(0.4, t)

The brown folds below the core become easier to follow. Black and SDR white stay fixed. Compare a dust fold with a nearby dark pocket.

Contrast curve

This S curve darkens values below 0.5 and brightens values above 0.5. The first assignment limits the input to 0–1.

One for RGB x = range(t, 0, 1); iif(x < 0.5, 2 * x ^ 2, 1 - 2 * (1 - x) ^ 2)

The dark lanes deepen and the bright core stands out. Inspect the faint outer dust before keeping the full effect.

Saturation

Each channel moves away from the working-space luminance. Use a factor of 1 to keep the incoming color or 0 for gray.

One for RGB max(l + (t - l) * 1.4, 0)

Compare the cool reflection around the core with the warm dust below it. The factor of 1.4 increases their color difference.

White balance

Raise red by 10%, keep green and lower blue by 10%. Adjust the gains to suit the cast you see.

Red
r * 1.1
Green
g
Blue
b * 0.9
The dust warms across the frame. Check the blue reflection too, since these gains affect the whole group.

Green reduction

Cap green at whichever is brighter, red or blue. Red and blue pass through.

Red
r
Green
min(g, max(r, b))
Blue
b
For this comparison, H-alpha supplies red, oxygen green and sulfur blue. The green filament loses much of its color. Leave this template off when green represents oxygen you want to show.

Invert

Subtract each channel from 1. Black and SDR white exchange places.

One for RGB ~t

The dark dust appears light and the bright core becomes dark. Follow a lane in the negative view, then toggle the adjustment off to return to the original tones.

Foraxx, SHO

Requires SII, Ha and OIII. Oxygen sets the red mix between sulfur and hydrogen. The overlap between hydrogen and oxygen sets the green mix. Blue comes from oxygen.

Red
m = OIII ^ ~OIII; m * SII + ~m * Ha
Green
p = Ha * OIII; m = p ^ ~p; m * Ha + ~m * OIII
Blue
OIII
The blue-violet rim in the SHO starting picture becomes teal, while patches inside turn red. Each output channel reads the named inputs, so this template replaces the incoming color.

Foraxx, HOO

Requires Ha and OIII. Red comes from hydrogen and blue from oxygen. Where both lines are strong, more hydrogen contributes to green.

Red
Ha
Green
p = Ha * OIII; m = p ^ ~p; m * Ha + ~m * OIII
Blue
OIII
The pale bank left of the dark inlet shifts from cyan toward a paler, warmer tone. Compare the same bank in both views to see the smaller change from an existing HOO mix.

Ha into red

Requires Ha. Only the red expression changes. A pixel takes the brighter of broadband red and stretched H-alpha.

Red
max(r, Ha)
Green
g
Blue
b
The bright rim turns red while the center of the dark lane changes very little. See the Split fields and the marked rim.

OIII into green and blue

Requires OIII. Compare oxygen independently with green and blue and keep the brighter value in each. Red passes through.

Red
r
Green
max(g, OIII)
Blue
max(b, OIII)
From exactly the same broadband starting picture as Ha into red, the oxygen-rich bank now turns cyan. The dark cavity shows much less change.

Work through three edits

Lift faint RGB nebulosity

On an SDR RGB composition such as the Iris Nebula, choose One for RGB and enter mtf(0.4, t). A channel value of 0.4 moves to 0.5 while black and white stay fixed. This gives the dust more separation from a dark background. Compare the dust with an adjacent dark pocket. If the pocket brightens too much, move 0.4 toward 0.5 or lower the layer’s opacity. If you separated stars, put the adjustment above the starless picture and below the returned stars to preserve their existing stretch.

Lifted Iris reflection with a fold marked Dust and a dark pocket marked beside it.
Compare the two marks after applying mtf(0.4, t). The fold brightens enough to trace toward the core. The dark pocket also lifts slightly. If it starts competing with the dust, reduce the lift.

Add H-alpha to broadband red

With a broadband picture and a stretched H-alpha input, choose Split. Enter max(r, Ha) for Red, g for Green and b for Blue. At a pixel with red 0.30 and H-alpha 0.55, red becomes 0.55. Where H-alpha is weaker, the broadband red passes through. Compare the nebula with nearby sky. If both turn red, review the H-alpha background and stretch before raising its contribution.

The marked rim gains red from H-alpha. The dark lane stays close to the broadband starting color. Compare the unmarked broadband and H-alpha views.

Limit an adjustment to oxygen emission

In a narrowband document with OIII, select the adjustment you want to limit. Choose New mask for this layer and enter rescale(OIII, 0.1, 0.5) in the mask’s Pixel math field. Choose Mask to inspect it. An oxygen value of 0.1 gives black, 0.3 gives half coverage and 0.5 gives white. The gradual transition lets a color adjustment follow a filament without a hard edge. These bounds are starting values. Raise the low bound if the sky appears gray, or lower the high bound if the filament receives too little of the adjustment.

In SNR G132 the strand is bright in this mask and the marked sky is black. The gray edges give the adjustment partial coverage. This capture uses Reach 1.00 and Smoothing 0.0 px.

Choose Picture and compare the filament and the surrounding background. An edit to the oxygen input’s stretch also changes this mask. Adjust Reach to extend coverage into fainter signal and Smoothing to soften visible speckle. Choosing another Shape or changing the mask’s input shortcuts replaces its custom expression.

For this example, the top adjustment uses mtf(0.25, t) in One for RGB. White and gray in the oxygen mask let it brighten the strand. The black mask at the sky mark keeps the sky at its previous level.