com.jhlabs.image

Class ConvolveFilter

Implemented Interfaces:
BufferedImageOp, Cloneable
Known Direct Subclasses:
AverageFilter, BlurFilter, BumpFilter, GaussianFilter, SharpenFilter

public class ConvolveFilter
extends AbstractBufferedImageOp

A filter which applies a convolution kernel to an image.

Field Summary

static int
CLAMP_EDGES
Clamp pixels off the edge to the nearest edge.
static int
WRAP_EDGES
Wrap pixels off the edge to the opposite edge.
static int
ZERO_EDGES
Treat pixels off the edge as zero.
protected boolean
alpha
Whether to convolve alpha.
protected Kernel
kernel
The convolution kernel.
protected boolean
premultiplyAlpha
Whether to promultiply the alpha before convolving.

Constructor Summary

ConvolveFilter()
Construct a filter with a null kernel.
ConvolveFilter(Kernel kernel)
Construct a filter with the given 3x3 kernel.
ConvolveFilter(float[] matrix)
Construct a filter with the given 3x3 kernel.
ConvolveFilter(int rows, int cols, float[] matrix)
Construct a filter with the given kernel.

Method Summary

static void
convolve(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve a block of pixels.
static void
convolve(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, int edgeAction)
Convolve a block of pixels.
static void
convolveH(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve with a kernel consisting of one row.
static void
convolveHV(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve with a 2D kernel.
static void
convolveV(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction)
Convolve with a kernel consisting of one column.
BufferedImage
createCompatibleDestImage(BufferedImage src, ColorModel dstCM)
BufferedImage
filter(BufferedImage src, BufferedImage dst)
Rectangle2D
getBounds2D(BufferedImage src)
int
getEdgeAction()
Get the action to perfomr for pixels off the image edges.
Kernel
getKernel()
Get the convolution kernel.
Point2D
getPoint2D(Point2D srcPt, Point2D dstPt)
boolean
getPremultiplyAlpha()
Get whether to premultiply the alpha channel.
RenderingHints
getRenderingHints()
boolean
getUseAlpha()
Get whether to convolve the alpha channel.
void
setEdgeAction(int edgeAction)
Set the action to perfomr for pixels off the image edges.
void
setKernel(Kernel kernel)
Set the convolution kernel.
void
setPremultiplyAlpha(boolean premultiplyAlpha)
Set whether to premultiply the alpha channel.
void
setUseAlpha(boolean useAlpha)
Set whether to convolve the alpha channel.
String
toString()

Methods inherited from class com.jhlabs.image.AbstractBufferedImageOp

clone, createCompatibleDestImage, getBounds2D, getPoint2D, getRGB, getRenderingHints, setRGB

Field Details

CLAMP_EDGES

public static int CLAMP_EDGES
Clamp pixels off the edge to the nearest edge.

WRAP_EDGES

public static int WRAP_EDGES
Wrap pixels off the edge to the opposite edge.

ZERO_EDGES

public static int ZERO_EDGES
Treat pixels off the edge as zero.

alpha

protected boolean alpha
Whether to convolve alpha.

kernel

protected Kernel kernel
The convolution kernel.

premultiplyAlpha

protected boolean premultiplyAlpha
Whether to promultiply the alpha before convolving.

Constructor Details

ConvolveFilter

public ConvolveFilter()
Construct a filter with a null kernel. This is only useful if you're going to change the kernel later on.

ConvolveFilter

public ConvolveFilter(Kernel kernel)
Construct a filter with the given 3x3 kernel.
Parameters:
kernel - the convolution kernel

ConvolveFilter

public ConvolveFilter(float[] matrix)
Construct a filter with the given 3x3 kernel.
Parameters:
matrix - an array of 9 floats containing the kernel

ConvolveFilter

public ConvolveFilter(int rows,
                      int cols,
                      float[] matrix)
Construct a filter with the given kernel.
Parameters:
rows - the number of rows in the kernel
cols - the number of columns in the kernel
matrix - an array of rows*cols floats containing the kernel

Method Details

convolve

public static void convolve(Kernel kernel,
                            int[] inPixels,
                            int[] outPixels,
                            int width,
                            int height,
                            boolean alpha,
                            int edgeAction)
Convolve a block of pixels.
Parameters:
kernel - the kernel
inPixels - the input pixels
outPixels - the output pixels
width - the width
height - the height
alpha - include alpha channel
edgeAction - what to do at the edges

convolve

public static void convolve(Kernel kernel,
                            int[] inPixels,
                            int[] outPixels,
                            int width,
                            int height,
                            int edgeAction)
Convolve a block of pixels.
Parameters:
kernel - the kernel
inPixels - the input pixels
outPixels - the output pixels
width - the width
height - the height
edgeAction - what to do at the edges

convolveH

public static void convolveH(Kernel kernel,
                             int[] inPixels,
                             int[] outPixels,
                             int width,
                             int height,
                             boolean alpha,
                             int edgeAction)
Convolve with a kernel consisting of one row.
Parameters:
kernel - the kernel
inPixels - the input pixels
outPixels - the output pixels
width - the width
height - the height
alpha - include alpha channel
edgeAction - what to do at the edges

convolveHV

public static void convolveHV(Kernel kernel,
                              int[] inPixels,
                              int[] outPixels,
                              int width,
                              int height,
                              boolean alpha,
                              int edgeAction)
Convolve with a 2D kernel.
Parameters:
kernel - the kernel
inPixels - the input pixels
outPixels - the output pixels
width - the width
height - the height
alpha - include alpha channel
edgeAction - what to do at the edges

convolveV

public static void convolveV(Kernel kernel,
                             int[] inPixels,
                             int[] outPixels,
                             int width,
                             int height,
                             boolean alpha,
                             int edgeAction)
Convolve with a kernel consisting of one column.
Parameters:
kernel - the kernel
inPixels - the input pixels
outPixels - the output pixels
width - the width
height - the height
alpha - include alpha channel
edgeAction - what to do at the edges

createCompatibleDestImage

public BufferedImage createCompatibleDestImage(BufferedImage src,
                                               ColorModel dstCM)
Overrides:
createCompatibleDestImage in interface AbstractBufferedImageOp

filter

public BufferedImage filter(BufferedImage src,
                            BufferedImage dst)

getBounds2D

public Rectangle2D getBounds2D(BufferedImage src)
Overrides:
getBounds2D in interface AbstractBufferedImageOp

getEdgeAction

public int getEdgeAction()
Get the action to perfomr for pixels off the image edges.
Returns:
the action

getKernel

public Kernel getKernel()
Get the convolution kernel.
Returns:
the kernel

getPoint2D

public Point2D getPoint2D(Point2D srcPt,
                          Point2D dstPt)
Overrides:
getPoint2D in interface AbstractBufferedImageOp

getPremultiplyAlpha

public boolean getPremultiplyAlpha()
Get whether to premultiply the alpha channel.
Returns:
true to premultiply the alpha

getRenderingHints

public RenderingHints getRenderingHints()
Overrides:
getRenderingHints in interface AbstractBufferedImageOp

getUseAlpha

public boolean getUseAlpha()
Get whether to convolve the alpha channel.
Returns:
true to convolve the alpha

setEdgeAction

public void setEdgeAction(int edgeAction)
Set the action to perfomr for pixels off the image edges.
Parameters:
edgeAction - the action

setKernel

public void setKernel(Kernel kernel)
Set the convolution kernel.
Parameters:
kernel - the kernel

setPremultiplyAlpha

public void setPremultiplyAlpha(boolean premultiplyAlpha)
Set whether to premultiply the alpha channel.
Parameters:
premultiplyAlpha - true to premultiply the alpha

setUseAlpha

public void setUseAlpha(boolean useAlpha)
Set whether to convolve the alpha channel.
Parameters:
useAlpha - true to convolve the alpha

toString

public String toString()