Package net.sourceforge.jiu.filters
Class ConvolutionKernelFilter
- java.lang.Object
-
- net.sourceforge.jiu.ops.Operation
-
- net.sourceforge.jiu.ops.ImageToImageOperation
-
- net.sourceforge.jiu.filters.ConvolutionKernelFilter
-
public class ConvolutionKernelFilter extends ImageToImageOperation
Applies a convolution kernel filter to an image.Supported image types
Only image types that store intensity samples are supported. Right now, this only includesGrayIntegerImage
andRGBIntegerImage
.Usage example
Standard approach (set up everything yourself):ConvolutionKernelFilter filter = new ConvolutionKernelFilter(); filter.setKernel(ConvolutionKernelFilter.TYPE_SHARPEN); filter.setInputImage(image); filter.process(); PixelImage sharpenedImage = filter.getOutputImage();
Use static convenience method on imageimg
:PixelImage filteredImage = ConvolutionKernelFilter.filter(img, ConvolutionKernelFilter.TYPE_BLUR);
Credits
The implementation of the filter was created by members of the Java newsgroup de.comp.lang.java and adapted to the JIU framework by Marco Schmidt. As it was done in a contest style where people improved other people's work, and even more people suggested ideas, tested results and discussed the contest it is (1) hard to tell who won the contest and (2) only fair to list all persons involved.The resulting implementation is significantly faster than the reference implementation. The contest was started by the posting [JPEC#3] Vorschläge to de.comp.lang.java by Marco Schmidt (2001-02-18) and was ended by the posting [JPEC#3] Ergebnisse (2001-03-07). A Usenet archive like Google Groups should be able to provide the postings.
- Author:
- Bernd Eckenfels, Carl Rosenberger, Dietmar Münzenberger, Karsten Schulz, Marco Kaiser, Marco Schmidt, Peter Luschny, Peter Schneider, Ramin Sadre, Roland Dieterich, Thilo Schwidurski
-
-
Field Summary
Fields Modifier and Type Field Description private static int[]
BLUR_DATA
private static int[]
EDGE_DETECTION_DATA
private static int[]
EMBOSS_DATA
private static int[]
HORIZONTAL_PREWITT_DATA
private static int[]
HORIZONTAL_SOBEL_DATA
private int
kernelBias
private int[]
kernelData
private int
kernelDiv
private int
kernelHeight
private int
kernelWidth
private static int[]
LITHOGRAPH_DATA
private static ConvolutionKernelData[]
PREDEFINED_KERNELS
private static int[]
PSYCHEDELIC_DISTILLATION_DATA
private static int[]
SHARPEN_DATA
static int
TYPE_BLUR
static int
TYPE_EDGE_DETECTION
static int
TYPE_EMBOSS
static int
TYPE_HORIZONTAL_PREWITT
static int
TYPE_HORIZONTAL_SOBEL
static int
TYPE_LITHOGRAPH
static int
TYPE_PSYCHEDELIC_DISTILLATION
static int
TYPE_SHARPEN
static int
TYPE_VERTICAL_PREWITT
static int
TYPE_VERTICAL_SOBEL
private static int[]
VERTICAL_PREWITT_DATA
private static int[]
VERTICAL_SOBEL_DATA
-
Constructor Summary
Constructors Constructor Description ConvolutionKernelFilter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
copyRow(IntegerImage srcImage, int srcChannelIndex, int rowIndex, int[] dest, int destOffset, int numBorderColumns)
Copies row data from input image to buffer and replicates samples at the left and right border.static PixelImage
filter(PixelImage input, int kernelType)
Filters argument image with argument kernel type and returns output image.static PixelImage
filter(PixelImage input, ConvolutionKernelData data)
void
process()
This method does the actual work of the operation.private void
process(int channelIndex, IntegerImage in, IntegerImage out)
Applies the kernel to one of the channels of an image.private void
process(IntegerImage in, IntegerImage out)
void
setKernel(int type)
Sets one of the predefined kernel types to be used for filtering.void
setKernel(int[] data, int width, int height, int div, int bias)
Sets properties of the kernel to be used in this operation.void
setKernel(ConvolutionKernelData ckd)
Sets kernel data to be used for filtering.-
Methods inherited from class net.sourceforge.jiu.ops.ImageToImageOperation
canInputAndOutputBeEqual, ensureImagesHaveSameResolution, ensureInputImageIsAvailable, ensureOutputImageResolution, getInputImage, getOutputImage, setCanInputAndOutputBeEqual, setInputImage, setOutputImage
-
Methods inherited from class net.sourceforge.jiu.ops.Operation
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress
-
-
-
-
Field Detail
-
TYPE_BLUR
public static final int TYPE_BLUR
- See Also:
- Constant Field Values
-
TYPE_SHARPEN
public static final int TYPE_SHARPEN
- See Also:
- Constant Field Values
-
TYPE_EDGE_DETECTION
public static final int TYPE_EDGE_DETECTION
- See Also:
- Constant Field Values
-
TYPE_EMBOSS
public static final int TYPE_EMBOSS
- See Also:
- Constant Field Values
-
TYPE_PSYCHEDELIC_DISTILLATION
public static final int TYPE_PSYCHEDELIC_DISTILLATION
- See Also:
- Constant Field Values
-
TYPE_LITHOGRAPH
public static final int TYPE_LITHOGRAPH
- See Also:
- Constant Field Values
-
TYPE_HORIZONTAL_SOBEL
public static final int TYPE_HORIZONTAL_SOBEL
- See Also:
- Constant Field Values
-
TYPE_VERTICAL_SOBEL
public static final int TYPE_VERTICAL_SOBEL
- See Also:
- Constant Field Values
-
TYPE_HORIZONTAL_PREWITT
public static final int TYPE_HORIZONTAL_PREWITT
- See Also:
- Constant Field Values
-
TYPE_VERTICAL_PREWITT
public static final int TYPE_VERTICAL_PREWITT
- See Also:
- Constant Field Values
-
BLUR_DATA
private static final int[] BLUR_DATA
-
SHARPEN_DATA
private static final int[] SHARPEN_DATA
-
EDGE_DETECTION_DATA
private static final int[] EDGE_DETECTION_DATA
-
EMBOSS_DATA
private static final int[] EMBOSS_DATA
-
PSYCHEDELIC_DISTILLATION_DATA
private static final int[] PSYCHEDELIC_DISTILLATION_DATA
-
LITHOGRAPH_DATA
private static final int[] LITHOGRAPH_DATA
-
HORIZONTAL_SOBEL_DATA
private static final int[] HORIZONTAL_SOBEL_DATA
-
VERTICAL_SOBEL_DATA
private static final int[] VERTICAL_SOBEL_DATA
-
HORIZONTAL_PREWITT_DATA
private static final int[] HORIZONTAL_PREWITT_DATA
-
VERTICAL_PREWITT_DATA
private static final int[] VERTICAL_PREWITT_DATA
-
PREDEFINED_KERNELS
private static ConvolutionKernelData[] PREDEFINED_KERNELS
-
kernelBias
private int kernelBias
-
kernelData
private int[] kernelData
-
kernelDiv
private int kernelDiv
-
kernelHeight
private int kernelHeight
-
kernelWidth
private int kernelWidth
-
-
Method Detail
-
copyRow
private void copyRow(IntegerImage srcImage, int srcChannelIndex, int rowIndex, int[] dest, int destOffset, int numBorderColumns)
Copies row data from input image to buffer and replicates samples at the left and right border.
-
filter
public static PixelImage filter(PixelImage input, int kernelType)
Filters argument image with argument kernel type and returns output image. Static convenience method to do filtering with one line of code:PixelImage blurredImage = ConvolutionKernelFilter.filter(in, ConvolutionKernelFilter.TYPE_BLUR);
-
filter
public static PixelImage filter(PixelImage input, ConvolutionKernelData data)
-
process
private void process(int channelIndex, IntegerImage in, IntegerImage out)
Applies the kernel to one of the channels of an image.- Parameters:
channelIndex
- index of the channel to be filtered, must be from 0 to ByteChannelImage.getNumChannels() - 1
-
process
private void process(IntegerImage in, IntegerImage out)
-
process
public void process() throws MissingParameterException, WrongParameterException
Description copied from class:Operation
This method does the actual work of the operation. It must be called after all parameters have been given to the operation object.- Overrides:
process
in classOperation
- Throws:
MissingParameterException
- if any mandatory parameter was not given to the operationWrongParameterException
- if at least one of the input parameters was not initialized appropriately (values out of the valid interval, etc.)
-
setKernel
public void setKernel(int[] data, int width, int height, int div, int bias)
Sets properties of the kernel to be used in this operation.- Parameters:
data
- the kernel coefficients; this one-dimensional array stores them in order top-to-bottom, left-to-right; the length of this array must be at least width times heightwidth
- the width of the kernel; must not be evenheight
- the height of the kernel; must not be evendiv
- the result is divided by this value after the addition of value (so this value must not be zero)bias
- this value is added to the result before the division
-
setKernel
public void setKernel(ConvolutionKernelData ckd)
Sets kernel data to be used for filtering.- Parameters:
ckd
- all information necessary for filtering
-
setKernel
public void setKernel(int type)
Sets one of the predefined kernel types to be used for filtering.- Parameters:
type
- one of the TYPE_xyz constants of this class- Throws:
IllegalArgumentException
- if the argument is not a valid TYPE_xyz constant
-
-