com.xinapse.filter
Class FixedWeightsKernelFilter

java.lang.Object
  extended by com.xinapse.filter.AbstractKernelFilter
      extended by com.xinapse.filter.FixedWeightsKernelFilter
All Implemented Interfaces:
SpatialFilter
Direct Known Subclasses:
GaussianBlurFilter, LaplacianFilter, SobelFilter

public class FixedWeightsKernelFilter
extends AbstractKernelFilter
implements SpatialFilter

A class for performing filtering of images based on a moving kernel of pixels with fixed weights within the kernel.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.xinapse.filter.SpatialFilter
SpatialFilter.SpecifierPanel
 
Field Summary
protected  float[][][] weights
          The 3-D array of weights in the kernel.
 
Fields inherited from interface com.xinapse.filter.SpatialFilter
N_DOTS
 
Constructor Summary
protected FixedWeightsKernelFilter()
          Default constructor produces an identity FixedWeightsKernelFilter with kernel size 1x1x1 that has no effect when applied.
  FixedWeightsKernelFilter(float[][][] wts, boolean normalise, FilterBoundaryCondition boundaryCondition)
          Constructs a 3-dimensional kernel-based filter with the given filter weights.
  FixedWeightsKernelFilter(float[][] wts, boolean normalise, FilterBoundaryCondition boundaryCondition)
          Constructs a 2-dimensional kernel-based filter with the given filter weights.
 
Method Summary
 void add(FixedWeightsKernelFilter filter)
          Adds the weights from a FixedWeightsKernelFilter to the weights of this one.
