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.
|
||||
|
||||
* 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.
|
||||
[#2166](https://github.com/lovell/sharp/issues/2166)
|
||||
|
||||
|
@ -68,10 +68,9 @@ namespace sharp {
|
||||
// Extract luminance
|
||||
VImage luminance = lab[0];
|
||||
// Find luminance range
|
||||
VImage stats = luminance.stats();
|
||||
double min = stats(0, 0)[0];
|
||||
double max = stats(1, 0)[0];
|
||||
if (min != max) {
|
||||
int const min = luminance.percent(1);
|
||||
int const max = luminance.percent(99);
|
||||
if (std::abs(max - min) > 1) {
|
||||
// Extract chroma
|
||||
VImage chroma = lab.extract_band(1, VImage::option()->set("n", 2));
|
||||
// Calculate multiplication factor and addition
|
||||
|
@ -13,7 +13,7 @@ const assertNormalized = function (data) {
|
||||
max = Math.max(max, data[i]);
|
||||
}
|
||||
assert.strictEqual(0, min);
|
||||
assert.strictEqual(255, max);
|
||||
assert.ok([254, 255].includes(max));
|
||||
};
|
||||
|
||||
describe('Normalization', function () {
|
||||
@ -30,7 +30,6 @@ describe('Normalization', function () {
|
||||
|
||||
it('spreads grayscaled image values between 0 and 255', function (done) {
|
||||
sharp(fixtures.inputJpgWithLowContrast)
|
||||
.gamma()
|
||||
.greyscale()
|
||||
.normalize(true)
|
||||
.raw()
|
||||
|
Loading…
x
Reference in New Issue
Block a user