Threshold upper and lower limit
Question about an existing feature
Is there an existing way to implement the threshold function but with a lower and upper limit?
eg.
threshold(lowerLimit,upperLimit)
What are you trying to achieve?
I want to make it so that all pixels above the upper limit will be converted to 255 and all pixels below the lower limit will be converted to 0 but the pixels that lie between the limits will remain unchanged.
Hi, did you find a solution? This sounds like the sort of thing a look up table (LUT) would solve. There's an open issue to track this future possible feature at https://github.com/lovell/sharp/issues/1441
In the meantime, you could output raw, uncompressed pixel data and write your own loop to modify pixel values. https://sharp.pixelplumbing.com/api-output#raw
Alternatively, you might be able to hand-roll an ICC colour profile with a "curve" that matches the required behaviour, but this would probably require a bit of effort.
Let's continue to track this at #1441