deface icon indicating copy to clipboard operation
deface copied to clipboard

File size increase

Open Tralapo opened this issue 3 years ago • 3 comments

I've been experimenting with this tool, it works amazing. I'm testing deface to run on jpg images downloaded from a webcam.

I noticed quite a file size increase on these jpg's: Original: 435kb Deface: 610kb - without any faces in the picture

Although it doesn't look like much, I'm planning on using this on quite a scale, which makes the total increased data storage quite large and I would like to avoid that where possible.

Any ideas what might increase the file size, even without faces on them?

Tralapo avatar Jun 03 '21 10:06 Tralapo

To save the resulting image it has to be completely re-encoded, so both size changes and a slight drop in image quality can be expected.

The relevant code line for saving anonymization results to new images is here: https://github.com/ORB-HD/deface/blob/f668068b1ac4598f91dc9ceacfbf86d2a2f1d40e/deface/deface.py#L183

imsave() is an alias to imwrite, which is documented at https://imageio.readthedocs.io/en/stable/userapi.html#imageio.imwrite. Here you see that you can pass image format-specific options through the **kwargs, e.g. for .jpg see here: https://imageio.readthedocs.io/en/stable/format_jpeg-pil.html#parameters-for-saving

For decreasing the output file sizes, I would try lowering the quality setting to something lower than 75.

Can you change the line referenced above to something like

imageio.imwrite(opath, frame, optimize=True, quality=50)

and report if it works?

We can also make this configurable through a command line flag similar to the --ffmpeg-config option, which already exists to control video output codec options.

mdraw avatar Jun 17 '21 01:06 mdraw

Sorry, I see I forgot to reply. For now I decided not to go ahead with this package. Although it would be great to make it more easily configurable, as the file size difference is quite big.

Tralapo avatar Jul 14 '21 10:07 Tralapo

@mdraw maybe a option to run the images through https://github.com/tjko/jpegoptim or http://optipng.sourceforge.net/ would be great.

frankenstein91 avatar Sep 23 '22 12:09 frankenstein91