I want to write a function to compare two images and tell whether they contain the same chart or not. For example, the charts shown below:

These two images are of the same chart. However, the charts have different colors, different sizes, different backgrounds, and won't be easily aligned together. How can I write a, preferably a javascript, function that can whether two passed images are of the same chart or not?
In other words, I want a function that tell whether the two chart line could be aligned together or not regardless of the actual points on the axes.
