mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add support to normalise for lower and upper percentiles (#3583)
This commit is contained in:
committed by
Lovell Fuller
parent
1eefd4e562
commit
d7776e3b98
@@ -34,7 +34,7 @@ describe('Normalization', function () {
|
||||
it('spreads grayscaled image values between 0 and 255', function (done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.greyscale()
|
||||
.normalize(true)
|
||||
.normalize()
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
@@ -107,4 +107,58 @@ describe('Normalization', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle luminance range', function (done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.normalise({ lower: 10, upper: 70 })
|
||||
.raw()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assertNormalized(data);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow lower without upper', function () {
|
||||
assert.doesNotThrow(() => sharp().normalize({ lower: 2 }));
|
||||
});
|
||||
it('should allow upper without lower', function () {
|
||||
assert.doesNotThrow(() => sharp().normalize({ upper: 98 }));
|
||||
});
|
||||
it('should throw when lower is out of range', function () {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: -10 }),
|
||||
/Expected number between 0 and 99 for lower but received -10 of type number/
|
||||
);
|
||||
});
|
||||
it('should throw when upper is out of range', function () {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ upper: 110 }),
|
||||
/Expected number between 1 and 100 for upper but received 110 of type number/
|
||||
);
|
||||
});
|
||||
it('should throw when lower is not a number', function () {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: 'fail' }),
|
||||
/Expected number between 0 and 99 for lower but received fail of type string/
|
||||
);
|
||||
});
|
||||
it('should throw when upper is not a number', function () {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ upper: 'fail' }),
|
||||
/Expected number between 1 and 100 for upper but received fail of type string/
|
||||
);
|
||||
});
|
||||
it('should throw when the lower and upper are equal', function () {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: 2, upper: 2 }),
|
||||
/Expected lower to be less than upper for range but received 2 >= 2/
|
||||
);
|
||||
});
|
||||
it('should throw when the lower is greater than upper', function () {
|
||||
assert.throws(
|
||||
() => sharp().normalise({ lower: 3, upper: 2 }),
|
||||
/Expected lower to be less than upper for range but received 3 >= 2/
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user