Question

Last night before going to bed, I browsed through the Scalar Data section of Learning Perl again and came across the following sentence:

the ability to have any character in a string means you can create, scan, and manipulate raw binary data as strings.

An idea immediately hit me that I could actually let Perl scan the pictures that I have stored on my hard disk to check if they contain the string Adobe. It seems by doing so, I can tell which of them have been photoshopped. So I tried to implement the idea and came up with the following code:

#!perl
use autodie;
use strict;
use warnings;

{
    local $/="\n\n";
    my $dir = 'f:/TestPix/';
    my @pix = glob "$dir/*";

    foreach my $file (@pix) {
        open  my $pic,'<',  "$file";

        while(<$pic>) {
            if (/Adobe/) {
                print "$file\n";
            }
        }
    }
}

Excitingly, the code seems to be really working and it does the job of filtering out the pictures that have been photoshopped. But problem is many pictures are edited by other utilities. I think I'm kind of stuck there. Do we have some simple but universal method to tell if a digital picture has been edited or not, something like

if (!= /the origianl format/) {...}

Or do we simply have to add more conditions? like

if (/Adobe/|/ACDSee/|/some other picture editors/)

Any ideas on this? Or am I oversimplifying due to my miserably limited programming knowledge?

Thanks, as always, for any guidance.

Was it helpful?

Solution

Your best bet in Perl is probably ExifTool. This gives you access to whatever non-image information is embedded into the image. However, as other people said, it's possible to strip this information out, of course.

OTHER TIPS

I'm not going to say there is absolutely no way to detect alterations in an image, but the problem is extremely difficult.

The only person I know of who claims to have an answer is Dr. Neal Krawetz, who claims that digitally altered parts of an image will have different compression error rates from the original portions. He claims that re-saving a JPEG at different quality levels will highlight these differences.

I have not found this to be the case, in my investigations, but perhaps you might have better results.

No. There is no functional distinction between a perfectly edited image, and one which was the way it is from the start - it's all just a bag of pixels in the end, after all, and any other metadata you can remove or forge all you want.

The name of the graphics program used to edit the image is not part of the image data itself but of something called meta data - which may be stored in the image file but, as others have noted, is neither required (so some programs may not store it, some may allow you an option of not storing it) nor reliable - if you forged an image, you might have forged the meta data as well.

So the answer to your question is "no, there's no way to universally tell if the pic was edited or not, although some image editing software may write its signature into the image file and it'll be left there by carelessness of the editing person.

If you're inclined to learn more about image processing in Perl, you could take a look at some of the excellent modules CPAN has to offer:

  • Image::Magick - read, manipulate and write of a large number of image file formats
  • GD - create colour drawings using a large number of graphics primitives, and emit the drawings in various formats.
  • GD::Graph - create charts
  • GD::Graph3d - create 3D Graphs with GD and GD::Graph

However, there are other utilities available for identifying various image formats. It's more of a question for Super User, but for various unix distros you can use file to identify many different types of files, and for MacOSX, Graphic Converter has never let me down. (It was even able to open the bizarre multi-file X-ray of my cat's shattered pelvis that I got on a disc from the vet.)

How would you know what the original format was? I'm pretty sure there's no guaranteed way to tell if an image has been modified.

I can just open the file (with my favourite programming language and filesystem API) and just write whatever I want into that file willy-nilly. As long as I don't screw something up with the file format, you'd never know it happened.

Heck, I could print the image out and then scan it back in; how would you tell it from an original?

As other's have stated, there is no way to know if the image was doctored. I'm guessing what you basically want to know is the difference between a realistic photograph and one that has been enhanced or modified.

There's always the option of running some extremely complex image recognition algorithm that would analyze every pixel in your image and do some very complicated stuff to determine if the image was doctored or not. This solution would probably involve AI which would examine millions of photos that are both doctored and those that are not and learn from them. However, this is more of a theoretical solution and isn't very practical... you would probably only see it in movies. It would be extremely complex to develop and probably take years. And even if you did get something like this to work, it probably still wouldn't be 100% correct all the time. I'm guessing AI technology still isn't at that level and could take a while until it is.

A not-commonly-known feature of exiftool allows you to recognize the originating software through an analysis of the JPEG quantization tables (not relying on image metadata). It recognizes tables written by many applications. Note that some cameras may use the same quantization tables as some applications, so this isn't a 100% solution, but it is worth looking into. Here is an example of exiftool run on two images, the first was edited by photoshop.

> exiftool -jpegdigest a.jpg b.jpg
======== a.jpg
JPEG Digest                     : Adobe Photoshop, Quality 10
======== b.jpg
JPEG Digest                     : Canon EOS 30D/40D/50D/300D, Normal
    2 image files read

This will work even if the metadata has been removed.

There is existing software out there which uses various techniques (compression artifacting, comparison to signature profiles in a database of cameras, etc.) to analyze the actual image data for evidence of alteration. If you have access to such software and the software available to you provides an API for external access to these analysis functions, then there's a decent chance that a Perl module exists which will interface with that API and, if no such module exists, it could probably be created rather quickly.

In theory, it would also be possible to implement the image analysis code directly in native Perl, but I'm not aware of anyone having done so and I expect that you'd be better off writing something that low-level and processor-intensive in a fully-compiled language (e.g., C/C++) rather than in Perl.

http://www.impulseadventure.com/photo/jpeg-snoop.html is a tool that does the job almost good

If there has been any cloning , there is a variation in the pixel density..or concentration which sometimes shows up.. upon manual inspection a Photoshop cloned area will have even pixel density(my meaning is variation of Pixels wrt a scanned image)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top