imgaug icon indicating copy to clipboard operation
imgaug copied to clipboard

in-memory JPEG augmentations

Open serycjon opened this issue 2 years ago • 0 comments

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)

serycjon avatar Feb 28 '22 15:02 serycjon