Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Gamma and brightness are not the same operations. Brightness is a linear operation, gamma is nonlinear; gamma affects only the grays.

However I think there are several different operations to change the brightness of an image:

  1. Add or substract a constant. Take care of the overflow (values above 255 must be truncated to 255; negative values to 0). This is basically your method 2.

    A variant would be to work in the HSV color space and change the V channel, then go back to RGB (your method 1).

    The drawback of this method is that it clips the image to 0 or 255.

  2. Multiply the image with a constant. This is similar to berak's suggestion, but the formula is a bit different for lightening.

    The algorithm is: if the value<1 (darken), then image_out=image_in*value

    If value>1 (lighten) then v2=2-value and image_out=image_in*v2+(1-v2)*255

    This method won't clip the image. Most programs use this method.

For all these operations you can use direct operations or color lookup (creating LUTs). I didn't test which solution is faster.

Gamma and brightness are not the same operations. Brightness is a linear operation, gamma is nonlinear; gamma affects only the grays.

However I think there are several different operations to change the brightness of an image:

  1. Add or substract a constant. Take care of the overflow (values above 255 must be truncated to 255; negative values to 0). This is basically your method 2.

    A variant would be to work in the HSV color space and change the V channel, then go back to RGB (your method 1).

    The drawback of this method is that it clips the image to 0 or 255.

  2. Multiply the image with a constant. constant (between 0 and 2). This is similar to berak's suggestion, but the formula is a bit different for lightening.

    The algorithm is: if the value<1 (darken), then image_out=image_in*value

    If value>1 (lighten) then v2=2-value and image_out=image_in*v2+(1-v2)*255

    This method won't clip the image. Most programs use this method.

For all these operations you can use direct operations or color lookup (creating LUTs). I didn't test which solution is faster.