Dear all,
the following two-liner is based on the fact that the different parts of a fake image might have different compression rates in certain image formats, such as jpg etc. Loss-less formats do not work for this.
We start with a fake jpg-image downloaded from the internet:
First I import the image from the desktop:
img1 = Import["~/Desktop/Fake.jpg"]
Then I export it with a low compression rate:
Export["~/Desktop/img1comp.jpg", img1, "CompressionLevel" -> 0.012]
I then import the new image
img2 = Import["~/Desktop/img1comp.jpg"];
and then substract the images and adjust the colour range.
ImageSubtract[img1, img2] // ImageAdjust
In the resulting image the forged parts are supposed to light up. Here only slightly; it will work better once the compression rate is adapted.
This illustrates just the general idea. There is an "aura" of brighter pixels around the object that is copied in.
Everything can be joined up into a (kind of) one-liner. I then wrap a little manipulate command around it, to vary the compression rate. In order to make this work one needs to play a bit with the compression rates, i.e. move the slider.
Manipulate[
Export["~/Desktop/img1comp.jpg", img1, "CompressionLevel" -> comp];
img2 = Import["~/Desktop/img1comp.jpg"];
ImageSubtract[img1, img2] // ImageAdjust, {{comp, 0.05}, 0, 0.5}]
Summary: (i) this is only a very crude algorithm, but it works in some cases, (ii) Mathematica certainly has all the algorithms to detect forgery in images, (iii) the shark in the image appears to be copied in :-)
A nice game is to write a little web-crawler to download images from common social network sites and analyse how many of them are fake. Note, that this particular algorithm is not particularly useful to detect forgeries of photos on facebook or dating websites, because they are often not "copy-and-paste", but rather "increase or decrease" the size of certain parts of an image.
Here is another example:
The output of the program is:
It is important to note that this method is not at all fool-proof; often there are false positives.