views:

387

answers:

7

This is a fairly broad question; what tools/libraries exist to take two photographs that are not identical, but extremely similar, and identify the specific differences between them?

An example would be to take a picture of my couch on Friday after my girlfriend is done cleaning and before a long weekend of having friends over, drinking, and playing rock band. Two days later I take a second photo of the couch; lighting is identical, the couch hasn't moved a milimeter, and I use a tripod in a fixed location.

What tools could I use to generate a diff of the images, or a third heatmap image of the differences? Are there any tools for .NET?

+3  A: 

This depends largely on the image format and compression. But, at the end of the day, you are probably taking two rasters and comparing them pixel by pixel.

Take a look at the Perceptual Image Difference Utility.

dirkgently
Thanks for the link, I'll definately be playing with that to see if it's a good jump-off point for what I'm doing.
STW
+1  A: 

It's an interesting question. I can't refer you to any specific libraries, but the process you're asking about is basically a minimal case of motion compensation. This is the way that MPEG (MP4, DIVX, whatever) video manages to compress video so extremely well; you might look into MPEG for some information about the way those motion compensation algorithms are implemented.

One other thing to keep in mind; JPEG compression is a block-based compression; much of the benefit that MPEG brings from things is to actually do a block comparison. If most of your image (say the background) is the same from one image to the next, those blocks will be unchanged. It's a quick way to reduce the amount of data needed to be compared.

McWafflestix
That's something that I never considered, but a great point
STW
You could even assemble a short clip from a copy of the before image and a copy the after image. Compress that with MPEG, and analyze the result.... ;-)
RBerteig
+1  A: 

The most obvious way to see every tiny, normally nigh-imperceptible difference, would be to XOR the pixel data. If the lighting is even slightly different, though, it might be too much. Differencing (subtracting) the pixel data might be more what you're looking for, depending on how subtle the differences are.

pyrochild
I'll definately have to play with that; it's probably one of the few approaches that I could develop from scratch within my skill level
STW
If you want to see some these approaches in action before coding them yourself, take a look at any layered raster graphics editor's layer composition modes. Paint.NET's are the ones I'm thinking of, but it's a basic binary pixel op, so all implementations should be the same.
pyrochild
+1  A: 

One place to start is with a rich image processing library such as IM. You can dabble with its operators interactively with the IMlab tool, call it directly from C or C++, or use its really decent Lua binding to drive it from Lua. It supports a wide array of operations on bitmaps, as well as an extensible library of file formats.

Even if you haven't deliberately moved anything, you might want to use an algorithm such as SIFT to get good sub-pixel quality alignment between the frames. Unless you want to treat the camera as fixed and detect motion of the couch as well.

RBerteig
That is both exactlyt the answer I was both dreading and hoping for; I'm not a C or C++ or Lua developer--but this looks like a fun project to get my feet/torso/head/snorkle wet with. I'll probably be in over my head but I suppose that's why I mentioned the snorkel
STW
If you dive in, you'll want to look at its companion libraries CD and IUP. CD provides a generic canvas for drawing on bitmaps (or screen) and IUP provides a portable UI framework. Links are at the IMLab page. There's lots of Lua help at www.lua.org through the official mailing list, and a user to user wiki, or here tagged "lua" to serve as that oh-so-vital snorkel when you need it. ;-)
RBerteig
+1  A: 

Check out Andrew Kirillov's article on CodeProject. He wrote a C# application using the AForge.NET computer vision library to detect motion. On the AForge.NET website, there's a discussion of two frame differences for motion detection.

Jeff Youel
+2  A: 

I wrote this free .NET application using the toolkit my company makes (DotImage). It has a very simple algorithm, but the code is open source if you want to play with it -- you could adapt the algorithm to .NET Image classes if you don't want to buy a copy of DotImage.

http://www.atalasoft.com/cs/blogs/31appsin31days/archive/2008/05/13/image-difference-utility.aspx

Lou Franco
A: 

just use the .net imaging classes, create a new bitmap() x 2 and look at the R & G & B values of each pixel, you can also look at the A (Alpha/transparency) values if you want to when determining difference.

also a note, using the getPixel(y, x) method can be vastly slow, there is another way to get the entire image (less elegant) and for each ing through it yourself if i remember it was called the getBitmap or something similar, look in the imaging/bitmap classes & read some tutes they really are all you need & aren't that difficult to use, dont go third party unless you have to.

Erx_VB.NExT.Coder
ps: email me if you need more resources/help on this, i spent 2 years of my life with this class a while back now :)
Erx_VB.NExT.Coder