-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add normalize() for simple histogram stretching
Available as normalize() or normalise(). Normalization takes place in LAB place, to the resulting sRGB image is not guaranteed to cover exactly 0-255, but it should be close enough. Existing alpha channels are preserved untouched by normalization. A possible side effect of this commit is that input grayscale images are no longer forced to sRGB on output.
- Loading branch information
Showing
7 changed files
with
145 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
|
||
var sharp = require('../../index'); | ||
var fixtures = require('../fixtures'); | ||
|
||
sharp.cache(0); | ||
|
||
describe('Normalization', function () { | ||
it('spreads grayscale image values between 0 and 255', function(done) { | ||
sharp(fixtures.inputJpgWithLowContrast) | ||
.gamma() | ||
.greyscale() | ||
.normalize() | ||
.raw() | ||
.toBuffer(function (err, data, info) { | ||
if (err) throw err; | ||
var min = 255, max = 0, i; | ||
for (i = 0; i < data.length; i++) { | ||
min = Math.min(min, data[i]); | ||
max = Math.max(max, data[i]); | ||
} | ||
assert.strictEqual(2, min); | ||
assert.strictEqual(255, max); | ||
return done(); | ||
}); | ||
}); | ||
|
||
it('spreads rgb image values between 0 and 255', function(done) { | ||
sharp(fixtures.inputJpgWithLowContrast) | ||
.normalize() | ||
.raw() | ||
.toBuffer(function (err, data, info) { | ||
if (err) throw err; | ||
var min = 255, max = 0, i; | ||
for (i = 0; i < data.length; i += 3) { | ||
min = Math.min(min, data[i], data[i + 1], data[i + 2]); | ||
max = Math.max(max, data[i], data[i + 1], data[i + 2]); | ||
} | ||
assert.strictEqual(0, min); | ||
assert.strictEqual(255, max); | ||
return done(); | ||
}); | ||
}); | ||
|
||
it('uses the same prototype for both spellings', function () { | ||
assert.strictEqual(sharp.prototype.normalize, sharp.prototype.normalise); | ||
}); | ||
}); |