# Do different png compression rates result in different images?

I have some ImageNet 2012 images in JPEG. I was only using imread and imwrite to convert them to png with different compression rates (both in C++ and python):

>

import cv2

import numpy as np

img = cv2.resize(img.astype(np.float32), (227,227),interpolation=cv2.INTER_CUBIC)

cv2.imwrite("newimg1.png", img, [cv2.IMWRITE_PNG_COMPRESSION, 9])

cv2.imwrite("newimg2.png", img, [cv2.IMWRITE_PNG_COMPRESSION, 0])


>

However, I have noticed that:

1. If I use a low compression rate (e.g.,0), the output images will be all in the same size (while they have different sizes before processing by cv). Why this happened?

2. I know that png compression is lossless so by doing imwrite with different compression rates, I should obtain identical images (e.g., exactly the same pixel value in each pixel(i, j)). I validated this by using different image input pipelines and found it is true. However, I wonder if different compression rates can result in other different features beyond pixel values. (I doubt this since later on I was using two batches of png images which only differ in compression rates for a specific task and expecting they two could give similar results while they didn't.)

Thanks.

Example images:

Original JPEG image Resized and compressed with rate 9 Resized and compressed with rate 0

According to my test, the last two images are identical but in different sizes.

edit retag close merge delete

1

I have some ImageNet 2012 images in JPEG

that's already lossy, and you can't recover the original pixel values.

then, without code / image examples, we can't know, what you're doing.

( 2019-05-31 00:28:28 -0500 )edit

Thanks for reply. Added the code and image examples. The dataset comes with JPEG so nothing I can do with it. To first convert the images to png, I was meant to avoid any further loss in quality.

( 2019-05-31 01:44:16 -0500 )edit
1

I don't think it's something to be concerned about: PNG compression is lossless.

( 2019-05-31 10:33:56 -0500 )edit