esimov / caire

Content aware image resize library
MIT License
10.36k stars 384 forks source link

Detect if the resize operation would deform an image with human faces. #67

Closed esimov closed 1 year ago

esimov commented 3 years ago

Is your feature request related to a problem? Please describe.

Let's suppose that an image is bigger vertically than horizontally, but also contains sensible information like a person face. If we wish to reduce the image vertically by a high order of magnitude this will results in a condensed, ugly and almost unrecognizable person face. We wish to avoid this, so in some way we need to detect if an image contains a person face and the applied resize would deform the resulted image.

Here is an example:

Original image Resulted image
winking-teenage-girl-life-in-viewscience-photo-library winking-teenage-girl-life-in-viewscience-photo-library

Describe the solution you'd like

Since we already using Pigo for face detection we can detect if an image contains human faces prior resizing but also we can analyze if the resize operation could be performed without distorting the generated image. In the other cases we can either skip the image resize operation and leave the image unaltered showing a warning message or we can scale the image to the most appropriate dimension.

esimov commented 1 year ago

Finally had some time, to implement this annoying situation. The resolution I opted for in case the face detection option is used and the resulted image would deform a persons face, is to halt the process and alert the end user. In this case the user can opt in to still resize the image, but he needs eventually to disable the face detection activation flag.