-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add greyscale option to threshold operation to control colourspace conversion before operation #480
Conversation
Rather than apply the same threshold to all channels, perhaps the API should allow multiple thresholds, one for each (non-alpha) channel? This would, for example, allow things like thresholding non-linear sRGB in a more linear manner. The |
What you're proposing is actually the first way I thought about implementing this. However, I think the use case of applying a different threshold to each color channel is rare, and I thought it didn't warrant the added complexity of handling a mismatch between the length of the threshold vector and the number of image channels. If calling threshold with a single value implies that the image should be converted to a 1 channel image, does calling with two values mean it should be a two channel image? I suppose the easy answer is to throw an error if called with a vector and there is a vector-length / channel number mismatch. What do you think? |
Yep, I agree, we definitely don't want to make this too complex until we have to. How about adding something like This would make your use case look like In keeping with the "all variants of English" approach, |
update docs add a test for color threshold
Can anyone explain what's going on with the appveyor test? It says this, which seems to have nothing to do with my new code: bufferutil.cc |
FYI I've made the requested changes to this branch. |
The Appveyor Windows CI failures look like they are related to npm/npm#13199 - don't worry too much about them for now. |
|
||
Converts all pixels in the image to greyscale white or black. Any pixel greather-than-or-equal-to the threshold (0..255) will be white. All others will be black. | ||
|
||
* `threshold`, if present, is a Number, representing the level above which pixels will be forced to white. | ||
|
||
* `options`, an options object that may contain a boolean `grayscale` or `greyscale`. When `grayscale` is `true`, `threshold` returns a black and white image, and when `false` a color image with each channel thresholded independently. The default is `grayscale: false` when omitted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this say that the default for greyscale
is true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, woops. Yes.
Thanks for the updates and the tests. I've added a couple of comments inline. Please can you add a test case for the explicit use of |
@@ -85,7 +85,7 @@ var Sharp = function(input, options) { | |||
sharpenFlat: 1, | |||
sharpenJagged: 2, | |||
threshold: 0, | |||
thresholdColor: false, | |||
thresholdGrayscale: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thresholdGrayscale: true
?
Thanks again for this - it will be in v0.15.1. |
This patch adds an optional boolean option that causes the threshold command to operate on each color channel independently, rather than first converting to a black and white image. Default behavior prior to the patch is unchanged.