Am I creating lossless PNG images?

While png is lossless, this does not mean it is uncompressed by default.

I specify compression using the IMWRITE_PNG_COMPRESSION flag. It varies between 0 (no compression) and 9 (maximum compression). So if you want uncompressed png:

cv2.imwrite(filename, data, [cv2.IMWRITE_PNG_COMPRESSION, 0])

The more you compress, the longer it takes to save.

Link to docs


PNG is a lossless format by design:

Since PNG's compression is fully lossless--and since it supports up to 48-bit truecolor or 16-bit grayscale--saving, restoring and re-saving an image will not degrade its quality, unlike standard JPEG (even at its highest quality settings).

The encoder and decoder should not matter, in regards of reading the images correctly. (Assuming, of course, they're not buggy).

And unlike TIFF, the PNG specification leaves no room for implementors to pick and choose what features they'll support; the result is that a PNG image saved in one app is readable in any other PNG-supporting application.