How to change the contrast and brightness of an image stored as pixel values

后端 未结 1 921
萌比男神i
萌比男神i 2021-01-06 06:35

I have an image that is stored as an array of pixel values. I want to be able to apply a brightness or contrast filter to this image. Is there any simple way, or algorithm,

相关标签:
1条回答
  • 2021-01-06 07:01

    My suggestion would be to use the built-in methods of Java to adjust the brightness and contrast, rather than trying to adjust the pixel values yourself. It seems pretty easy by doing something like this...

    float brightenFactor = 1.2f
    
    PlanarImage img=JAI.create("fileload","C:\\aimages\\blue_water.jpg");
    BufferedImage image = img.getAsBufferedImage();
    
    RescaleOp op = new RescaleOp(brightenFactor, 0, null);
    image = op.filter(image, image);
    

    The float number is a percentage of the brightness. In my example it would increase the brightness to 120% of the existing value (ie. 20% brighter than the original image)

    See this link for a similar question... Adjust brightness and contrast of BufferedImage in Java

    See this link for an example application... http://www.java2s.com/Code/Java/Advanced-Graphics/BrightnessIncreaseDemo.htm

    0 讨论(0)
提交回复
热议问题