javax.media.jai
Class KernelJAI

java.lang.Object
  |
  +--javax.media.jai.KernelJAI
All Implemented Interfaces:
Serializable

public class KernelJAI
extends Object
implements Serializable

A kernel representing a matrix with a key position, used by operators such as Convolve .

A KernelJAI is characterized by its width, height, and origin, or key element. The key element is the element which is placed over the current source pixel to perform convolution or error diffusion.

A kernel K is separable it the outer product of two one-dimensional vectors. It can speed up computation. One can construct a kernel from two one-dimensional vectors. <>The symmetry can be useful (such as computation speedup). Currently the protected instance variables isHorizonallySymmetric and isVerticallySymmetric are set to false.

See Also:
ConvolveDescriptor, OrderedDitherDescriptor, ErrorDiffusionDescriptor, Serialized Form

Field Summary
protected  float[] data
          The kernel data in row-major format.
protected  float[] dataH
          The horizontal data for a separable kernel
protected  float[] dataV
          The vertical data for a separable kernel
static KernelJAI[] DITHER_MASK_441
          4x4x1 mask useful for dithering 8-bit grayscale images to 1-bit images.
static KernelJAI[] DITHER_MASK_443
          4x4x3 mask useful for dithering 24-bit color images to 8-bit pseudocolor images.
static KernelJAI ERROR_FILTER_FLOYD_STEINBERG
          Floyd and Steinberg error filter (1975).
static KernelJAI ERROR_FILTER_JARVIS
          Jarvis, Judice, and Ninke error filter (1976).
static KernelJAI ERROR_FILTER_STUCKI
          Stucki error filter (1981).
static KernelJAI GRADIENT_MASK_SOBEL_HORIZONTAL
          Gradient Mask for SOBEL_HORIZONTAL
static KernelJAI GRADIENT_MASK_SOBEL_VERTICAL
          Gradient Mask for SOBEL_VERTICAL
protected  int height
          The height of the kernel.
protected  boolean isHorizontallySymmetric
          True if the kernel has horizontal (Y axis) symmetry.
protected  boolean isSeparable
          True if the kernel is separable.
protected  boolean isVerticallySymmetric
          True if the kernel has vertical (X axis) symmetry.
protected  KernelJAI rotatedKernel
          Variable to cache a copy of the rotated kernel
protected  int width
          The width of the kernel.
protected  int xOrigin
          The X coordinate of the key element.
protected  int yOrigin
          The Y coordinate of the key element.
 
Constructor Summary
KernelJAI(int width, int height, float[] data)
          Constructs a kernel with the given parameters.
KernelJAI(int width, int height, int xOrigin, int yOrigin, float[] data)
          Constructs a KernelJAI with the given parameters.
KernelJAI(int width, int height, int xOrigin, int yOrigin, float[] dataH, float[] dataV)
          Constructs a separable KernelJAI from two float arrays.
KernelJAI(Kernel k)
          Constructs a KernelJAI from a java.awt.image.Kernel object.
 
Method Summary
 int getBottomPadding()
          Returns the number of pixels required below the key element.
 float getElement(int xIndex, int yIndex)
          Returns a given element of the kernel.
 int getHeight()
          Returns the height of the kernel.
 float[] getHorizontalKernelData()
          Returns the horizontal portion of the kernel if the kernel is separable, or null otherwise.
 float[] getKernelData()
          Returns a copy of the kernel data in row-major format.
 int getLeftPadding()
          Returns the number of pixels required to the left of the key element.
 int getRightPadding()
          Returns the number of pixels required to the right of the key element.
 KernelJAI getRotatedKernel()
          Returns a 180 degree rotated version of the kernel.
 int getTopPadding()
          Returns the number of pixels required above the key element.
 float[] getVerticalKernelData()
          Returns the vertical portion of the kernel if the kernel is separable, or null otherwise.
 int getWidth()
          Returns the width of the kernel.
 int getXOrigin()
          Returns the X coordinate of the key kernel element.
 int getYOrigin()
          Returns the Y coordinate of the key kernel element.
 boolean isHorizontallySymmetric()
          Returns true if the kernel has horizontal (Y axis) symmetry.
 boolean isSeparable()
          Returns true if the kernel is separable.
 boolean isVerticallySymmetric()
          Returns true if the kernel has vertical (X axis) symmetry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_FILTER_FLOYD_STEINBERG

public static final KernelJAI ERROR_FILTER_FLOYD_STEINBERG
Floyd and Steinberg error filter (1975).
 (1/16 x)  [   * 7 ]
           [ 3 5 1 ]
 

ERROR_FILTER_JARVIS

public static final KernelJAI ERROR_FILTER_JARVIS
Jarvis, Judice, and Ninke error filter (1976).
           [     * 7 5 ]
 (1/48 x)  [ 3 5 7 5 3 ]
           [ 1 3 5 3 1 ]
 

ERROR_FILTER_STUCKI

public static final KernelJAI ERROR_FILTER_STUCKI
Stucki error filter (1981).
           [     * 7 5 ]
 (1/42 x)  [ 2 4 8 4 2 ]
           [ 1 2 4 2 1 ]
 

DITHER_MASK_441

public static final KernelJAI[] DITHER_MASK_441
4x4x1 mask useful for dithering 8-bit grayscale images to 1-bit images.

DITHER_MASK_443

public static final KernelJAI[] DITHER_MASK_443
4x4x3 mask useful for dithering 24-bit color images to 8-bit pseudocolor images.

