Photoshop offers a feature called same color. It adjusts the colors of an image based on another.
Here is an example, these 2 pictures share different colors (one of them has an orange shade over it).
Image 1
Image 2
After using Photoshop‘s same color function the first image’s colors are adjusted like this:
I wonder how you can achieve a similar effect using imagemagick/code or how this effect works in general. Photoshop is able to tell exactly which colors should be changed.