0

We develop a web application where users upload all kinds of images (photos, technical drawings, comics, line drawings ... everything you can think of). Unfortunately the users do not care about choosing the right file format for the image's content (in fact, they probably do not know that different image formats even exist).

I wonder if there is a way to automatically (without human interaction) detect the best file format (jpeg or png) depending on the image's content. The definition of "best" considers the visual quality in a web context and the file's size.

In other words, this question is similiar to the "Need to preserve finde detail" branch in Google's Image File Format Decision Tree.

This question is not about compressing/optimizing images with tools like pngcrush, pngquant, jpegtran, jpegrescan and others. Those optimizations would be done after choosing the "best" image file format.

powpow
  • 111
  • 1
  • I'd say: Yes, there is a way to **automatically** detect the "best" file format, if and only if you can define the word "best" in technical and formal terms that are suitable for implementing an algorithm based on them. So far, so obvious. For example, you could define a quality measure (e.g. sum of squared pixel distances to the original image, divided by the number of pixels), and then simply try out the available file formats and compressions, and see which one achieves the highest quality. – Marco13 Jun 19 '16 at 11:43
  • No, it is not possible to do this automatically, since to know the optimal format, you need to know the intended use of the image and you cannot determine that without asking the user. Suppose the image is the result of a supervised classification, and `2` represents a cornfield and `4` represents a forest, you may determine that JPEG is best and the quantisation may now mean that pixels at the boundary of corn and forest are now sea `3`.... – Mark Setchell Jun 19 '16 at 16:51

1 Answers1

0

Full disclosure, I work for them, but Cloudinary has a feature for exactly this problem:

http://cloudinary.com/documentation/image_transformations#automatic_format_selection

If you pair the q_auto and f_auto transformation parameters in a delivery URL, Cloudinary will figure out the best format to serve given both an image’s particular content (which is what you’re asking about) and also each user’s browser’s format support. So, a photograph might get served as a JPG to Safari, WebP to Chrome, and JPEG-XR to Edge; a line drawing might get served as a PNG to all three. All automatically.

Eric Portis
  • 156
  • 3