If I get correctly what you are asking you basically just need to find the G in this equation:
$$Image_{out} = Image_{in}^G$$
This could be easily solved as
$$G = \frac{\log{Image_{out}}}{\log{Image_{in}}}$$
Because usallyusually gamma is applied in a uniform fashion on the image, you can just pick any two non zero pixel values (one for source and one for destination) to find out the gamma value applied.
EDIT: As @ChristianRau pointed out, if you don't actually know if the image has been modified with gamma correction, you have to take an higher amount of samples and trying to fit a gamma function on those. If a fit to a gamma function results in too many significant outliers, then probably gamma correction wasn't the function applied.