swissspidy / media-experiments

WordPress media experiments
GNU General Public License v2.0
87 stars 1 forks source link

Saliency detection #5

Closed swissspidy closed 11 months ago

swissspidy commented 1 year ago

Detect the most relevant part of an image to improve thumbnail cropping. For example using MediaPipe’s object detection solution.

swissspidy commented 11 months ago

VIPs supports smart cropping (vips_smartcrop()) with the attention strategy (--smartcrop attention), which is also the default. "This one searches the image for features which might catch a human eye"

johnbillion commented 11 months ago

libvips is available in wasm which means we could use Sharp client-side and get some really powerful image processing capabilities without needing the PHP bindings.

Looks like StackBlitz has done some work on this. I've no clue what level of processing power it requires, whether it's feasible on a mobile device, etc.

swissspidy commented 11 months ago

libvips is already setup in this project, so I‘d probably start with that. Though it would be nice being able to use with other encoders as well.

kleisauke commented 11 months ago

Here's an online wasm-vips demo that uses the attention strategy: https://kleisauke.github.io/wasm-vips/playground/?modules=#smartcrop

Note that Wasm support in sharp v0.33.0 requires a Node.js compatible runtime, making it currently incompatible within web browsers.

swissspidy commented 11 months ago

Will probably simply turn this toggle into a "Thumbnail generation" dropdown:

Screenshot 2023-12-18 at 15 48 06

Possible options:

The attention strategy seems to work well, though sometimes the result is a bit odd at first.

Example input image:

Headshot

Default crop:

Headshot-150x150

Attention:

Headshot-2-150x150-1