{
let img = document.createElement('img');
let canvas
img.crossOrigin = ""
img.onload = function() {
console.log(img.width, img.height)
let kernel = imageKernel(img.width, img.height)
console.log('running!')
let start = window.performance.now()
let out = kernel(img)
console.log('Size', out.length, out[0].length);
const dots = [];
let minx = img.width;
let miny = img.height;
let maxx = 0;
let maxy = 0;
for (let y = 0; y <= out.length-1; y++) {
const arr = out[y];
for (let x = 0; x <= arr.length-1; x++) {
if (arr[x] == 1) {
if (x < minx) minx = x;
if (x > maxx) maxx = x;
if (y < miny) miny = y;
if (y > maxy) maxy = y;
}
}
}
miny = img.height - miny;
maxy = img.height - maxy;
console.log([minx, miny], [maxx, maxy]);
let boxSize = Math.max(maxx - minx, maxy - miny);
let stop = window.performance.now()
console.log('Took', stop - start);
canvas2.width = img.width;
canvas2.height = img.height;
const ctx = canvas2.getContext("2d");
ctx.drawImage(img, 0, 0);
console.log(canvas);
ctx.beginPath();
const mid = (a, b) => ((b - a) / 2) + a;
ctx.arc(mid(minx, maxx), mid(miny, maxy), boxSize, 0, 2 * Math.PI);
ctx.strokeStyle = 'yellow';
ctx.stroke();
}
img.src = 'https://i.imgur.com/QOyFPcN.jpg'
}