Greyscale JPG: Scaled image gets brighter
See original GitHub issueHello,
After reading, rescaling, and writing a JPG, the brightness gets changed. If the rescaling is skipped, the brightness is correct.
This is one of our test-images: https://upload.wikimedia.org/wikipedia/commons/thumb/f/f2/Broadway_tower_grayscale.jpg/256px-Broadway_tower_grayscale.jpg (The other we cannot share)
This only seems to happen with the color-model grey.
Interestingly, it also happens when Image.getScaledInstance is used.
public static void main(String ... args) throws Exception {
Iterator<ImageReader> readers = ImageIO.getImageReaders(ImageIO.createImageInputStream(new FileInputStream(new java.io.File("/Users/x1fkirma/test2/original.jpg"))));
int i = 0;
while(readers.hasNext()) {
i += 1;
ImageReader reader = readers.next();
System.out.println("Reader: " + reader);
reader.setInput(ImageIO.createImageInputStream(new FileInputStream(new java.io.File("/Users/x1fkirma/test2/tower.jpg"))));
BufferedImage input = reader.read(0);
//twelvemonkey
BufferedImage result = com.twelvemonkeys.image.ImageUtil.createScaled(input, 875, 583, Image.SCALE_DEFAULT);
//java.awt.rescale
//java.awt.Image img = input.getScaledInstance(875, 583, java.awt.Image.SCALE_SMOOTH);
//BufferedImage result = new BufferedImage(875, 583, input.getType());
//Graphics2D g2 = result.createGraphics();
//g2.drawImage(img, 0, 0, null);
//g2.dispose();
javax.imageio.ImageIO.write(result, "jpg", new java.io.File("/Users/x1fkirma/test2/scaled_" + i + ".jpg"));
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Grayscale images appear brighter in Photoshop than after ...
Go to Edit menu and go down the list drop-down menu and see what color space you are in. The order I use...
Read more >Gray scale images - Medium
In this post, we will learn how to create gray-scale images. A gray-scale (or gray level) image is simply one in which the...
Read more >How to alter the brightness of a grey scale image?
Following Java program reads a colored image as greyscale, saves it, normalizes the brightness and increases the contrast of the given image ......
Read more >Image conversion to Grayscale using ImageMagick is very dark
I converted a bunch of "normal" JPG photos via ... Is there a better way to convert a photo-realistic image with ImageMagick to...
Read more >Image-6 Grayscale
Grayscale Conversion Algorithm · Pixel's average is effectively a "brightness" number 0..255 · Summarizes the 3 red/green/blue numbers as one number · To...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You are right, it’s my fault. It works properly with ResampleOp. Sorry for the confusion. I was properly confused because the image already looked “light greyish”. I assume ResampleOp is the method which is also recommended to rescale an image?
@haraldk I’ve looked more into the topic and noticed the behavior depends on the performance hints. I’ve found the following cases: ImageUtil:
ResampleOp with the following RenderingHints, and filter is called with the second argument as null:
ResampleOp seems to work in all cases when the second argument for filter is a pre created BufferedImage, created like the following: