13

I'm processing a bunch of images with some framework, and all I'm given is a bunch of BufferedImage objects. Unfortunately, these images are really dim, and I'd like to brighten them up and adjust the contrast a little.

Something like:

BufferedImage image = something.getImage();
image = new Brighten(image).brighten(0.3); // for 30%
image = new Contrast(image).contrast(0.3);
// ...

Any ideas?

26

That was easy, actually.

RescaleOp rescaleOp = new RescaleOp(1.2f, 15, null);
rescaleOp.filter(image, image);  // Source and destination are the same.

A scaleFactor of 1.2 and offset of 15 seems to make the image about a stop brighter.

Yay!

Read more in the docs for RescaleOp.

5
  • What is a range of scaleFactor and offset? – Marcin Erbel Oct 10 '13 at 17:18
  • 3
    @ADTC photographymad.com/pages/view/… – a paid nerd Aug 6 '15 at 16:46
  • 1
    Scale of 1.2 is +20%. Every value is multiplied by 1.2, so what used to be 100% becomes 120% (quoting javadoc on RescaleOp, "dstElement = (srcElement*scaleFactor) + offset") – mvmn Jan 2 '17 at 22:50
  • Offset 15 is not that clear though, this may need an adjustment depending on a color channel sample size for a particular BufferedImage. – mvmn Jan 2 '17 at 22:50
  • is Offset value 15 is used to change the contrast of the image – Siva Jun 23 '17 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.