Package com.jhlabs.image
Class ConvolveFilter
java.lang.Object
com.jhlabs.image.AbstractBufferedImageOp
com.jhlabs.image.ConvolveFilter
- All Implemented Interfaces:
BufferedImageOp,Cloneable
- Direct Known Subclasses:
AverageFilter,BlurFilter,BumpFilter,GaussianFilter,SharpenFilter
A filter which applies a convolution kernel to an image.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether to convolve alpha.static intClamp pixels off the edge to the nearest edge.protected KernelThe convolution kernel.protected booleanWhether to promultiply the alpha before convolving.static intWrap pixels off the edge to the opposite edge.static intTreat pixels off the edge as zero. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a filter with a null 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.ConvolveFilter(Kernel kernel) Construct a filter with the given 3x3 kernel. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidconvolve(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) Convolve a block of pixels.static voidConvolve a block of pixels.static voidconvolveH(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) Convolve with a kernel consisting of one row.static voidconvolveHV(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) Convolve with a 2D kernel.static voidconvolveV(Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) Convolve with a kernel consisting of one column.createCompatibleDestImage(BufferedImage src, ColorModel dstCM) filter(BufferedImage src, BufferedImage dst) getBounds2D(BufferedImage src) intGet the action to perfomr for pixels off the image edges.Get the convolution kernel.getPoint2D(Point2D srcPt, Point2D dstPt) booleanGet whether to premultiply the alpha channel.booleanGet whether to convolve the alpha channel.voidsetEdgeAction(int edgeAction) Set the action to perfomr for pixels off the image edges.voidSet the convolution kernel.voidsetPremultiplyAlpha(boolean premultiplyAlpha) Set whether to premultiply the alpha channel.voidsetUseAlpha(boolean useAlpha) Set whether to convolve the alpha channel.toString()Methods inherited from class com.jhlabs.image.AbstractBufferedImageOp
clone, getRGB, setRGB
-
Field Details
-
ZERO_EDGES
public static int ZERO_EDGESTreat pixels off the edge as zero. -
CLAMP_EDGES
public static int CLAMP_EDGESClamp pixels off the edge to the nearest edge. -
WRAP_EDGES
public static int WRAP_EDGESWrap pixels off the edge to the opposite edge. -
kernel
The convolution kernel. -
alpha
protected boolean alphaWhether to convolve alpha. -
premultiplyAlpha
protected boolean premultiplyAlphaWhether 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(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 kernelcols- the number of columns in the kernelmatrix- an array of rows*cols floats containing the kernel
-
ConvolveFilter
Construct a filter with the given 3x3 kernel.- Parameters:
kernel- the convolution kernel
-
-
Method Details
-
setKernel
Set the convolution kernel.- Parameters:
kernel- the kernel- See Also:
-
getKernel
Get the convolution kernel.- Returns:
- the kernel
- See Also:
-
setEdgeAction
public void setEdgeAction(int edgeAction) Set the action to perfomr for pixels off the image edges.- Parameters:
edgeAction- the action- See Also:
-
getEdgeAction
public int getEdgeAction()Get the action to perfomr for pixels off the image edges.- Returns:
- the action
- See Also:
-
setUseAlpha
public void setUseAlpha(boolean useAlpha) Set whether to convolve the alpha channel.- Parameters:
useAlpha- true to convolve the alpha- See Also:
-
getUseAlpha
public boolean getUseAlpha()Get whether to convolve the alpha channel.- Returns:
- true to convolve the alpha
- See Also:
-
setPremultiplyAlpha
public void setPremultiplyAlpha(boolean premultiplyAlpha) Set whether to premultiply the alpha channel.- Parameters:
premultiplyAlpha- true to premultiply the alpha- See Also:
-
getPremultiplyAlpha
public boolean getPremultiplyAlpha()Get whether to premultiply the alpha channel.- Returns:
- true to premultiply the alpha
- See Also:
-
filter
-
createCompatibleDestImage
- Specified by:
createCompatibleDestImagein interfaceBufferedImageOp- Overrides:
createCompatibleDestImagein classAbstractBufferedImageOp
-
getBounds2D
- Specified by:
getBounds2Din interfaceBufferedImageOp- Overrides:
getBounds2Din classAbstractBufferedImageOp
-
getPoint2D
- Specified by:
getPoint2Din interfaceBufferedImageOp- Overrides:
getPoint2Din classAbstractBufferedImageOp
-
getRenderingHints
- Specified by:
getRenderingHintsin interfaceBufferedImageOp- Overrides:
getRenderingHintsin classAbstractBufferedImageOp
-
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 kernelinPixels- the input pixelsoutPixels- the output pixelswidth- the widthheight- the heightedgeAction- what to do at the edges
-
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 kernelinPixels- the input pixelsoutPixels- the output pixelswidth- the widthheight- the heightalpha- include alpha channeledgeAction- 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 kernelinPixels- the input pixelsoutPixels- the output pixelswidth- the widthheight- the heightalpha- include alpha channeledgeAction- 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 kernelinPixels- the input pixelsoutPixels- the output pixelswidth- the widthheight- the heightalpha- include alpha channeledgeAction- 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 kernelinPixels- the input pixelsoutPixels- the output pixelswidth- the widthheight- the heightalpha- include alpha channeledgeAction- what to do at the edges
-
toString
-