GRADIENT_MASK_SOBEL_HORIZONTAL

public static final KernelJAI GRADIENT_MASK_SOBEL_HORIZONTAL
Gradient Mask for SOBEL_HORIZONTAL

GRADIENT_MASK_SOBEL_VERTICAL

public static final KernelJAI GRADIENT_MASK_SOBEL_VERTICAL
Gradient Mask for SOBEL_VERTICAL

width

protected int width
The width of the kernel.

height

protected int height
The height of the kernel.

xOrigin

protected int xOrigin
The X coordinate of the key element.

yOrigin

protected int yOrigin
The Y coordinate of the key element.

data

protected float[] data
The kernel data in row-major format.

dataH

protected float[] dataH
The horizontal data for a separable kernel

dataV

protected float[] dataV
The vertical data for a separable kernel

isSeparable

protected boolean isSeparable
True if the kernel is separable.

isHorizontallySymmetric

protected boolean isHorizontallySymmetric
True if the kernel has horizontal (Y axis) symmetry.

isVerticallySymmetric

protected boolean isVerticallySymmetric
True if the kernel has vertical (X axis) symmetry.

rotatedKernel

protected KernelJAI rotatedKernel
Variable to cache a copy of the rotated kernel
Constructor Detail

KernelJAI

public KernelJAI(int width,
                 int height,
                 int xOrigin,
                 int yOrigin,
                 float[] data)
Constructs a KernelJAI with the given parameters. The data array is copied.
Parameters:
width - the width of the kernel.
height - the height of the kernel.
xOrigin - the X coordinate of the key kernel element.
yOrigin - the Y coordinate of the key kernel element.
data - the float data in row-major format.
Throws:
IllegalArgumentException - if data is null.
IllegalArgumentException - if width is not a positive number.
IllegalArgumentException - if height is not a positive number.
IllegalArgumentException - if kernel data array does not have width * height number of elements.

KernelJAI

public KernelJAI(int width,
                 int height,
                 int xOrigin,
                 int yOrigin,
                 float[] dataH,
                 float[] dataV)
Constructs a separable KernelJAI from two float arrays. The data arrays are copied. A Separable kernel K = dataH * dataV^T, the outer product of two one dimensional vectors dataH and dataV. It can often speed up compution.
Parameters:
width - the width of the kernel.
height - the height of the kernel.
xOrigin - the X coordinate of the key kernel element.
yOrigin - the Y coordinate of the key kernel element.
dataH - the float data for the horizontal direction.
dataV - the float data for the vertical direction.
Throws:
IllegalArgumentException - if dataH is null.
IllegalArgumentException - if dataV is null.
IllegalArgumentException - if width is not a positive number.
IllegalArgumentException - if height is not a positive number.
IllegalArgumentException - if dataH does not have width elements.
IllegalArgumentException - if dataV does not have height elements.

KernelJAI

public KernelJAI(int width,
                 int height,
                 float[] data)
Constructs a kernel with the given parameters. The data array is copied. The key element is set to (trunc(width/2), trunc(height/2)).
Parameters:
width - the width of the kernel.
height - the height of the kernel.
data - the float data in row-major format.
Throws:
IllegalArgumentException - if data is null.
IllegalArgumentException - if width is not a positive number.
IllegalArgumentException - if height is not a positive number.
IllegalArgumentException - if data does not have width * height number of elements.

KernelJAI

public KernelJAI(Kernel k)
Constructs a KernelJAI from a java.awt.image.Kernel object.
Throws:
NullPointerException - if k is null.
Method Detail

getWidth

public int getWidth()
Returns the width of the kernel.

getHeight

public int getHeight()
Returns the height of the kernel.

getXOrigin

public int getXOrigin()
Returns the X coordinate of the key kernel element.

getYOrigin

public int getYOrigin()
Returns the Y coordinate of the key kernel element.

getKernelData

public float[] getKernelData()
Returns a copy of the kernel data in row-major format.

getHorizontalKernelData

public float[] getHorizontalKernelData()
Returns the horizontal portion of the kernel if the kernel is separable, or null otherwise. The kernel may be tested for separability by calling isSeparable().

getVerticalKernelData

public float[] getVerticalKernelData()
Returns the vertical portion of the kernel if the kernel is separable, or null otherwise. The kernel may be tested for separability by calling isSeparable().

getElement

public float getElement(int xIndex,
                        int yIndex)
Returns a given element of the kernel.
Throws:
ArrayIndexOutOfBoundsException - if either xIndex or yIndex is an invalid index.

isSeparable

public boolean isSeparable()
Returns true if the kernel is separable.

isHorizontallySymmetric

public boolean isHorizontallySymmetric()
Returns true if the kernel has horizontal (Y axis) symmetry.

isVerticallySymmetric

public boolean isVerticallySymmetric()
Returns true if the kernel has vertical (X axis) symmetry.

getLeftPadding

public int getLeftPadding()
Returns the number of pixels required to the left of the key element.

getRightPadding

public int getRightPadding()
Returns the number of pixels required to the right of the key element.

getTopPadding

public int getTopPadding()
Returns the number of pixels required above the key element.

getBottomPadding

public int getBottomPadding()
Returns the number of pixels required below the key element.

getRotatedKernel

public KernelJAI getRotatedKernel()
Returns a 180 degree rotated version of the kernel. This is needed by most convolve operations to get the correct results.
Returns:
the rotated kernel.