Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust brightness and contrast of BufferedImage in Java

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?

like image 795
a paid nerd Avatar asked Aug 08 '10 06:08

a paid nerd


People also ask

How do I increase contrast in Java?

Invoke the convertTo() method by passing the empty matrix, -1 (to get the same type), alpha value to increase or decrease contrast (0-1 or, 1-100) and, 0 as beta value.

What is the difference between image and BufferedImage in Java?

If you are familiar with Java's util. List, the difference between Image and BufferedImage is the same as the difference between List and LinkedList. Image is a generic concept and BufferedImage is the concrete implementation of the generic concept; kind of like BMW is a make of a Car.

What is image brightness and contrast?

Brightness refers to the overall lightness or darkness of the image. Use the Brightness slider to adjust your image's luminosity level. Contrast is the difference in brightness between objects or regions.

How do I darken the contrast of a picture?

Click the picture that you want to change the contrast for. Under Picture Tools, on the Format tab, in the Adjust group, click Contrast. Click the contrast percentage that you want.


1 Answers

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.

like image 122
a paid nerd Avatar answered Sep 29 '22 00:09

a paid nerd