Java Program to Increase or Decrease Brightness of an Image
Before understanding how the brightness is adjusted in any image first we have to understand how an image is represented. image is represented in the 2D form of a pixel, a pixel is the smallest element of an image. the value of pixel at any point corresponds to the intensity of light of the photons striking at that point. every pixel stores N-bit unsigned int value where N is the depth of the image (8-bit image, 16-bit image, 24-bit image). the value of pixel can vary from 0 to 255 for the 8-bit image where 0 corresponds to black and 255 corresponds to white. each pixel color is made up of a combination of RGB values. Brightness is nothing but how much the light perceive by an image.
Brightness of an image can be increase or decrease by just increasing or decreasing the RGB value of an image pixel.the value of brightness will usually be in the range of -255 to +255. Negative values will darken the image and positive values will brighten the image.
We need to follow 3 steps sequentially as listed below as follows:
- Read the image using ImageIO class
- Getting the width and height of the image and loop through each and every pixel
- Getting the RGB value of each pixel to add the amount of brightness
Consider a sample arbitrary input image with which we will be playing to increase or either away decrease its contrast to illustrate change.
Output: Bright Image