- Category: Software
- Published on Thursday, 20 November 2014 06:13
- Hits: 4477
Image subtraction is the process where the numerical values for individual pixels from two images are subtracted from one another, and the resulting values are used to construct a new image. The resulting image is analogous to a map of the differences between the two pictures. In a Search and Rescue context, this could feasibly used to determine the difference between aerial photographs over time, and locate a subject that has moved or caused disturbance. This is practically difficult for a variety of reasons, but other applications are easier to implement.
For man tracking, image subtraction can be useful for highlighting footprints in training photographs of footprints. Taking before and after pictures in this instance is fairly easy, and the use of a tripod virtually eliminates any image alignment problems. The image below shows a fairly easy to see footprint in a desert wash. A trained eye can see the heel on the left and the toe on the right, but this is very difficult for most without formal tracking training.
Subtracting this image from a before picture of the same spot, keeping the camera on a tripod to maintain alignment, yields this picture:
Here is it easier to see the footprint.
The computer program that created the subtracted image is very short, although that is because it uses some very powerful programming tools. The programming language is called Python, and the two tools that is uses are called SciPy and NumPy. These can be downloaded as a package in the WinPython distribution for Windows. The source code for Python image subtraction is here:
|beforemisc.imread( , )|
|aftermisc.imread( , )|
The first two lines import the libraries SciPy and NumPy, which are used later. The lines defining the variables 'before' and 'after' read the images into arrays of numbers which are flattened, or turned into grayscale images. The line defining the variable 'subtracted' subtracts the two arrays from each other, and the final line writes the results to a new image file. There is a lot that could be done to improve this code, such as a check for overwriting an existing file before subtracted.jpg is written, but the basic image processing is here.
Another interesting set of photos is below. This is a very difficult track for even a well trained and practiced tracker to pick out, but the software does a nice job of extracting the differences. This particular case worked out better doing the subtraction in color rather than in grayscale.
You can download high resolution versions of these images here, but be warned, it's a large file. Before_and_After_High_Res (142 MB zip file).