Image lookup table (source code)

= Image lookup table

An \b[image lookup table] maps a stored pixel value or index to a displayed color. For an 8-bit <grayscale> image with stored values $I_{ij}\in\{0,\ldots,255\}$, a table can be written
$$
C:\{0,\ldots,255\}\longrightarrow\{0,\ldots,255\}^3,
\qquad
\text{displayed color at }(i,j)=C(I_{ij}),
$$
using an <RGB color model> triple. Changing $C$ changes the appearance without necessarily changing $I$. <ImageJ> explicitly distinguishes Invert LUT, which changes the display, from inversion of the pixel values.<ImageJ User Guide by Tiago Ferreira and Wayne Rasband>[IJ1.46r, section28.15.1, Invert LUT; section27.11, Invert]{ref}

For an original example, store the row
$$
I=(0,64,128,255).
$$
The identity grayscale table is $C(v)=(v,v,v)$; an inverted table is $C_{\rm inv}(v)=(255-v,255-v,255-v)$. The same four stored values appear in opposite brightness order under these tables, but their <arithmetic mean> remains $447/4=111.75$. An <image thresholding> rule selecting stored values above 100 still gives the <binary selection mask> $(0,0,1,1)$.

Numerically replacing the pixels by $255-I$ instead produces $(255,191,127,0)$. Its <arithmetic mean> is $573/4=143.25$, and the same strict threshold gives $(1,1,1,0)$. Thus an inverted-looking image does not by itself establish that its numerical values or selected subset were inverted.

The distinction is especially visible with <binary selection masks>: the documented Create Mask command stores 255 inside the selection and 0 outside, while an inverting lookup table can display the selected class as black.<ImageJ User Guide by Tiago Ferreira and Wayne Rasband>[Section27.12.10, Create Mask]{ref} Record the <foreground-background polarity> from the stored encoding and algorithm, rather than inferring it from screen brightness.

A program can also apply a lookup mapping to the data. ImageJ's Apply LUT command changes gray values and restores the identity table so that the displayed appearance is retained.<ImageJ User Guide by Tiago Ferreira and Wayne Rasband>[Section28.15.2, Apply LUT]{ref} Distinguish that operation from assigning a display table. A table mapping several input values to the same color can conceal numerical distinctions in the display even while those distinctions remain in the original stored image.