Skip to content

Optimized Blurhash #235

Closed
Closed

Description

@renchap

I am looking at using Blurhash to get very small but nice blurred image previews : https://blurha.sh

The algorithm is quite simple and defined here: https://github.com/woltapp/blurhash/blob/master/Algorithm.md

There is a Ruby native Blurhash implementation, and it works fine using something like this:

image = Vips::Image.new_from_file(path)
Blurhash.encode(image.width, image.height, image.to_a.flatten)

Unfortunately this involves creating a huge array with all pixels and this is quite slow.

Do you think there is a way to have a more efficient implementation using Vips directly? I would be happy to have pointers, I am not really familiar with the low-level VIPS functions and if they can be used for this to avoid doing the computation using Ruby.

Thanks :)

Activity

  1. Nakilon commented on May 10, 2020

    @Nakilon
    Contributor

    While it's still not the "using Vips directly", try resizing the image to 100x100 and see if it works enough well for you:

      size = 100
      image = Vips::Image.new_from_file(filename, access: :sequential)
      image = image.resize(size.fdiv(image.width), vscale: size.fdiv(image.height))
      Blurhash.encode(image.width, image.height, image.to_a.flatten)
    
  2. jcupitt commented on May 11, 2020

    @jcupitt
    Member

    I think the DCT would probably need to be implemented in C or C++. Let's tag this as an enhacement.

  3. jcupitt commented on May 11, 2020

    @jcupitt
    Member

    ... an enhancement on libvips, I mean

  4. renchap commented on May 11, 2020

    @renchap
    Author

    @Nakilon Thanks for the suggestion, I am already doing a resize before calculating the blurhash to reduce the number of ruby allocations, but I think it can be even faster and memory-efficient :)

    @jcupitt Ok, I was not sure it could be done, if vips gets primitives to do this it would be awesome!

  5. locked and limited conversation to collaborators on Jan 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions