This simple custom transformer uses the following expression for adjusting brightness and contrast of an image:
if (brightness < 0.0)
value = value * ( 1.0 + brightness);
else
value = value + ((1.0 - value) * brightness);
value = (value - 0.5) * (tan ((contrast + 1) * PI/4) ) + 0.5;
where value is the input color value in the 0..1 range and brightness and contrast are in the -1..1 range;
From
http://en.wikipedia.org/wiki/Image_editing#Contrast_change_and_brightening.
The expression comes from
GIMP, free software raster graphics editor.
Less bright and less contrast
b = -0.3
c = -0.2
Original
Brighter and more contrast
b = 0.2
c = 0.5
Note that the transformer only works with RGB interpretations such as RGB24 and RGB48. The
RasterExpressionEvaluator cannot take expressions from an attribute. If it could (or will be able in the future), we could analyze a raster with
RasterBandPropertiesExtractor, and construct an expression suitable for a particular raster interpretation.
This transformer contains one of the longest conditions I've ever written for the
RasterExpressionEvaluator, check it out:
if(A:_brightness<0.0, (((1/(A:_num_of_colors)*A[0]*(1.0 + A:_brightness)) - 0.5) * (tan((A:_contrast + 1) * 3.14159/4.0))+0.5)*A:_num_of_colors, ((((1/A:_num_of_colors*A[0] + ((1.0- 1/A:_num_of_colors*A[0])*A:_brightness))) - 0.5) * (tan((A:_contrast + 1) * 3.14159/4.0))+0.5)*A:_num_of_colors);if(A:_brightness<0.0, (((1/A:_num_of_colors*A[1]*(1.0 + A:_brightness)) - 0.5) * (tan((A:_contrast + 1) * 3.14159/4.0))+0.5)*A:_num_of_colors, ((((1/A:_num_of_colors*A[1] + ((1.0- 1/A:_num_of_colors*A[1])*A:_brightness))) - 0.5) * (tan((A:_contrast + 1) * 3.14159/4.0))+0.5)*A:_num_of_colors);if(A:_brightness<0.0, (((1/A:_num_of_colors*A[2]*(1.0 + A:_brightness)) - 0.5) * (tan((A:_contrast + 1) * 3.14159/4.0))+0.5)*A:_num_of_colors, ((((1/A:_num_of_colors*A[2] + ((1.0- 1/A:_num_of_colors*A[2])*A:_brightness))) - 0.5) * (tan((A:_contrast + 1) * 3.14159/4.0))+0.5)*A:_num_of_colors)