Class Brightness


  • public class Brightness
    extends LookupTableOperation
    Adjusts the brightness of an image.

    The brightness change is specified as a percentage value between -100 and 100. -100 will make the resulting image black, 0 will leave it unchanged, 100 will make it white.

    Supported image types

    Usage examples

    Both examples make the input image 30 percent brighter.

    If all you want is to create a new image with adjusted brightness from the image data of an existing image, simply use the static helper method:

    PixelImage adjustedImage = Brightness.adjust(inputImage, 30);
    This leaves the original image inputImage unchanged and allocates a second image object which is here assigned to the variable adjustedImage.

    If you want more control over parameters, create your own Brightness object. You can then reuse image objects, e.g. to write the adjusted image data to the original image object:

     Brightness brightness = new Brightness();
     brightness.setInputImage(image);
     brightness.setOutputImage(image);
     brightness.setBrightness(30);
     brightness.process();
     // at this point, image will contain the adjusted image data,
     // the original data wil be overwritten 
     

    Author:
    Marco Schmidt
    • Field Detail

      • brightness

        private int brightness
    • Constructor Detail

      • Brightness

        public Brightness()
    • Method Detail

      • adjust

        public static PixelImage adjust​(PixelImage input,
                                        int percentage)
        This static helper method is more simple to use when all you need are the standard options.
        Parameters:
        input - the image to work on
        percentage - brightness modification, from -100 to 100
        Returns:
        a new image with adjusted brightness
      • createLookupTable

        private int[] createLookupTable​(int numSamples,
                                        int brightness)
        Creates a lookup table that holds all new values for samples 0 to numSamples - 1.
      • setBrightness

        public void setBrightness​(int newBrightness)
        Sets the brightness adjustment value in percent (between -100 and 100).
        Parameters:
        newBrightness - the amount of change to be applied to the brightness of the input image
        Throws:
        IllegalArgumentException - if the argument is smaller than -100 or larger than 100