static FixedWeightsKernelFilter add(FixedWeightsKernelFilter filter1, FixedWeightsKernelFilter filter2)
          Adds the weights from two FixedWeightsKernelFilters to create a new FixedWeightsKernelFilter.
 FixedWeightsKernelFilter convolve(FixedWeightsKernelFilter filter)
          Convolves this FixedWeightsKernelFilter with another FixedWeightsKernelFilter to create a new FixedWeightsKernelFilter.
 FixedWeightsKernelFilter copyResize(int[] newSize, boolean normalise)
          Copies a FixedWeightsKernelFilter, possibly resizing it, creating a new FixedWeightsKernelFilter.
 void filterInPlaceBinary(BitSet pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose)
          Filter an array of binary pixel values "in place".
 void filterInPlaceByte(byte[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose)
          Filter an array of signed byte pixel values "in place".
 void filterInPlaceDouble(double[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose)
          Filter an array of double-precision pixel values "in place".
 void filterInPlaceFloat(float[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose)
          Filter an array of floating-point pixel values "in place".
 void filterInPlaceInt(int[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose)
          Filter an array of signed int pixel values "in place".
 void filterInPlaceLong(long[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose)
          Filter an array of long pixel values "in place".
 void filterInPlaceShort(short[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose)
          Filter an array of signed short pixel values "in place".
 void filterInPlaceUByte(byte[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose)
          Filter an array of unsigned byte pixel values "in place".
 void filterInPlaceUInt(int[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose)
          Filter an array of unsigned int pixel values "in place".
 void filterInPlaceUShort(short[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose)
          Filter an array of unsigned short pixel values "in place".
 int getNKernelCols()
          Returns the number of columns in the filter kernel.
 int getNKernelRows()
          Returns the number of rows in the filter kernel.
 int getNKernelSlices()
          Returns the number of slices in the filter kernel.
 void scale(float scaleFactor)
          Scale all kernel weights by the given scaling factor.
 float sumWeights()
          Returns the sum of all the weights for this FixedWeightsKernelFilter.
 java.lang.String toString()
          Returns a java.lang.String describing this FixedWeightsKernelFilter.
 
Methods inherited from class com.xinapse.filter.AbstractKernelFilter
filter, filter, filter, filterInPlace, filterInPlace, filterInPlace, filterInPlace, filterInPlace, filterInPlace, filterInPlace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.xinapse.filter.SpatialFilter
filter, filter, filterInPlace, filterInPlace, filterInPlace, filterInPlace
 

Field Detail

weights

protected final float[][][] weights
The 3-D array of weights in the kernel. The first index is the slice index, the second is the row index, and the third is the column index.

Constructor Detail

FixedWeightsKernelFilter

protected FixedWeightsKernelFilter()
Default constructor produces an identity FixedWeightsKernelFilter with kernel size 1x1x1 that has no effect when applied.


FixedWeightsKernelFilter

public FixedWeightsKernelFilter(float[][] wts,
                                boolean normalise,
                                FilterBoundaryCondition boundaryCondition)
                         throws java.lang.IllegalArgumentException
Constructs a 2-dimensional kernel-based filter with the given filter weights. The filter may optionally be normalised so that it is intensity-preserving (i.e., the sum of weights will be forced to add up to 1).

Parameters:
wts - a two-dimensional array of weights. This array must have an odd number of elements in each of the two dimensions. The centre of the weights kernel will be centred on the pixel being filtered. The first index of the array refers to the the row direction, and the second to the column direction.
normalise - if true the weights will be normalised when constructing the kernel. If the weights cannot be normalised, then this argument has no effect.
boundaryCondition - the FilterBoundaryCondition to apply when this filter is applied to an array of pixels.
Throws:
java.lang.IllegalArgumentException - if the dimensions of the kernel weights array aren't odd-numbered in each of the two dimensions.

FixedWeightsKernelFilter

public FixedWeightsKernelFilter(float[][][] wts,
                                boolean normalise,
                                FilterBoundaryCondition boundaryCondition)
                         throws java.lang.IllegalArgumentException
Constructs a 3-dimensional kernel-based filter with the given filter weights. The filter may optionally be normalised so that it is intensity-preserving (i.e., the sum of weights will be forced to add up to 1).

Parameters:
wts - a three-dimensional array of weights. This array must have an odd number of elements in each of the three dimensions. The centre of the weights kernel will be centred on the pixel being filtered. The first index of the array refers to the slice direction, the second index to the row direction, and the third to the column direction.
normalise - if true the weights will be normalised when constructing the kernel. If the weights cannot be normalised, then this argument has no effect.
boundaryCondition - the FilterBoundaryCondition to apply when this filter is applied to an array of pixels.
Throws:
java.lang.IllegalArgumentException - if the dimensions of the kernel weights array aren't odd-numbered in each of the three dimensions.
Method Detail

getNKernelCols

public int getNKernelCols()
Description copied from class: AbstractKernelFilter
Returns the number of columns in the filter kernel.

Specified by:
getNKernelCols in class AbstractKernelFilter
Returns:
the number of columns in the filter kernel.

getNKernelRows

public int getNKernelRows()
Description copied from class: AbstractKernelFilter
Returns the number of rows in the filter kernel.

Specified by:
getNKernelRows in class AbstractKernelFilter
Returns:
the number of rows in the filter kernel.

getNKernelSlices

public int getNKernelSlices()
Description copied from class: AbstractKernelFilter
Returns the number of slices in the filter kernel.

Specified by:
getNKernelSlices in class AbstractKernelFilter
Returns:
the number of slices in the filter kernel.

scale

public void scale(float scaleFactor)
Scale all kernel weights by the given scaling factor.

Parameters:
scaleFactor - the scaling factor for the weights.

sumWeights

public float sumWeights()
Returns the sum of all the weights for this FixedWeightsKernelFilter.

Returns:
the sum of all the weights.

add

public void add(FixedWeightsKernelFilter filter)
         throws java.lang.IllegalArgumentException
Adds the weights from a FixedWeightsKernelFilter to the weights of this one.

Parameters:
filter - the FixedWeightsKernelFilter from which to add the weights.
Throws:
java.lang.IllegalArgumentException - if the two filters do not have the same kernel dimensions.

add

public static FixedWeightsKernelFilter add(FixedWeightsKernelFilter filter1,
                                           FixedWeightsKernelFilter filter2)
                                    throws java.lang.IllegalArgumentException
Adds the weights from two FixedWeightsKernelFilters to create a new FixedWeightsKernelFilter.

Parameters:
filter1 - the first FixedWeightsKernelFilter from which to add the weights.
filter2 - the second FixedWeightsKernelFilter from which to add the weights.
Returns:
a new FixedWeightsKernelFilter with weights which calculated by summing the weights from the two supplied filters.
Throws:
java.lang.IllegalArgumentException - if the two filters do not have the same kernel dimensions.

copyResize

public FixedWeightsKernelFilter copyResize(int[] newSize,
                                           boolean normalise)
                                    throws java.lang.IllegalArgumentException
Copies a FixedWeightsKernelFilter, possibly resizing it, creating a new FixedWeightsKernelFilter. If the requested size is larger than the current size in any direction, the new filter is padded with zeros. If the requested size is smaller than the current size in any direction, the new filter is cropped.

Parameters:
newSize - an array of length at least 3 that specifies the new kernel size.
normalise - whether the resulting FixedWeightsKernelFilter should be normalised (the sum of all weights should be unity).
Returns:
a copy of the supplied FixedWeightsKernelFilter, but resized.
Throws:
java.lang.IllegalArgumentException

convolve

public FixedWeightsKernelFilter convolve(FixedWeightsKernelFilter filter)
Convolves this FixedWeightsKernelFilter with another FixedWeightsKernelFilter to create a new FixedWeightsKernelFilter.

Parameters:
filter - the FixedWeightsKernelFilter with which this FixedWeightsKernelFilter will be convolved.
Returns:
a new FixedWeightsKernelFilter that results from comvolving this filter with the supplied filter.

filterInPlaceBinary

public void filterInPlaceBinary(BitSet pixels,
                                int nCols,
                                int nRows,
                                int nSlices,
                                MonitorWorker worker,
                                boolean verbose)
                         throws CancelledException
Description copied from class: AbstractKernelFilter
Filter an array of binary pixel values "in place". This default implementation should be overridden by AbstractKernelFilters that are interested in a more efficient implementation for PixelDataType.BINARY images.

Overrides:
filterInPlaceBinary in class AbstractKernelFilter
Parameters:
pixels - the array of image pixel values.
nCols - the number of image columns
nRows - the number of image rows.
nSlices - the number of image slices.
worker - the MonitorWorker that may be used to cancel the filter operation.
verbose - whether verbose reporting to System.out is turned on.
Throws:
CancelledException - if the filter operation is cancelled by the user or programmatically.

filterInPlaceByte

public void filterInPlaceByte(byte[] pixels,
                              int nCols,
                              int nRows,
                              int nSlices,
                              MonitorWorker worker,
                              boolean verbose)
                       throws CancelledException
Description copied from class: AbstractKernelFilter
Filter an array of signed byte pixel values "in place". This default implementation should be overridden by SpatialFilters that are interested in a more efficient implementation for PixelDataType.BYTE images.

Overrides:
filterInPlaceByte in class AbstractKernelFilter
Parameters:
pixels - the array of image pixel values.
nCols - the number of image columns
nRows - the number of image rows.
nSlices - the number of image slices.
worker - the MonitorWorker that may be used to cancel the filter operation.
verbose - whether verbose reporting to System.out is turned on.
Throws:
CancelledException - if the filter operation is cancelled by the user or programmatically.

filterInPlaceUByte

public void filterInPlaceUByte(byte[] pixels,
                               int nCols,
                               int nRows,
                               int nSlices,
                               MonitorWorker worker,
                               boolean verbose)
                        throws CancelledException
Description copied from class: AbstractKernelFilter
Filter an array of unsigned byte pixel values "in place". This default implementation should be overridden by SpatialFilters that are interested in a more efficient implementation for PixelDataType.UBYTE images.

Overrides:
filterInPlaceUByte in class AbstractKernelFilter
Parameters:
pixels - the array of image pixel values.
nCols - the number of image columns
nRows - the number of image rows.
nSlices - the number of image slices.
worker - the MonitorWorker that may be used to cancel the filter operation.
verbose - whether verbose reporting to System.out is turned on.
Throws:
CancelledException - if the filter operation is cancelled by the user or programmatically.

filterInPlaceShort

public void filterInPlaceShort(short[] pixels,
                               int nCols,
                               int nRows,
                               int nSlices,
                               MonitorWorker worker,
                               boolean verbose)
                        throws CancelledException
Description copied from class: AbstractKernelFilter
Filter an array of signed short pixel values "in place". This default implementation should be overridden by SpatialFilters that are interested in a more efficient implementation for PixelDataType.SHORT images.

Overrides:
filterInPlaceShort in class AbstractKernelFilter
Parameters:
pixels - the array of image pixel values.
nCols - the number of image columns
nRows - the number of image rows.
nSlices - the number of image slices.
worker - the MonitorWorker that may be used to cancel the filter operation.
verbose - whether verbose reporting to System.out is turned on.
Throws:
CancelledException - if the filter operation is cancelled by the user or programmatically.

filterInPlaceUShort

public void filterInPlaceUShort(short[] pixels,
                                int nCols,
                                int nRows,
                                int nSlices,
                                MonitorWorker worker,
                                boolean verbose)
                         throws CancelledException
Description copied from class: AbstractKernelFilter
Filter an array of unsigned short pixel values "in place". This default implementation should be overridden by SpatialFilters that are interested in a more efficient implementation for PixelDataType.USHORT images.

Overrides:
filterInPlaceUShort in class AbstractKernelFilter
Parameters:
pixels - the array of image pixel values.
nCols - the number of image columns
nRows - the number of image rows.
nSlices - the number of image slices.
worker - the MonitorWorker that may be used to cancel the filter operation.
verbose - whether verbose reporting to System.out is turned on.
Throws:
CancelledException - if the filter operation is cancelled by the user or programmatically.

filterInPlaceInt

public void filterInPlaceInt(int[] pixels,
                             int nCols,
                             int nRows,
                             int nSlices,
                             MonitorWorker worker,
                             boolean verbose)
                      throws CancelledException
Description copied from class: AbstractKernelFilter
Filter an array of signed int pixel values "in place". This default implementation should be overridden by SpatialFilters that are interested in a more efficient implementation for PixelDataType.INT images.

Overrides:
filterInPlaceInt in class AbstractKernelFilter
Parameters:
pixels - the array of image pixel values.
nCols - the number of image columns
nRows - the number of image rows.
nSlices - the number of image slices.
worker - the MonitorWorker that may be used to cancel the filter operation.
verbose - whether verbose reporting to System.out is turned on.
Throws:
CancelledException - if the filter operation is cancelled by the user or programmatically.

filterInPlaceUInt

public void filterInPlaceUInt(int[] pixels,
                              int nCols,
                              int nRows,
                              int nSlices,
                              MonitorWorker worker,
                              boolean verbose)
                       throws CancelledException
Description copied from class: AbstractKernelFilter
Filter an array of unsigned int pixel values "in place". This default implementation should be overridden by SpatialFilters that are interested in a more efficient implementation for PixelDataType.UINT images.

Overrides:
filterInPlaceUInt in class AbstractKernelFilter
Parameters:
pixels - the array of image pixel values.
nCols - the number of image columns
nRows - the number of image rows.
nSlices - the number of image slices.
worker - the MonitorWorker that may be used to cancel the filter operation.
verbose - whether verbose reporting to System.out is turned on.
Throws:
CancelledException - if the filter operation is cancelled by the user or programmatically.

filterInPlaceLong

public void filterInPlaceLong(long[] pixels,
                              int nCols,
                              int nRows,
                              int nSlices,
                              MonitorWorker worker,
                              boolean verbose)
                       throws CancelledException
Description copied from class: AbstractKernelFilter
Filter an array of long pixel values "in place". This default implementation should be overridden by SpatialFilters that are interested in a more efficient implementation for PixelDataType.LONG images.

Overrides:
filterInPlaceLong in class AbstractKernelFilter
Parameters:
pixels - the array of image pixel values.
nCols - the number of image columns
nRows - the number of image rows.
nSlices - the number of image slices.
worker - the MonitorWorker that may be used to cancel the filter operation.
verbose - whether verbose reporting to System.out is turned on.
Throws:
CancelledException - if the filter operation is cancelled by the user or programmatically.

filterInPlaceFloat

public void filterInPlaceFloat(float[] pixels,
                               int nCols,
                               int nRows,
                               int nSlices,
                               MonitorWorker worker,
                               boolean verbose)
                        throws CancelledException
Description copied from class: AbstractKernelFilter
Filter an array of floating-point pixel values "in place".

Specified by:
filterInPlaceFloat in class AbstractKernelFilter
Parameters:
pixels - the array of image pixel values.
nCols - the number of image columns
nRows - the number of image rows.
nSlices - the number of image slices.
worker - the MonitorWorker that may be used to cancel the filter operation.
verbose - whether verbose reporting to System.out is turned on.
Throws:
CancelledException - if the filter operation is cancelled by the user or programmatically.

filterInPlaceDouble

public void filterInPlaceDouble(double[] pixels,
                                int nCols,
                                int nRows,
                                int nSlices,
                                MonitorWorker worker,
                                boolean verbose)
                         throws CancelledException
Description copied from class: AbstractKernelFilter
Filter an array of double-precision pixel values "in place". This default implementation should be overridden by SpatialFilters that are interested in a more efficient implementation for PixelDataType.DOUBLE images.

Overrides:
filterInPlaceDouble in class AbstractKernelFilter
Parameters:
pixels - the array of image pixel values.
nCols - the number of image columns
nRows - the number of image rows.
nSlices - the number of image slices.
worker - the MonitorWorker that may be used to cancel the filter operation.
verbose - whether verbose reporting to System.out is turned on.
Throws:
CancelledException - if the filter operation is cancelled by the user or programmatically.

toString

public java.lang.String toString()
Returns a java.lang.String describing this FixedWeightsKernelFilter.

Overrides:
toString in class java.lang.Object
Returns:
a java.lang.String showing the weights of this FixedWeightsKernelFilter.


Copyright 2006-2011 Xinapse Systems Limited. All Rights Reserved.