For more complex stuff like this you could look into something like
rsmbl.github.io/Resemble.js
It even gives you the exact percentage of similarity.
At the same time, the makeshift solution would be to
1. Have both the input and output images on a canvas of the same size
2. Loop over every pixel and compare the colors
3. Track how many comparisons are true and you can do a little simple math to get the percentage of pixels that match