<p>Given two different image files (in whatever format I choose), I need to write a program to predict the chance if one being the illegal copy of another. The author of the copy may do stuff like rotating, making negative, or adding trivial details (as well as changing the dimension of the image).</p>

<p>Do you know any algorithm to do this kind of job?</p>

[{'answer_id': 23946, 'author': 'Nick', 'author_id': 1490, 'author_profile': 'https://Stackoverflow.com/users/1490', 'pm_score': 5, 'selected': False, 'text': '<p>Read the paper: <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.81.3347&amp;rep=rep1&amp;type=pdf" rel="noreferrer"><strong>Porikli, Fatih, Oncel Tuzel, and Peter Meer. “Covariance Tracking Using Model Update Based\non Means on Riemannian Manifolds”. (2006) IEEE Computer Vision and Pattern Recognition.</strong></a></p>\n\n<p>I was successfully able to detect overlapping regions in images captured from adjacent webcams using the technique presented in this paper.  My covariance matrix was composed of Sobel, canny and SUSAN aspect/edge detection outputs, as well as the original greyscale pixels.</p>\n'}, {'answer_id': 79619, 'author': 'shea241', 'author_id': 14656, 'author_profile': 'https://Stackoverflow.com/users/14656', 'pm_score': 4, 'selected': False, 'text': '<p>It is indeed much less simple than it seems :-)  Nick\'s suggestion is a good one.</p>\n\n<p>To get started, keep in mind that any worthwhile comparison method will essentially work by converting the images into a different form -- a form which makes it easier to pick similar features out.  Usually, this stuff doesn\'t make for very light reading ...\n<br/>\n<br/>\n<br/>\nOne of the simplest examples I can think of is simply using the color space of each image.  If two images have highly similar color distributions, then you can be reasonably sure that they show the same thing.  At least, you can have enough certainty to flag it, or do more testing.  Comparing images in color space will also resist things such as rotation, scaling, and some cropping.  It won\'t, of course, resist heavy modification of the image or heavy recoloring (and even a simple hue shift will be somewhat tricky).</p>\n\n<p><a href="http://en.wikipedia.org/wiki/RGB_color_space" rel="noreferrer">http://en.wikipedia.org/wiki/RGB_color_space</a><br/>\n<a href="http://upvector.com/index.php?section=tutorials&amp;subsection=tutorials/colorspace" rel="noreferrer">http://upvector.com/index.php?section=tutorials&amp;subsection=tutorials/colorspace</a><br/>\n<br/>\n<br/></p>\n\n<p>Another example involves something called the Hough Transform.  This transform essentially decomposes an image into a set of lines.  You can then take some of the \'strongest\' lines in each image and see if they line up.  You can do some extra work to try and compensate for rotation and scaling too -- and in this case, since comparing a few lines is MUCH less computational work than doing the same to entire images -- it won\'t be so bad.</p>\n\n<p><a href="http://homepages.inf.ed.ac.uk/amos/hough.html" rel="noreferrer">http://homepages.inf.ed.ac.uk/amos/hough.html</a><br/>\n<a href="http://rkb.home.cern.ch/rkb/AN16pp/node122.html" rel="noreferrer">http://rkb.home.cern.ch/rkb/AN16pp/node122.html</a><br/>\n<a href="http://en.wikipedia.org/wiki/Hough_transform" rel="noreferrer">http://en.wikipedia.org/wiki/Hough_transform</a></p>\n'}, {'answer_id': 714077, 'author': 'JeffH', 'author_id': 73826, 'author_profile': 'https://Stackoverflow.com/users/73826', 'pm_score': 1, 'selected': False, 'text': '<p>If you\'re willing to consider a different approach altogether to detecting illegal copies of your images, you could consider <a href="http://www.watermarkingworld.org/faq.html" rel="nofollow noreferrer">watermarking</a>. (from 1.4)</p>\n\n<blockquote>\n  <p>...inserts copyright information into the digital object without the loss of quality. Whenever the copyright of a digital object is in question, this information is extracted to identify the rightful owner. It is also possible to encode the identity of the original buyer along with the identity of the copyright holder, which allows tracing of any unauthorized copies.</p>\n</blockquote>\n\n<p>While it\'s also a complex field, there are techniques that allow the watermark information to persist through gross image alteration: (from 1.9)</p>\n\n<blockquote>\n  <p>... any signal transform of reasonable strength cannot remove the watermark. Hence a pirate willing to remove the watermark will not succeed unless they debase the document too much to be of commercial interest.</p>\n</blockquote>\n\n<p>of course, the faq calls implementing this approach: "...very challenging" but if you succeed with it, you get a high confidence of whether the image is a copy or not, rather than a percentage likelihood.</p>\n'}, {'answer_id': 1331835, 'author': 'Owen', 'author_id': 449081, 'author_profile': 'https://Stackoverflow.com/users/449081', 'pm_score': 3, 'selected': False, 'text': "<p>This is just a suggestion, it might not work and I'm prepared to be called on this.</p>\n\n<p>This will generate false positives, but hopefully not false negatives.</p>\n\n<ol>\n<li><p>Resize both of the images so that they are the same size (I assume that the ratios of widths to lengths are the same in both images).</p></li>\n<li><p>Compress a bitmap of both images with a lossless compression algorithm (e.g. gzip).</p></li>\n<li><p>Find pairs of files that have similar file sizes. For instance, you could just sort every pair of files you have by how similar the file sizes are and retrieve the top X.</p></li>\n</ol>\n\n<p>As I said, this will definitely generate false positives, but hopefully not false negatives. You can implement this in five minutes, whereas the Porikil et. al. would probably require extensive work.</p>\n"}, {'answer_id': 3444976, 'author': 'Nick Udell', 'author_id': 315544, 'author_profile': 'https://Stackoverflow.com/users/315544', 'pm_score': 2, 'selected': False, 'text': '<p>I believe if you\'re willing to apply the approach to every possible orientation and to negative versions, a good start to image recognition (with good reliability) is to use eigenfaces: <a href="http://en.wikipedia.org/wiki/Eigenface" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Eigenface</a></p>\n\n<p>Another idea would be to transform both images into vectors of their components. A good way to do this is to create a vector that operates in x*y dimensions (x being the width of your image and y being the height), with the value for each dimension applying to the (x,y) pixel value. Then run a variant of K-Nearest Neighbours with two categories: match and no match. If it\'s sufficiently close to the original image it will fit in the match category, if not then it won\'t.</p>\n\n<p>K Nearest Neighbours(KNN) can be found here, there are other good explanations of it on the web too: <a href="http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm</a></p>\n\n<p>The benefits of KNN is that the more variants you\'re comparing to the original image, the more accurate the algorithm becomes. The downside is you need a catalogue of images to train the system first.</p>\n'}, {'answer_id': 3445087, 'author': 'Tom Gullen', 'author_id': 356635, 'author_profile': 'https://Stackoverflow.com/users/356635', 'pm_score': 8, 'selected': False, 'text': '<p>These are simply ideas I\'ve had thinking about the problem, never tried it but I like thinking about problems like this!</p>\n\n<p><strong>Before you begin</strong></p>\n\n<p>Consider normalising the pictures, if one is a higher resolution than the other, consider the option that one of them is a compressed version of the other, therefore scaling the resolution down might provide more accurate results.</p>\n\n<p>Consider scanning various prospective areas of the image that could represent zoomed portions of the image and various positions and rotations.  It starts getting tricky if one of the images are a skewed version of another, these are the sort of limitations you should identify and compromise on.</p>\n\n<p><a href="https://www.mathworks.com/" rel="noreferrer">Matlab</a> is an excellent tool for testing and evaluating images.</p>\n\n<p><strong>Testing the algorithms</strong></p>\n\n<p>You should test (at the minimum) a large human analysed set of test data where matches are known beforehand.  If for example in your test data you have 1,000 images where 5% of them match, you now have a reasonably reliable benchmark.  An algorithm that finds 10% positives is not as good as one that finds 4% of positives in our test data.  However, one algorithm may find all the matches, but also have a large 20% false positive rate, so there are several ways to rate your algorithms.</p>\n\n<p>The test data should attempt to be designed to cover as many types of dynamics as possible that you would expect to find in the real world.</p>\n\n<p>It is important to note that each algorithm to be useful must perform better than random guessing, otherwise it is useless to us!</p>\n\n<p>You can then apply your software into the real world in a controlled way and start to analyse the results it produces.  This is the sort of software project which can go on for infinitum, there are always tweaks and improvements you can make, it is important to bear that in mind when designing it as it is easy to fall into the trap of the never ending project.</p>\n\n<p><strong>Colour Buckets</strong></p>\n\n<p>With two pictures, scan each pixel and count the colours.  For example you might have the \'buckets\':</p>\n\n<pre><code>white\nred\nblue\ngreen\nblack\n</code></pre>\n\n<p>(Obviously you would have a higher resolution of counters).  Every time you find a \'red\' pixel, you increment the red counter.  Each bucket can be representative of spectrum of colours, the higher resolution the more accurate but you should experiment with an acceptable difference rate.</p>\n\n<p>Once you have your totals, compare it to the totals for a second image.  You might find that each image has a fairly unique footprint, enough to identify matches.</p>\n\n<p><strong>Edge detection</strong></p>\n\n<p>How about using <a href="https://en.wikipedia.org/wiki/Edge_detection" rel="noreferrer">Edge Detection</a>.\n<a href="https://i.stack.imgur.com/mY9PV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mY9PV.png" alt="alt text"></a><br>\n<sub>(source: <a href="http://upload.wikimedia.org/wikipedia/en/thumb/8/8e/EdgeDetectionMathematica.png/500px-EdgeDetectionMathematica.png" rel="noreferrer">wikimedia.org</a>)</sub>  </p>\n\n<p>With two similar pictures edge detection should provide you with a usable and fairly reliable unique footprint.</p>\n\n<p>Take both pictures, and apply edge detection.  Maybe measure the average thickness of the edges and then calculate the probability the image could be scaled, and rescale if necessary.  Below is an example of an applied <a href="https://en.wikipedia.org/wiki/Gabor_filter" rel="noreferrer">Gabor Filter</a> (a type of edge detection) in various rotations.</p>\n\n<p><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b5/Gabor-ocr.png/220px-Gabor-ocr.png" alt="alt text"></p>\n\n<p>Compare the pictures pixel for pixel, count the matches and the non matches.  If they are within a certain threshold of error, you have a match.  Otherwise, you could try reducing the resolution up to a certain point and see if the probability of a match improves.  </p>\n\n<p><strong>Regions of Interest</strong></p>\n\n<p>Some images may have distinctive segments/regions of interest.  These regions probably contrast highly with the rest of the image, and are a good item to search for in your other images to find matches.  Take this image for example:</p>\n\n<p><a href="https://i.stack.imgur.com/Sgg79.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/Sgg79.jpg" alt="alt text"></a><br>\n<sub>(source: <a href="http://meetthegimp.org/wp-content/uploads/2009/04/97.jpg" rel="noreferrer">meetthegimp.org</a>)</sub>  </p>\n\n<p>The construction worker in blue is a region of interest and can be used as a search object.  There are probably several ways you could extract properties/data from this region of interest and use them to search your data set.</p>\n\n<p>If you have more than 2 regions of interest, you can measure the distances between them.  Take this simplified example:</p>\n\n<p><a href="https://i.stack.imgur.com/z7U80.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/z7U80.jpg" alt="alt text"></a><br>\n<sub>(source: <a href="http://www.per2000.eu/assets/images/3_dots_black_03.jpg" rel="noreferrer">per2000.eu</a>)</sub>  </p>\n\n<p>We have 3 clear regions of interest.  The distance between region 1 and 2 may be 200 pixels, between 1 and 3 400 pixels, and 2 and 3 200 pixels.</p>\n\n<p>Search other images for similar regions of interest, normalise the distance values and see if you have potential matches.  This technique could work well for rotated and scaled images.  The more regions of interest you have, the probability of a match increases as each distance measurement matches.</p>\n\n<p>It is important to think about the context of your data set.  If for example your data set is modern art, then regions of interest would work quite well, as regions of interest were probably <em>designed</em> to be a fundamental part of the final image.  If however you are dealing with images of construction sites, regions of interest may be interpreted by the illegal copier as ugly and may be cropped/edited out liberally.  Keep in mind common features of your dataset, and attempt to exploit that knowledge.</p>\n\n<p><strong>Morphing</strong></p>\n\n<p><a href="https://en.wikipedia.org/wiki/Morphing" rel="noreferrer">Morphing</a> two images is the process of turning one image into the other through a set of steps:</p>\n\n<p><img src="https://t0.gstatic.com/images?q=tbn:ff9g8dy_q1Nr4M:http://blog.ekoventure.com/data//1498/original/morph.jpg&amp;t=1" alt="alt text"></p>\n\n<p>Note, this is different to fading one image into another!</p>\n\n<p>There are many software packages that can morph images.  It\'s traditionaly used as a transitional effect, two images don\'t morph into something halfway usually, one extreme morphs into the other extreme as the final result.</p>\n\n<p>Why could this be useful?  Dependant on the morphing algorithm you use, there may be a relationship between similarity of images, and some parameters of the morphing algorithm.</p>\n\n<p>In a grossly over simplified example, one algorithm might execute faster when there are less changes to be made.  We then know there is a higher probability that these two images share properties with each other.</p>\n\n<p>This technique <em>could</em> work well for rotated, distorted, skewed, zoomed, all types of copied images.  Again this is just an idea I have had, it\'s not based on any researched academia as far as I am aware (I haven\'t look hard though), so it may be a lot of work for you with limited/no results.</p>\n\n<p><strong>Zipping</strong></p>\n\n<p>Ow\'s answer in this question is excellent, I remember reading about these sort of techniques studying AI. It is quite effective at comparing corpus lexicons.</p>\n\n<p>One interesting optimisation when comparing corpuses is that you can remove words considered to be too common, for example \'The\', \'A\', \'And\' etc.  These words dilute our result, we want to work out how different the two corpus are so these can be removed before processing.  Perhaps there are similar common signals in images that could be stripped before compression?  It might be worth looking into.</p>\n\n<p>Compression ratio is a very quick and reasonably effective way of determining how similar two sets of data are.  Reading up about <a href="https://computer.howstuffworks.com/file-compression.htm" rel="noreferrer">how compression works</a> will give you a good idea why this could be so effective.  For a fast to release algorithm this would probably be a good starting point.</p>\n\n<p><strong>Transparency</strong></p>\n\n<p>Again I am unsure how transparency data is stored for certain image types, gif png etc, but this will be extractable and would serve as an effective simplified cut out to compare with your data sets transparency.</p>\n\n<p><strong>Inverting Signals</strong></p>\n\n<p>An image is just a signal.  If you play a noise from a speaker, and you play the opposite noise in another speaker in perfect sync at the exact same volume, they cancel each other out.</p>\n\n<p><a href="https://i.stack.imgur.com/Jq3kQ.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/Jq3kQ.gif" alt="alt text"></a><br>\n<sub>(source: <a href="http://www.themotorreport.com.au/wp-content/uploads/2008/07/noise-cancellation.gif" rel="noreferrer">themotorreport.com.au</a>)</sub>  </p>\n\n<p>Invert on of the images, and add it onto your other image.  Scale it/loop positions repetitively until you find a resulting image where enough of the pixels are white (or black?  I\'ll refer to it as a neutral canvas) to provide you with a positive match, or partial match.</p>\n\n<p>However, consider two images that are equal, except one of them has a brighten effect applied to it:</p>\n\n<p><a href="https://i.stack.imgur.com/24hiI.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/24hiI.jpg" alt="alt text"></a><br>\n<sub>(source: <a href="https://www.mcburrz.com/images/photo/brighten.jpg" rel="noreferrer">mcburrz.com</a>)</sub>  </p>\n\n<p>Inverting one of them, then adding it to the other will not result in a neutral canvas which is what we are aiming for.  However, when comparing the pixels from both original images, we can definatly see a clear relationship between the two.</p>\n\n<p>I haven\'t studied colour for some years now, and am unsure if the colour spectrum is on a linear scale, but if you determined the average factor of colour difference between both pictures, you can use this value to normalise the data before processing with this technique.</p>\n\n<p><strong>Tree Data structures</strong></p>\n\n<p>At first these don\'t seem to fit for the problem, but I think they could work.</p>\n\n<p>You could think about extracting certain properties of an image (for example colour bins) and generate a <a href="https://en.wikipedia.org/wiki/Huffman_coding" rel="noreferrer">huffman tree</a> or similar data structure.  You might be able to compare two trees for similarity.  This wouldn\'t work well for photographic data for example with a large spectrum of colour, but cartoons or other reduced colour set images this might work.</p>\n\n<p>This probably wouldn\'t work, but it\'s an idea.  The <a href="https://en.wikipedia.org/wiki/Trie" rel="noreferrer">trie datastructure</a> is great at storing lexicons, for example a dictionarty.  It\'s a prefix tree.  Perhaps it\'s possible to build an image equivalent of a lexicon, (again I can only think of colours) to construct a trie.  If you reduced say a 300x300 image into 5x5 squares, then decompose each 5x5 square into a sequence of colours you could construct a trie from the resulting data.  If a 2x2 square contains:</p>\n\n<pre><code>FFFFFF|000000|FDFD44|FFFFFF\n</code></pre>\n\n<p>We have a fairly unique trie code that extends 24 levels, increasing/decreasing the levels (IE reducing/increasing the size of our sub square) may yield more accurate results.</p>\n\n<p>Comparing trie trees should be reasonably easy, and could possible provide effective results. </p>\n\n<p><strong>More ideas</strong></p>\n\n<p>I stumbled accross an interesting paper breif about <a href="https://ieeexplore.ieee.org/document/387577/?arnumber=387577" rel="noreferrer">classification of satellite imagery</a>, it outlines:</p>\n\n<blockquote>\n  <p>Texture measures considered are: cooccurrence matrices, gray-level differences, texture-tone analysis, features derived from the Fourier spectrum, and Gabor filters. Some Fourier features and some Gabor filters were found to be good choices, in particular when a single frequency band was used for classification.</p>\n</blockquote>\n\n<p>It may be worth investigating those measurements in more detail, although some of them may not be relevant to your data set.</p>\n\n<p><strong>Other things to consider</strong></p>\n\n<p>There are probably a lot of papers on this sort of thing, so reading some of them should help although they can be very technical.  It is an extremely difficult area in computing, with many fruitless hours of work spent by many people attempting to do similar things.  Keeping it simple and building upon those ideas would be the best way to go.  It should be a reasonably difficult challenge to create an algorithm with a better than random match rate, and to start improving on that really does start to get quite hard to achieve.</p>\n\n<p>Each method would probably need to be tested and tweaked thoroughly, if you have any information about the type of picture you will be checking as well, this would be useful.  For example advertisements, many of them would have text in them, so doing text recognition would be an easy and probably very reliable way of finding matches especially when combined with other solutions.  As mentioned earlier, attempt to exploit common properties of your data set.</p>\n\n<p>Combining alternative measurements and techniques each that can have a weighted vote (dependant on their effectiveness) would be one way you could create a system that generates more accurate results.</p>\n\n<p>If employing multiple algorithms, as mentioned at the begining of this answer, one may find all the positives but have a false positive rate of 20%, it would be of interest to study the properties/strengths/weaknesses of other algorithms as another algorithm may be effective in eliminating false positives returned from another.</p>\n\n<p>Be careful to not fall into attempting to complete the never ending project, good luck!</p>\n'}, {'answer_id': 3464874, 'author': 'navneeth', 'author_id': 191241, 'author_profile': 'https://Stackoverflow.com/users/191241', 'pm_score': 3, 'selected': False, 'text': '<p>In the form described by you, the problem is tough. Do you consider copy, paste of part of the image into another larger image as a copy ? etc.</p>\n<p>What we loosely refer to as duplicates can be difficult for algorithms to discern.\nYour duplicates can be either:</p>\n<ol>\n<li>Exact Duplicates</li>\n<li>Near-exact Duplicates. (minor edits of image etc)</li>\n<li>perceptual Duplicates (same content, but different view, camera etc)</li>\n</ol>\n<p>No1 &amp; 2 are easier to solve. No 3. is very subjective and still a research topic.\nI can offer a solution for No1 &amp; 2.\nBoth solutions use the excellent image hash- hashing library: <a href="https://github.com/JohannesBuchner/imagehash" rel="nofollow noreferrer">https://github.com/JohannesBuchner/imagehash</a></p>\n<ol>\n<li>Exact duplicates\nExact duplicates can be found using a perceptual hashing measure.\nThe phash library is quite good at this. I routinely use it to clean\ntraining data.\nUsage (from github site) is as simple as:</li>\n</ol>\n<pre><code>from PIL import Image\nimport imagehash\n\n# image_fns : List of training image files\nimg_hashes = {}\n\nfor img_fn in sorted(image_fns):\n    hash = imagehash.average_hash(Image.open(image_fn))\n    if hash in img_hashes:\n        print( \'{} duplicate of {}\'.format(image_fn, img_hashes[hash]) )\n    else:\n        img_hashes[hash] = image_fn\n</code></pre>\n<ol start="2">\n<li>Near-Exact Duplicates\nIn this case you will have to set a threshold and compare the hash values for their distance from each\nother. This has to be done by trial-and-error for your image content.</li>\n</ol>\n<pre><code>from PIL import Image\nimport imagehash\n\n# image_fns : List of training image files\nimg_hashes = {}\nepsilon = 50\n\nfor img_fn1, img_fn2 in zip(image_fns, image_fns[::-1]):\n    if image_fn1 == image_fn2:\n        continue\n\n    hash1 = imagehash.average_hash(Image.open(image_fn1))\n    hash2 = imagehash.average_hash(Image.open(image_fn2))\n    if hash1 - hash2 &lt; epsilon:\n        print( \'{} is near duplicate of {}\'.format(image_fn1, image_fn2) )\n\n</code></pre>\n<p>If you take a step-back, this is easier to solve if you watermark the master images.\nYou will need to use a watermarking scheme to embed a code into the image. To take a step back, as opposed to some of the low-level approaches (edge detection etc) suggested by some folks, a watermarking method is superior because:</p>\n<p>It is resistant to Signal processing attacks\n► Signal enhancement – sharpening, contrast, etc.\n► Filtering – median, low pass, high pass, etc.\n► Additive noise – Gaussian, uniform, etc.\n► Lossy compression – JPEG, MPEG, etc.</p>\n<p>It is resistant to Geometric attacks\n► Affine transforms\n► Data reduction – cropping, clipping, etc.\n► Random local distortions\n► Warping</p>\n<p>Do some research on watermarking algorithms and you will be on the right path to solving your problem. (\nNote: You can benchmark you method using the <a href="http://www.petitcolas.net/fabien/watermarking/stirmark/" rel="nofollow noreferrer">STIRMARK</a> dataset. It is an accepted standard for this type of application.</p>\n'}, {'answer_id': 3467477, 'author': 'sastanin', 'author_id': 25450, 'author_profile': 'https://Stackoverflow.com/users/25450', 'pm_score': 5, 'selected': False, 'text': '<p>An idea:</p>\n\n<ol>\n<li>use keypoint detectors to find scale- and transform- invariant descriptors of some points in the image (e.g. SIFT, SURF, GLOH, or LESH).</li>\n<li>try to align keypoints with similar descriptors from both images (like in panorama stitching), allow for some image transforms if necessary (e.g. scale &amp; rotate, or elastic stretching).</li>\n<li>if many keypoints align well (exists such a transform, that keypoint alignment error is low; or transformation "energy" is low, etc.), you likely have similar images.</li>\n</ol>\n\n<p>Step 2 is not trivial. In particular, you may need to use a smart algorithm to find the most similar keypoint on the other image. Point descriptors are usually very high-dimensional (like a hundred parameters), and there are many points to look through. kd-trees may be useful here, hash lookups don\'t work well.</p>\n\n<p>Variants:</p>\n\n<ul>\n<li>Detect edges or other features instead of points.</li>\n</ul>\n'}, {'answer_id': 41258546, 'author': 'unfa', 'author_id': 1363337, 'author_profile': 'https://Stackoverflow.com/users/1363337', 'pm_score': 1, 'selected': False, 'text': '<p>If you\'re running Linux I would suggest two tools:</p>\n\n<p><strong>align_image_stack from package hugin-tools</strong> - is a commandline program that can automatically correct rotation, scaling, and other distortions (it\'s mostly intended for compositing HDR photography, but works for video frames and other documents too). More information: <a href="http://hugin.sourceforge.net/docs/manual/Align_image_stack.html" rel="nofollow noreferrer">http://hugin.sourceforge.net/docs/manual/Align_image_stack.html</a></p>\n\n<p><strong>compare from package imagemagick</strong> - a program that can find and count the amount of different pixels in two images. Here\'s a neat tutorial: <a href="http://www.imagemagick.org/Usage/compare/" rel="nofollow noreferrer">http://www.imagemagick.org/Usage/compare/</a>  uising the -fuzz N% you can increase the error tolerance. The higher the N the higher the error tolerance to still count two pixels as the same.</p>\n\n<p>align_image_stack should correct any offset so the compare command will actually have a chance of detecting same pixels.</p>\n'}]
['https://Stackoverflow.com/questions/23931', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']