xxxxxxxxxx
30
let classifier;
let img;
function preload() {
img = loadImage('penguin.jpg');
}
function setup() {
createCanvas(img.width, img.height);
img.loadPixels();
for (let x = 0; x < img.width; x +=1) {
for (let y = 0; y < img.height; y +=1) {
let c = img.get(x,y);
let contrast = 100;
let factor = (259 * (contrast + 255)) / (255 * (259 - contrast));
if (x === 0 && y === 0) {
print(factor);
}
let nR = constrain(factor*(red(c)-128) + 128, 0, 255);
let nG = constrain(factor*(green(c)-128) + 128, 0, 255);
let nB = constrain(factor*(blue(c)-128) + 128, 0, 255);
let nC = color(nR,nG,nB);
img.set(x,y,nC);
}
}
img.updatePixels();
image(img, 0, 0);
}