fi.helsinki.cs.ohtu.mpeg2.video
Class SimpleDiscreteCosineTransform

java.lang.Object
  extended by fi.helsinki.cs.ohtu.mpeg2.video.SimpleDiscreteCosineTransform
All Implemented Interfaces:
DiscreteCosineTransform, InverseDiscreteCosineTransform

public class SimpleDiscreteCosineTransform
extends java.lang.Object
implements DiscreteCosineTransform, InverseDiscreteCosineTransform

The algorithms in this class are the trivial algorithms directly based on the definitions of the transforms. Both have a complexity of O(n^2), where n is the number of elements in the input. However, the constant factor is quite low due to pre-calculating lookup tables for the more expensive terms in the calculations.


Field Summary
private static java.util.HashMap<java.lang.Integer,double[]> cosPrecalc
           
 
Constructor Summary
SimpleDiscreteCosineTransform()
           
 
Method Summary
private static double C(int a)
           
private static double[] getPrecalc(int size)
          Performs calculating the most expensive term of the DCT process in advance and caches the result.
 double[] transformFromFrequencySpace(int[] input, int size)
          Transforms one image with the IDCT.
 double[] transformToFrequencySpace(int[] input, int size)
          Transforms one image with the DCT.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cosPrecalc

private static java.util.HashMap<java.lang.Integer,double[]> cosPrecalc
Constructor Detail

SimpleDiscreteCosineTransform

public SimpleDiscreteCosineTransform()
Method Detail

transformToFrequencySpace

public double[] transformToFrequencySpace(int[] input,
                                          int size)
Description copied from interface: DiscreteCosineTransform
Transforms one image with the DCT.

Specified by:
transformToFrequencySpace in interface DiscreteCosineTransform
Parameters:
input - The image to be transformed
size - The number of rows and columns in the image
Returns:
The transformed image

transformFromFrequencySpace

public double[] transformFromFrequencySpace(int[] input,
                                            int size)
Description copied from interface: InverseDiscreteCosineTransform
Transforms one image with the IDCT.

Specified by:
transformFromFrequencySpace in interface InverseDiscreteCosineTransform
Parameters:
input - The image to be transformed
size - The number of rows and columns in the image
Returns:
The transformed image

C

private static double C(int a)
Parameters:
a - The coordinate for which to calculate the coefficient
Returns:
1/sqrt(2) if a is zero, 1 otherwise

getPrecalc

private static double[] getPrecalc(int size)
Performs calculating the most expensive term of the DCT process in advance and caches the result. The value at index i * size + j in the returned array will contain the value cos(((2 * j + 1) * i * Math.pi) / (2 * size)). The use of this precalc doesn't in any way hamper the thread-safety of the DCT.

Returns:
The precalculated array.