Teachers open the door but You must enter by yourself.

Open Media Lab.
オープンメディアラボ

濃淡画像への変換
Conversion to Gray-scale

Lij = 0.3 * Rij + 0.59 * Gij + 0.11 * Bij

ソースコード

window.addEventListener('load', function(){
	const canvas = document.getElementById('canvas');
	canvas.height = canvas.width*1.333;
	const context = canvas.getContext('2d');
	const image = new Image();
	image.src = 'ip/original.jpg';
	image.addEventListener("load", function(){
		context.drawImage(image,0,0);
		const x = context.getImageData(0,0,canvas.width,canvas.height);
		for (let i=0; i < x.data.length; i+=4) {
			const gray=x.data[i]*0.299+x.data[i+1]*0.587+x.data[i+2]*0.114;
			x.data[i]=x.data[i+1]=x.data[i+2]=gray;
		}
		context.putImageData(x,0,0);
	});
});
This site is powered by
Powered by MathJax