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:
https://www.robots.ox.ac.uk/~vgg/software/imcomp/
Sample:
The text was updated successfully, but these errors were encountered: