xxxxxxxxxx
// noprotect
let img = null;
let grayImg = null;
let edgeImg = null;
const kernel = [[ -1, -1, -1],
[ -1, 8, -1],
[ -1, -1, -1]];
function preload() {
const w = windowWidth/200;
const h = windowHeight/100;
img = loadImage("IMG_1148.JPG");
img.resize(w,h);
grayImg = loadImage("IMG_1148.JPG");
grayImg.resize(w,h);
edgeImg = loadImage("IMG_1148.JPG");
edgeImg.resize(w,h);
}
function setup() {
createCanvas(windowWidth, windowHeight);
grayImg.filter(GRAY);
grayImg.loadPixels();
edgeImg.loadPixels();
for(let x = 1; x < grayImg.width-1; x++){
for(let y = 1; y < grayImg.height-1; y++){
let sum = 128;
for (let ky = -1; ky <= 1; ky++) {
for (let kx = -1; kx <= 1; kx++) {
let pos = (y + ky)*grayImg.width + (x + kx);
let val = grayImg.pixels[pos][0];
sum += kernel[ky+1][kx+1] * val;
}
}
edgeImg.pixels[y*edgeImg.width + x] = color(sum);
}
}
edgeImg.updatePixels();
}
function draw() {
image(img, 0, 0, windowWidth/2, windowHeight);
image(edgeImg, windowWidth/2, 0, windowWidth/2, windowHeight);
}