# Revision history [back]

### Do different png compression rates result in different images?

I have some ImageNet 2012 images in JPEG. I was using two lines of simple code: imread and imwrite to convert them to png with different compression rates. 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.

### Do different png compression rates result in different images?

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

import cv2 import numpy as np

img = cv2.imread("img.JPEG") 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.

### 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.imread("img.JPEG") 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.

### 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 cv2

import numpy as np

img = cv2.resize(img.astype(np.float32), (227,227),interpolation=cv2.INTER_CUBIC) (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.

### 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.

 6 None supra56 945 ●9 ●6

### 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                            cv2

import numpy as np np

img = cv2.resize(img.astype(np.float32), (227,227),interpolation=cv2.INTER_CUBIC) (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]) 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.