imgaug
imgaug copied to clipboard
in-memory JPEG augmentations
Hi, it seems JPEG augmentations are using temporary file on disk to do the JPEG compression: https://github.com/aleju/imgaug/blob/0101108d4fed06bc5056c4a03e2bcb0216dac326/imgaug/augmenters/arithmetic.py#L1747
This can be done in-memory (-> probably more efficiently) using io.BytesIO()
. Something like the following:
import io
from PIL import Image
import numpy as np
pil_image = Image.fromarray(np_rgb_img)
buf = io.BytesIO()
pil_image.save(buf, format='JPEG', quality=0.25)
pil_image = Image.open(buf)
np_img_with_compression = np.asarray(pil_image)