mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Improve normalise op with use of histogram #200
This commit is contained in:
parent
9a54a034e1
commit
55c4d8807c
@ -16,6 +16,9 @@ Requires libvips v8.13.0
|
|||||||
|
|
||||||
* The `flip` and `flop` operations will now occur before the `rotate` operation.
|
* The `flip` and `flop` operations will now occur before the `rotate` operation.
|
||||||
|
|
||||||
|
* Improve `normalise` operation with use of histogram.
|
||||||
|
[#200](https://github.com/lovell/sharp/issues/200)
|
||||||
|
|
||||||
* Use combined bounding box of alpha and non-alpha channels for `trim` operation.
|
* Use combined bounding box of alpha and non-alpha channels for `trim` operation.
|
||||||
[#2166](https://github.com/lovell/sharp/issues/2166)
|
[#2166](https://github.com/lovell/sharp/issues/2166)
|
||||||
|
|
||||||
|
@ -68,10 +68,9 @@ namespace sharp {
|
|||||||
// Extract luminance
|
// Extract luminance
|
||||||
VImage luminance = lab[0];
|
VImage luminance = lab[0];
|
||||||
// Find luminance range
|
// Find luminance range
|
||||||
VImage stats = luminance.stats();
|
int const min = luminance.percent(1);
|
||||||
double min = stats(0, 0)[0];
|
int const max = luminance.percent(99);
|
||||||
double max = stats(1, 0)[0];
|
if (std::abs(max - min) > 1) {
|
||||||
if (min != max) {
|
|
||||||
// Extract chroma
|
// Extract chroma
|
||||||
VImage chroma = lab.extract_band(1, VImage::option()->set("n", 2));
|
VImage chroma = lab.extract_band(1, VImage::option()->set("n", 2));
|
||||||
// Calculate multiplication factor and addition
|
// Calculate multiplication factor and addition
|
||||||
|
@ -13,7 +13,7 @@ const assertNormalized = function (data) {
|
|||||||
max = Math.max(max, data[i]);
|
max = Math.max(max, data[i]);
|
||||||
}
|
}
|
||||||
assert.strictEqual(0, min);
|
assert.strictEqual(0, min);
|
||||||
assert.strictEqual(255, max);
|
assert.ok([254, 255].includes(max));
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('Normalization', function () {
|
describe('Normalization', function () {
|
||||||
@ -30,7 +30,6 @@ describe('Normalization', function () {
|
|||||||
|
|
||||||
it('spreads grayscaled image values between 0 and 255', function (done) {
|
it('spreads grayscaled image values between 0 and 255', function (done) {
|
||||||
sharp(fixtures.inputJpgWithLowContrast)
|
sharp(fixtures.inputJpgWithLowContrast)
|
||||||
.gamma()
|
|
||||||
.greyscale()
|
.greyscale()
|
||||||
.normalize(true)
|
.normalize(true)
|
||||||
.raw()
|
.raw()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user