OpenCV image quality
Code:
1) Compression method
cv2.imwrite('yahboomTest.jpg', img, [cv2.IMWRITE_JPEG_QUALITY, 50])
cv2.CV_IMWRITE_JPEG_QUALITY: Set the picture(.jpeg or .jpg) quality, value range is 0--100 (the larger the value, the higher the quality). Default value is 95
cv2.CV_IMWRITE_WEBP_QUALITY: Set the picture(.web) quality, value range is 0--100 (the larger the value, the higher the quality).
cv2.CV_IMWRITE_PNG_COMPRESSION: Set the picture(.png) quality, value range is 0--100 (the larger the value, the higher Compression ratio). Default value is 3.
import cv2 img = cv2.imread('yahboom.jpg',1) cv2.imwrite('yahboomTest.jpg', img, [cv2.IMWRITE_JPEG_QUALITY, 50]) #1M 100k 10k 0-100 Lossy compression
|
# 1 Lossy compression, 2 Transparency attribute import cv2 img = cv2.imread('yahboom.jpg',1) cv2.imwrite('yahboomTest.png', img, [cv2.IMWRITE_PNG_COMPRESSION,0]) # jpg 0 High compression ratio 0-100 png 0 Low compression ratio 0-9
|
#bgr8 to jpeg format import enum import cv2 def bgr8_to_jpeg(value, quality=75): return bytes(cv2.imencode('.jpg', value)[1])
|
import ipywidgets.widgets as widgets image_widget1 = widgets.Image(format='jpg', ) image_widget2 = widgets.Image(format='jpg', ) # create a horizontal box container to place the image widget next to eachother image_container = widgets.HBox([image_widget1, image_widget2]) # display the container in this cell's output display(image_container) img1 = cv2.imread('yahboomTest.jpg',1) img2 = cv2.imread('yahboomTest.png',1) image_widget1.value = bgr8_to_jpeg(img1) image_widget2.value = bgr8_to_jpeg(img2)
|
