Replies: 3 comments 3 replies
-
|
Sorry to be a bit slow to get back to you on this. Average colorComputing the average is straight forward since that is a function already in iex> image = Image.open! "./test/support/images/Kamchatka-2019-8754.jpg"
%Vix.Vips.Image{ref: #Reference<0.2751592336.3974758430.163424>}
iex> Image.average(image)
[128, 116, 95]
Getting all colorsAlthough possible, this is a very expensive operation and I strongly recommend not doing it. Examining all pixels results in one NIF call per pixel which will be extremely expensive. See Deriving a color paletteI think deriving a color pallet for an image would be very helpful. I opened an issue on this topic but that has not born fruit at this stage. Using a histogramIt's possible to create a histogram of colors that fall into different bins. You could use this to at least establish broad color usage. The function to use Conversion to/from hex/rgbWhat I really need to do is make the time to finish up a proper color library. The current approach to colors in I will add conversion from RGB to Hex at least (give me a week or so). |
Beta Was this translation helpful? Give feedback.
-
|
I've pushed a commit that adds |
Beta Was this translation helpful? Give feedback.
-
|
Also, on getting all the colors of an image, Nx can get most of the way there: iex> i = Image.open! "./test/support/images/Kamchatka-2019-8754.jpg"
%Vix.Vips.Image{ref: #Reference<0.1315682744.4087480349.157106>}
# Convert to a Nx tensor. This comes at the expense of having to stream
# the entire image and allocate it in memory - libvips operations typically
# stream content and never have to allocated memory for the full image.
iex> {:ok, tensor} = Image.to_nx(i)
{:ok,
#Nx.Tensor<
u8[width: 1000][height: 542][bands: 3]
EXLA.Backend<host:0, 0.1315682744.4087480340.156769>
[
[
[220, 223, 232],
[220, 223, 232],
[220, 223, 232],
...
],
...
]
>}
# Now we need turn the tensor into a simple 2 dimensional
# list of colors
iex> {width, height, bands} = Nx.shape(tensor)
{1000, 542, 3}
iex> colors = Nx.reshape(tensor, {width * height, bands})
#Nx.Tensor<
u8[542000][3]
EXLA.Backend<host:0, 0.1315682744.4087480340.156771>
[
[220, 223, 232],
[220, 223, 232],
[220, 223, 232],
[220, 223, 232],
...
]
>What is currently missing (and I've asked the question in the Elixir slack) is the equivalent of bumpy's Using scholar it's also possible then to use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Let's say I have an image and I would like to extract the RGB and HEX value from that. Is there a function already available in
Image?Wouldn't be nicer if those colors are embedded in the metadata (exif) itself?
ImageMagick returns average color:
Right now I'm doing like this to get an average color of any given image.
Beta Was this translation helpful? Give feedback.
All reactions