function threshold_black_and_white(ctx, threshold) {
	const image_data = ctx.getImageData(0, 0, ctx.canvas.width, ctx.canvas.height);
	for (let i = 0; i < image_data.data.length; i += 4) {
		const white = (image_data.data[i + 0] + image_data.data[i + 1] + image_data.data[i + 2]) / 3 / 255 > threshold;
		image_data.data[i + 0] = white ? 255 : 0;
		image_data.data[i + 1] = white ? 255 : 0;
		image_data.data[i + 2] = white ? 255 : 0;
		image_data.data[i + 3] = 255;
	}
	ctx.putImageData(image_data, 0, 0);
}
Converts the image to black and white by applying a lightness threshold.
@param {CanvasRenderingContext2D} ctx - The 2D rendering context of the canvas.
@param {number} threshold - The threshold value between black and white (0 to 1).