0

I encountered a weird problem: I converted a ppm file into png, jpg, and bmp. Visually, png, jpg, and bmp files look darker. I thought it was something wrong with the pixels so I use the following code to print out the pixels of the png file,

public class testMethods {
  public static void main(String[] args) throws IOException {
    File file = new File("res/35blur.png");
    BufferedImage image = ImageIO.read(file);

    for (int i = 0; i < image.getHeight(); i++) {
      for (int j = 0; j < image.getWidth(); j++) {
        int firstPixel = image.getRGB(j, i);
        int red = (firstPixel >> 16) & 0xFF;
        int green = (firstPixel >> 8) & 0xFF;
        int blue = firstPixel & 0xFF;
        System.out.println(red);
        System.out.println(green);
        System.out.println(blue);
      }
    }
  }
}

But the output are the same as the rgb values in the ppm file. Anyone know what could possibly be the reason for this?

enter image description here

d0nut
  • 29
  • 1
  • 5
  • How did you obtain the pixel values from the ppm file, and how was it converted? The software used to open/view the ppm file may simply have a filter on it that is not representative of real-world values. There was also an issue in the past (not sure if it still exists) where photoshop would incorrectly save PPM files with brighter colours compared to other comment formats that appeared darker. – sorifiend Jun 13 '22 at 01:04
  • 1
    Could it be related to https://stackoverflow.com/q/62046921 ? – Dawood ibn Kareem Jun 13 '22 at 01:11
  • @sorifiend the way I obtain pixels from the ppm file is by using scanner to read the ppm file line by line. Then, the way I convert it to a png file is by setting those rgb values to the corresponding pixels in a bufferedImage. I write a file using that bufferedImage – d0nut Jun 13 '22 at 01:30
  • @DawoodibnKareem my ppm is P3 – d0nut Jun 13 '22 at 01:31
  • Different color spaces, probably, How did you convert your PPM to PNG? – Harald K Jun 17 '22 at 15:16

0 Answers0