0

I am using python to compress an image to varying degrees ( or quality ) . I have implemented it based on OpenCV:

def compressAndwrite(save_path, img, quality):
    '''
    save_path: string
    img: np.ndarray
    quality: int, 0-100
    '''
    cv2.imwrite(save_path, img, [int(cv2.IMWRITE_JPEG_QUALITY), quality])

Is there any way that I can use libjpeg in python to achieve the same effect instead of PIL or OpenCV?

If not, how can I compress and write an jpeg image using JPEG algorithm when given a parameter quality?

one dog
  • 1
  • 1
  • Can you clarify why you don't want to use OpenCV or PIL please? – Mark Setchell Oct 20 '21 at 09:01
  • Thank you for your answer sincerely. My ultimate goal is to compress an image to different degrees using JPEG algorithm. I have no idea how `cv2.imwrite` in OpenCV and `imObj.save` in PIL work to control the quality or compression ratio of the saved image relative to the original image. So I have to use `libjpeg` to do it. – one dog Oct 21 '21 at 03:31
  • This may help https://stackoverflow.com/a/52281257/2836621 – Mark Setchell Oct 21 '21 at 06:00
  • This is the most comprehensive discussion of JPEG that I know https://www.youtube.com/watch?v=CPT4FSkFUgs – Mark Setchell Oct 21 '21 at 06:02

0 Answers0