Teachers open the door but You must enter by yourself.

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

エンボス処理
Emboss

Lij = Lij - Li-1 j-1 + 128

ソースコード

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 j=x.height-1; j > 0 ; j--) {
			for (let i=x.width-1; i > 0; i--) {
				const m=(i-1+(j-1)*x.width)*4;
				const n=(i+j*x.width)*4;
				const gray1=x.data[m]*0.3+x.data[m+1]*0.59+x.data[m+2]*0.11;
				const gray=x.data[n]*0.3+x.data[n+1]*0.59+x.data[n+2]*0.11;
				const emboss=gray-gray1+128;
				x.data[n]=x.data[n+1]=x.data[n+2]
					=emboss>255?255:(emboss<0?0:emboss);
			}
		}
		context.putImageData(x,0,0);
	});
});

出力値は必ずしも0~255の間になるとは限らないので、丸め処理が必要となることに注意!

This site is powered by
Powered by MathJax