-
This might be trivial for people who understand image formats better than me, but is there currently a way to use this library to extract the RGB pixels from an image, so that they are suitable for use with BlurHash? Here is the example code from the blurhash-elixir package: # Pixel data supplied in RGB order, with 3 bytes per pixels.
pixels = [255, 43, 20, 11, 0, 155, ...]
hash = BlurHash.encode(pixels, 30, 30, 4, 3) I’m looking for a way to get the |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 8 replies
-
Since you need the pixel data as a list I think the following is the most straight forward: {:oh, image} = Image.open("./test/support/images/example.webp")
{:ok, binary} = Vix.Vips.Image.write_to_binary(image)
pixel_list = :binary.bin_to_list(binary)
[100, 177, 247, 100, 177, 247, 100, 177, 247, 98, 176, 245, 95, 172, 242, 94,
171, 241, 94, 171, 241, 89, 171, 242, 81, 171, 245, 76, 171, 246, 76, 171, 246,
76, 171, 246, 76, 171, 246, 76, 171, 246, 76, 171, 246, 76, 171, 246, 78, 172,
...] A couple of observations:
Implementing blurhash has been on my to-do list for a while so I'll take a look at a more idiomatic implementation in Image. There are some opportunties for improved performance like operating on binary data not lists, converting the image to linear sRGB natively and so on. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the feedback and the kind words, much appreciated. And I'm glad you're at least up and running. It might take me a couple of days but I will work on an implementation leveraging the good work already done in the lib Some other placeholder techniques I've been looking at you might be interested in: |
Beta Was this translation helpful? Give feedback.
-
The rinpath/blurhash library looks a good implementation to build upon. I think you should be able to use it directly with: {:oh, image} = Image.open("./test/support/images/example.webp")
{:ok, binary} = Vix.Vips.Image.write_to_binary(image)
Blurhash.encode(binary, Image.width(image), Image.height(image), components_x, components_y) |
Beta Was this translation helpful? Give feedback.
-
I've pushed a commit that implements Would you consider giving this a try? Just configure image with |
Beta Was this translation helpful? Give feedback.
-
I've added Image.Blurhash.decode/3. I think this is good to release now, as long as your testing confirms it works in your use case. Let me know? |
Beta Was this translation helpful? Give feedback.
-
Image version 0.44.0 is now published with the following changelog entry: Enhancements
|
Beta Was this translation helpful? Give feedback.
Image version 0.44.0 is now published with the following changelog entry:
Enhancements
Image.Blurhash.encode/2
andImage.Blurhash.decode/1
to encode and decode blurhashes. Based upon a fork of rinpatch_blurhash. Thanks to @stiang for the suggestion. Thanks very much to @rinpatch for the implementation.