Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in-memory JPEG augmentations #811

Open
serycjon opened this issue Feb 28, 2022 · 0 comments
Open

in-memory JPEG augmentations #811

serycjon opened this issue Feb 28, 2022 · 0 comments

Comments

@serycjon
Copy link

Hi, it seems JPEG augmentations are using temporary file on disk to do the JPEG compression:

with tempfile.NamedTemporaryFile(mode="wb+", suffix=".jpg") as f:

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant