Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brightness, Saturation and Hue #609

Closed
diegocsandrim opened this issue Oct 20, 2016 · 8 comments
Closed

Brightness, Saturation and Hue #609

diegocsandrim opened this issue Oct 20, 2016 · 8 comments

Comments

@diegocsandrim
Copy link

Hi @lovell,
Does sharp support brightness, saturation and hue?
I was looking for something similar to modulate of imagemagick or graphicsmagick.
I took a look at the docs but could not find.

@lovell
Copy link
Owner

lovell commented Oct 20, 2016

Hello, *magick's "modulate" operator is approximately equivalent to a colourspace conversion to LCH (Luminance, Chroma, Hue) then a multiplication of pixels in the L and C channels. libvips supports these operations, but this is not currently exposed in sharp.

As always, I'm happy to accept a PR and help with discussions about how the API for this might work.

@adityapatadia
Copy link

I would like to work on this. Can you point me to some resource which teaches about how can this be done?

@lovell
Copy link
Owner

lovell commented Jan 24, 2017

@adityapatadia Thanks for your interest.

This feature will involve a combination of converting to the LCH colourspace via colourspace, splitting out any channels to be "modulated", using multiply to modify them with the relevant value before joining the channels back up again.

You probably won't need to worry about the colourspace conversion away from LCH as there's already logic to clean up at the end of the pipeline.

  • L(ightness) ~= brightness
  • C(hroma) ~= saturation
  • H(ue)

The API could look something like:

// identity transform, 100 means 100% of the original value so no change
.modulate({ brightness: 100, saturation: 100 }) 
// reduce saturation by ~25%
.modulate({ saturation: 75 }) 
// convert red to green etc.
.modulate({ hue: 166 }) 

@adityapatadia
Copy link

I would be asking much more questions.
Apart form API, how do I implement in the C code? Which files should I add the operations? Can you show me sample from which I can learn?

@lovell
Copy link
Owner

lovell commented Feb 11, 2017

@adityapatadia Although it's marked patch-welcome, this is a relatively complex task. Perhaps look at implementing something like #577 first?

@jonathan-kosgei
Copy link

Hi @lovell I looked through the files and for example the Blur function in https://github.com/lovell/sharp/blob/master/src/operations.cc looks easy enough because it's syntax is close to pyvips and node-vips syntax.
However not being a C dev, I'm not sure how it ties in with the other files. Could there be a simple write up on how to add functionality from libvips to sharp? Also would you recommend any short tutorials/books/courses to get started with image processing?

@lovell
Copy link
Owner

lovell commented May 9, 2018

@jonathan-kosgei Thank you for the offer of help.

sharp uses libvips C++ API
http://jcupitt.github.io/libvips/API/current/using-from-cpp.html

Your idea to start with an existing operation such as blur is a good idea. Perhaps follow blurSigma as it moves through the various layers.

https://github.com/lovell/sharp/search?q=blurSigma&type=Code

https://github.com/lovell/sharp/blob/master/lib/operation.js#L180
https://github.com/lovell/sharp/blob/master/src/pipeline.cc#L1209
https://github.com/lovell/sharp/blob/master/src/operations.cc#L237

I'm always happy to help with and provide feedback on partially-complete PRs.

@lovell
Copy link
Owner

lovell commented Apr 25, 2019

v0.22.1 now available with this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants