Sharp: Feature request: colour grading

Created on 30 Oct 2018  路  11Comments  路  Source: lovell/sharp

I'm interested in being able to apply 3D LUTs to images on the fly, eg. .cube files. I think vips_maplut() is the right function under the hood for this, perhaps I'll need to figure out how to generate LUT images from those files first though.

I've been trying to use some node libraries to do this, extracting the pixels as an ndarray, applying the LUT, then saving the modified pixels back to an image buffer but it's super slow and error prone (truncated image data etc).

If it's not something that makes sense for sharp no worries, hopefully I can find info on transforming an image as a readableStream assuming that's doable :)

enhancement help wanted

All 11 comments

Hello, you're correct that libvips' maplut operation is suitable for this - we'd need to expose it in sharp. Happy to accept/help with a PR for this if you're able.

To be honest I don't really know any C languages but perhaps I can figure it out from the existing code patterns. I'll try and get a build running locally and have a look.

@lovell I've been tinkering with it for a while but I think I'm not quite understanding something. It looks like I can only pass a single image to maplut(), I'm trying with a hald image from https://filterhunt.com but as far as I understand it you need two hald images - one with the standard RGB values that is then mapped to the LUT hald image. Do you know if that's right?

I have some work in progress here: https://github.com/roborourke/sharp/tree/maplut

It compiles at least! Doesn't actually modify the output at all though.

Ah, sorry, I was thinking of 3x 1D LUTs, e.g. one for each channel of an RGB image. For maplut I guess a HALD image would need to be parsed/converted/interpolated into separate R, G and B tables first, if such a thing is possible, then combined into a 3-channel image.

It might be worth you asking this question over on the libvips repo. Perhaps a 3D LUT could be converted to an ICC profile and applied that way?

Yeah you can get them in icm format I think. I see your point re 3x 1D LUTs. Hopefully there might be some existing tools to convert between LUT formats :/

Will ask over on the libvips repo, thanks!

Thanks for cross-linking! I should have done that. I've played a bit more using vips_icc_transform() but it still doesn't seem to modify the output so I'm definitely doing something wrong...

Work in progress: https://github.com/roborourke/sharp/tree/icc-transform

If you didn't see it, #1323 is the existing feature request relating to custom output profiles.

Cheers, I guess I didn't know what I was looking for before :) So the intention in #1323 is to modify the output pixel values? Would it matter that it didn't have the sRGB colourspace then?

Anyway, if this use case is covered by that issue then we can close this one.

If you think you'll be able to achieve what you need using a colour profile transform (rather than a 3D LUT) then yes, the possible future enhancement discussed in #1323 should suffice.

I'm happy to keep this issue open as another possible future enhancement given others may require a LUT feature, albeit limited to per-channel manipulation.

Commented on #1323 - the icc-transform branch on my fork is working for applying a custom ICC profile now but I'm not sure it's definitely working the same way a 3D LUT would. Given the capabilities of libvips right now it might be the closest I can get for the time being at least!

Was this page helpful?
0 / 5 - 0 ratings