0

When I take pictures with my camera the file sizes seem exceedingly large. In this example the original is 5186kb. I wrote a java program to just read the image and then write it again, removing any information except the pixel values.

The first time it is rewritten, the file size goes down to 1005kb, over a 500% reduction! To make sure I wasn't losing data to compression I iterated the program 100 times on the resulting images and the file size stayed at exactly 1005kb with no loss in image quality.

My question is, what is the camera storing in the other 4181kb? Some sort of metadata I know, but it seems like a lot. I would like to know what I am losing by resizing my images like this.

ZGorlock
  • 544
  • 4
  • 11
  • 1
    Are you sure you're not re-compressing the file? My older Nikon 5100 saves jpegs at about that size (RAW files are even bigger) and it's definitely not 4megs of non-image data. Try using something like [ImageMagick Compare function](https://imagemagick.org/script/compare.php) to get the actual pixel level difference between the before and after picture. – StarGeek Jan 31 '21 at 23:08
  • I did the comparison and there is a lot of red, so it is compressing an uncompressed jpg? Visually the two files look identical to me, and why does it only resize it the first time and not subsequent iterations? The code I am using is just this: BufferedImage image = ImageIO.read(source); image.getGraphics().drawImage(image, 0, 0, null); ImageIO.write(image, "jpg", target); – ZGorlock Feb 01 '21 at 01:32
  • Here are the image files I am using. Original:https://drive.google.com/file/d/12gJMGVcaegEqLR4Cn0tvHdTODPvPpVal/view?usp=sharing Result:https://drive.google.com/file/d/1HrdZ8Zu9GjQnK-w2I5pQUxMhwoI_K5On/view?usp=sharing Diff:https://drive.google.com/file/d/1bZTMUCM2IqEdW_c8y8IutvPRdQ5lvT2G/view?usp=sharing – ZGorlock Feb 01 '21 at 01:36
  • 1
    Jpegs are, by definition compressed images. Additionally, such compression is "Lossy", meaning each time you re-compress the image, you are losing more and more image data (which leads to the [needs more jpeg meme](https://knowyourmeme.com/memes/needs-more-jpeg)). See [this Photo.StackExchange](https://photo.stackexchange.com/questions/99604/what-factors-cause-or-prevent-generational-loss-when-jpegs-are-recompressed-mu) question for details. The tl;dr is that your code is damaging your images. It's up to you to decide if the trade off for small files it worth it. – StarGeek Feb 01 '21 at 02:24
  • Ok thanks, I knew I was losing something I was just interested in *what* I was losing so I could make that decision. The weird thing to me is that if I run it through once, or if I run it through 1000 times, the output is the same. – ZGorlock Feb 01 '21 at 02:29

1 Answers1

1

Assuming the file format you are using is .jpg, the original file was saved in a higher value of jpg compression say 95%, while when you resave the file, you probably were using say 85% jpg compression value.

The size doesn't change in consequent saves as the compression value stays the same

AliWieckowicz
  • 549
  • 1
  • 4
  • 17