When rendering or generating a volume, each gray value needs to be mapped to a specific color with a certain opacity. This is performed using a transfer function, which assigns RGB values and opacity to every voxel in the volume. By applying the transfer function, the 3D volume is visualized. More information can be found in this article on volume rendering.