You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Assuming img1 and img2 are your two images and they have the same dimensionsletcanvas=document.createElement('canvas');letctx=canvas.getContext('2d');canvas.width=img1.width;canvas.height=img1.height;ctx.drawImage(img1,0,0);letimgData1=ctx.getImageData(0,0,canvas.width,canvas.height);ctx.clearRect(0,0,canvas.width,canvas.height);ctx.drawImage(img2,0,0);letimgData2=ctx.getImageData(0,0,canvas.width,canvas.height);letimgDataResult=ctx.createImageData(canvas.width,canvas.height);for(leti=0;i<imgData1.data.length;i+=4){letr1=imgData1.data[i];letg1=imgData1.data[i+1];letb1=imgData1.data[i+2];letr2=imgData2.data[i];letg2=imgData2.data[i+1];letb2=imgData2.data[i+2];// calculate the color differenceletdiff=Math.abs(r1-r2)+Math.abs(g1-g2)+Math.abs(b1-b2);if(diff==0){// the pixels are the same, set to grayscaleletgrayscale=0.3*r1+0.59*g1+0.11*b1;imgDataResult.data[i]=grayscale;imgDataResult.data[i+1]=grayscale;imgDataResult.data[i+2]=grayscale;}else{// the pixels are different, set to blue or redimgDataResult.data[i]=r1>r2 ? 255 : 0;// red channelimgDataResult.data[i+1]=0;// green channelimgDataResult.data[i+2]=r1<r2 ? 255 : 0;// blue channel}imgDataResult.data[i+3]=255;// alpha channel}ctx.putImageData(imgDataResult,0,0);
The text was updated successfully, but these errors were encountered:
ref:
![telegram-cloud-photo-size-2-5434150931555010562-y](https://private-user-images.githubusercontent.com/1360552/240156803-62a37397-721e-45f4-bb6d-f4b13df1eff9.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQwOTM4NzYsIm5iZiI6MTcyNDA5MzU3NiwicGF0aCI6Ii8xMzYwNTUyLzI0MDE1NjgwMy02MmEzNzM5Ny03MjFlLTQ1ZjQtYmI2ZC1mNGIxM2RmMWVmZjkuanBnP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTlUMTg1MjU2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NDJkNDUyZWQwMjExYjAwYTRhMDQ2NTFkYTEwYzgxNWNhNzFiNDMwNTE3YTRhZTk0Yzk0ZjdlYjU0ZGRkNTUzNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ._63JgQx5s-hubrKtUbIXtgnlQ6po91y0AGzhuJryjCo)
https://www.robots.ox.ac.uk/~vgg/software/imcomp/
Sample:
The text was updated successfully, but these errors were encountered: