16

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?

a paid nerd
  • 30,702
  • 30
  • 134
  • 179

1 Answers1

28

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.

a paid nerd
  • 30,702
  • 30
  • 134
  • 179
  • What is a range of scaleFactor and offset? – Marcin Erbel Oct 10 '13 at 17:18
  • 3
    @ADTC http://www.photographymad.com/pages/view/what-is-a-stop-of-exposure-in-photography – a paid nerd Aug 06 '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 02 '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 02 '17 at 22:50
  • is Offset value 15 is used to change the contrast of the image – Siva Jun 23 '17 at 07:24