{
const data = cv.imread(im);
const canvas = DOM.canvas(im.width, im.height);
cv.cvtColor(data, data, cv.COLOR_RGBA2GRAY);
let anchor = new cv.Point(-1, -1);
let M = cv.Mat.ones(2, 2, cv.CV_8U);
cv.erode(data, data, M, anchor, 1, cv.BORDER_CONSTANT, cv.morphologyDefaultBorderValue());
const contours = new cv.MatVector();
const hierarchy = new cv.Mat();
cv.findContours(data, contours, hierarchy, cv.RETR_CCOMP, cv.CHAIN_APPROX_NONE)
cv.cvtColor(data, data, cv.COLOR_GRAY2RGB);
// return canvas
for(let i = 0; i < contours.size(); i++) {
// const {m00, m01, m10} = cv.moments(contours.get(i));
// if(m00 === 0) continue;
// const center = new cv.Point(m10 / m00, m01 / m00);
// cv.circle(data, center, 10, [0, 0, 0, 255], 6);
// cv.circle(data, center, 10, [0, 255, 0, 255], 2);
let color = new cv.Scalar(Math.round(Math.random() * 255), Math.round(Math.random() * 255),
Math.round(Math.random() * 255));
cv.drawContours(data, contours, i, color, 1, cv.LINE_8, hierarchy, 100);
// let color = new cv.Scalar(Math.round(Math.random() * 255), Math.round(Math.random() * 255),
// Math.round(Math.random() * 255));
// let color = new cv.Scalar(Math.round(0), Math.round(255),
// Math.round(0));
// if (cv.contourArea(contours.get(i)) > 50) {
// cv.drawContours(mask, contours, i, color, -1, cv.LINE_8, hierarchy, 100);
// }
}
// cv.cvtColor(mask, mask, cv.COLOR_RGBA2GRAY, 0);
// cv.threshold(mask, mask, 100, 255, cv.THRESH_BINARY);
// cv.cvtColor(mask, mask, cv.COLOR_GRAY2RGB, 0)
// // cv.bitwise_not(mask, mask)
// // cv.cvtColor(black, black, cv.COLOR_GRAY2RGBA);
// cv.bitwise_and(data, mask, data)
// let color = new cv.Scalar(Math.round(Math.random() * 255), Math.round(Math.random() * 255),
// Math.round(Math.random() * 255));
// cv.drawContours(data, contours, -1, color, -1, cv.LINE_8, hierarchy, 100);
// const canvas = DOM.canvas(image.width, image.height);
// return contours.get(0)
cv.imshow(canvas, data);
data.delete();
contours.delete();
hierarchy.delete();
return sideBySide(im, canvas);
}