1 year ago
#210645

Manjunath K Mayya
Lossless Image compression in python using Open CV or any other modules
I want to perform lossless compression on the image Example image attached here. It is a 16 bit image of 1024*1024.
I realized that lossless compression is possible using PNG format with Open CV. Open CV allows compression using a compression attribute, which can be set between 0 to 9 to vary the compression. But the compression is not much. Below is the code that I used and screenshot of file sizes of actual image, image compressed with value 9 and image compressed with value 0.
Code
import numpy as np
import os, cv2, sys
actual_image_in_png_format = os.path.join(os.getcwd(), 'actual_image.png')
src = cv2.imread(actual_image_in_png_format,cv2.IMREAD_UNCHANGED)
cv2.imwrite("PNG_COMPRESSION_9.png", src, [cv2.IMWRITE_PNG_COMPRESSION, 9])
cv2.imwrite("PNG_COMPRESSION_0.png", src, [cv2.IMWRITE_PNG_COMPRESSION, 0])
My question is that, is it possible to get a higher lossless compression using Open CV or any other python modules.
Thanks in advance.
python
opencv
lossless-compression
0 Answers
Your Answer