Created
July 5, 2016 01:39
-
-
Save andrevenancio/499018845edc85808f03a65a1cb98b9d to your computer and use it in GitHub Desktop.
apply a threshold filter with a fixed constant. (ES6)
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
threshold(pixels, threshold) { | |
const d = pixels.data; | |
for (let i = 0; i < d.length; i += 4) { | |
const r = d[i + 0]; | |
const g = d[i + 1]; | |
const b = d[i + 2]; | |
let v = 0; | |
if ((r + g + b) > threshold) { | |
v = 255; | |
} | |
d[i + 0] = d[i + 1] = d[i + 2] = v; | |
} | |
return pixels; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment