Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find rectangle of difference between two images

I have two images the same size. What is the best way to find the rectangle in which they differ. Obviously I could go through the image 4 times in different directions, but i'm wondering if there's an easier way.

Example:

first image

second image

difference

like image 916
Gelatin Avatar asked Apr 24 '10 14:04

Gelatin


People also ask

How do you find the difference between two pictures?

The difference between two images is calculated by finding the difference between each pixel in each image, and generating an image based on the result.


2 Answers

A naive approach would be to start at the origin, and work line by line, column by column. Compare each pixel, keeping note of the topmost, leftmost, rightmost, and bottommost, from which you can calculate your rectangle. There will be cases where this single pass approach would be faster (i.e. where there is a very small differing area)

like image 129
Rowland Shaw Avatar answered Sep 21 '22 06:09

Rowland Shaw


Image processing like this is expensive, there are a lot of bits to look at. In real applications, you almost always need to filter the image to get rid of artifacts induced by imperfect image captures.

A common library used for this kind of bit whacking is OpenCV, it takes advantage of dedicated CPU instructions available to make this fast. There are several .NET wrappers available for it, Emgu is one of them.

like image 22
Hans Passant Avatar answered Sep 24 '22 06:09

Hans Passant