se.lth.cs.jpeg
Class JPEGMotionDetector

java.lang.Object
  |
  +--se.lth.cs.jpeg.JPEGMotionDetector

public class JPEGMotionDetector
extends java.lang.Object

Motion detector for JPEG encoded images. Decodes images internally and computes the difference from the last image.

Sampling distance

A sampling distance of N means that only every Nth pixel, in both X and Y dimensions, is inspected in images. In other words, only one out of totally N*N pixels is inspected. Larger N means lower execution time and lower precision.

The JPEG decoding algorithm is tuned to only decode to the necessary resolution; higher sampling distance means that the image is decoded to lower resolution, which takes less time.

Spotting where in the image something moves

The motion detection algorithm works by computing the difference between two images. The "centre of gravity" in the difference image gives a rough idea of where in the image something is happening. After a comparison, the coordinates of this point can be retrieved using getMotionX() and getMotionY(). However, note that these coordinates only make sense if something is actually moving.

(Implementation note: to make the algorithm focus on a few large differences (motion) rather than many small ones (noise), all elements in the difference image are squared before computing the centre of gravity. This modification amplifies large differences.)


Constructor Summary
JPEGMotionDetector(int width, int height, int samplingDistance)
          Create a motion detector with a given sampling distance.
 
Method Summary
 int compareToPrevious(byte[] image)
           Returns the image difference between the given image and the previous one, in the range of 0 (no difference) to 255 (completely different).
 void finalize()
          Finalizer.
 int getMotionX()
           
 int getMotionY()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JPEGMotionDetector

public JPEGMotionDetector(int width,
                          int height,
                          int samplingDistance)
Create a motion detector with a given sampling distance.

Parameters:
width - Image width in pixels
height - Image height in pixels
samplingDistance - Sampling distance. The only legal values are 1, 2, 4, and 8.
Method Detail

compareToPrevious

public int compareToPrevious(byte[] image)

Returns the image difference between the given image and the previous one, in the range of 0 (no difference) to 255 (completely different).

On the first call, there is no previous image to compare to (of course). This method then returns zero.

This method also determines the point of interest (POI), which is the point in the image where the largest differences occur. After calling this method, the POI can be determined using methods getMotionX() and getMotionY().

Parameters:
image - The image in JPEG encoded form.
Throws:
java.lang.IndexOutOfBoundsException - If the size of the image differs from that given in constructor
java.lang.IllegalArgumentException - If the image is not correctly JPEG encoded

finalize

public void finalize()
              throws java.lang.Throwable
Finalizer. Cleans up any data structures allocated in the native code. Called by the Java runtime system on system shutdown; not to be called by your code.

Overrides:
finalize in class java.lang.Object

getMotionX

public int getMotionX()
Returns:
the X coordinate of the point of interest (POI).

getMotionY

public int getMotionY()
Returns:
the Y coordinate of the point of interest (POI).