如何更改存储为像素值的图像的对比度和亮度 [英] How to change the contrast and brightness of an image stored as pixel values

查看:234
本文介绍了如何更改存储为像素值的图像的对比度和亮度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储为像素值数组的图像。我希望能够对此图像应用亮度或对比度滤镜。是否有任何简单的方法或算法可用于实现此目的。

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, that I can use to achieve this.

这是我的代码......

Here is my code...

   PlanarImage img=JAI.create("fileload","C:\\aimages\\blue_water.jpg");
   BufferedImage image = img.getAsBufferedImage();

   int w = image.getWidth();
   int h = image.getHeight();
   int k = 0;

   int[] sbins = new int[256];
   int[] pixel = new int[3];

   Double d = 0.0;
   Double d1;
   for (int x = 0; x < bi.getWidth(); x++) {
       for (int y = 0; y < bi.getHeight(); y++) {
           pixel = bi.getRaster().getPixel(x, y, new int[3]);
           k = (int) ((0.2125 * pixel[0]) + (0.7154 * pixel[1]) + (0.072 * pixel[2]));
           sbins[k]++;
       }
   }


推荐答案

我的建议使用Java的内置方法来调整亮度和对比度,而不是尝试自己调整像素值。做这样的事情似乎很容易......

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);

浮点数是亮度的百分比。在我的例子中,它会将亮度增加到现有值的120%(即比原始图像亮20%)

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)

有关类似问题,请参阅此链接。 。
用Java调整BufferedImage的亮度和对比度

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

请参阅此链接以获取示例应用程序...
http://www.java2s.com/Code/Java/Advanced-Graphics/BrightnessIncreaseDemo.htm

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

这篇关于如何更改存储为像素值的图像的对比度和亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