Package com.xinapse.filter
Class FixedWeightsKernelFilter
java.lang.Object
com.xinapse.filter.AbstractKernelFilter
com.xinapse.filter.FixedWeightsKernelFilter
- All Implemented Interfaces:
SpatialFilter
- Direct Known Subclasses:
GaussianBlurFilter,LaplacianFilter,SobelFilter
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
FieldsModifier and TypeFieldDescriptionprotected final float[][][]The 3-D array of weights in the kernel.Fields inherited from class com.xinapse.filter.AbstractKernelFilter
bcFields inherited from interface com.xinapse.filter.SpatialFilter
N_DOTS -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor produces an identityFixedWeightsKernelFilterwith kernel size 1x1x1 that has no effect when applied.FixedWeightsKernelFilter(float[][][] wts, boolean normalise, BoundaryCondition boundaryCondition) Constructs a 3-dimensional kernel-based filter with the given filter weights.FixedWeightsKernelFilter(float[][] wts, boolean normalise, BoundaryCondition boundaryCondition) Constructs a 2-dimensional kernel-based filter with the given filter weights. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(FixedWeightsKernelFilter filter) Adds the weights from a FixedWeightsKernelFilter to the weights of this one.static FixedWeightsKernelFilteradd(FixedWeightsKernelFilter filter1, FixedWeightsKernelFilter filter2) Adds the weights from two FixedWeightsKernelFilters to create a new FixedWeightsKernelFilter.convolve(FixedWeightsKernelFilter filter) Convolves this FixedWeightsKernelFilter with another FixedWeightsKernelFilter to create a new FixedWeightsKernelFilter.copyResize(int[] newSize, boolean normalise) Copies a FixedWeightsKernelFilter, possibly resizing it, creating a new FixedWeightsKernelFilter.voidfilterInPlaceBinary(BitSet pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose) Filter an array of binary pixel values "in place".voidfilterInPlaceByte(byte[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose) Filter an array of signed byte pixel values "in place".voidfilterInPlaceDouble(double[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose) Filter an array of double-precision pixel values "in place".voidfilterInPlaceFloat(float[] pixels, int fromCol, int toCol, int fromRow, int toRow, int fromSlice, int toSlice, int nCols, int nRows, int nSlices) Filter a cuboid portion of an array of floating-point pixel values "in place".voidfilterInPlaceFloat(float[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose) Filter an array of floating-point pixel values "in place".voidfilterInPlaceInt(int[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose) Filter an array of signed int pixel values "in place".voidfilterInPlaceLong(long[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose) Filter an array of long pixel values "in place".voidfilterInPlaceShort(short[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose) Filter an array of signed short pixel values "in place".voidfilterInPlaceUByte(byte[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose) Filter an array of unsigned byte pixel values "in place".voidfilterInPlaceUInt(int[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose) Filter an array of unsigned int pixel values "in place".voidfilterInPlaceUShort(short[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose) Filter an array of unsigned short pixel values "in place".float[]Returns the kernel weights as a flat array.intReturns the number of columns in the filter kernel.intReturns the number of rows in the filter kernel.intReturns the number of slices in the filter kernel.voidscale(float scaleFactor) Scale all kernel weights by the given scaling factor.floatReturns the sum of all the weights for thisFixedWeightsKernelFilter.toImage(Class<? extends WritableImage> imageClass) Create an image of the kernel weights.toString()Returns aStringdescribing thisFixedWeightsKernelFilter.Methods inherited from class com.xinapse.filter.AbstractKernelFilter
filter, filter, filter, filterInPlace, filterInPlace, filterInPlace, filterInPlace, filterInPlace, filterInPlace, filterInPlaceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.xinapse.filter.SpatialFilter
filter, filter, filterInPlace, filterInPlace, filterInPlace, filterInPlace
-
Field Details
-
weights
protected final float[][][] weightsThe 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 Details
-
FixedWeightsKernelFilter
protected FixedWeightsKernelFilter()Default constructor produces an identityFixedWeightsKernelFilterwith kernel size 1x1x1 that has no effect when applied. -
FixedWeightsKernelFilter
public FixedWeightsKernelFilter(float[][] wts, boolean normalise, BoundaryCondition boundaryCondition) throws 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- iftruethe weights will be normalised when constructing the kernel. If the weights cannot be normalised, then this argument has no effect.boundaryCondition- theBoundaryConditionto apply when this filter is applied to an array of pixels.- Throws:
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, BoundaryCondition boundaryCondition) throws 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- iftruethe weights will be normalised when constructing the kernel. If the weights cannot be normalised, then this argument has no effect.boundaryCondition- theBoundaryConditionto apply when this filter is applied to an array of pixels.- Throws:
IllegalArgumentException- if the dimensions of the kernel weights array aren't odd-numbered in each of the three dimensions.
-
-
Method Details
-
getNKernelCols
public int getNKernelCols()Description copied from class:AbstractKernelFilterReturns the number of columns in the filter kernel.- Specified by:
getNKernelColsin classAbstractKernelFilter- Returns:
- the number of columns in the filter kernel.
-
getNKernelRows
public int getNKernelRows()Description copied from class:AbstractKernelFilterReturns the number of rows in the filter kernel.- Specified by:
getNKernelRowsin classAbstractKernelFilter- Returns:
- the number of rows in the filter kernel.
-
getNKernelSlices
public int getNKernelSlices()Description copied from class:AbstractKernelFilterReturns the number of slices in the filter kernel.- Specified by:
getNKernelSlicesin classAbstractKernelFilter- Returns:
- the number of slices in the filter kernel.
-
getFlatKernelWeights
public float[] getFlatKernelWeights()Returns the kernel weights as a flat array.- Returns:
- the kernel weights as a flat array in slice/row/col major order.
-
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 thisFixedWeightsKernelFilter.- Returns:
- the sum of all the weights.
-
add
Adds the weights from a FixedWeightsKernelFilter to the weights of this one.- Parameters:
filter- the FixedWeightsKernelFilter from which to add the weights.- Throws:
IllegalArgumentException- if the two filters do not have the same kernel dimensions.
-
add
public static FixedWeightsKernelFilter add(FixedWeightsKernelFilter filter1, FixedWeightsKernelFilter filter2) throws 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:
IllegalArgumentException- if the two filters do not have the same kernel dimensions.
-
copyResize
public FixedWeightsKernelFilter copyResize(int[] newSize, boolean normalise) throws 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:
IllegalArgumentException
-
convolve
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 convolving 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:AbstractKernelFilterFilter 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:
filterInPlaceBinaryin classAbstractKernelFilter- Parameters:
pixels- the array of image pixel values.nCols- the number of image columnsnRows- 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:AbstractKernelFilterFilter 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:
filterInPlaceBytein classAbstractKernelFilter- Parameters:
pixels- the array of image pixel values.nCols- the number of image columnsnRows- 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:AbstractKernelFilterFilter 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:
filterInPlaceUBytein classAbstractKernelFilter- Parameters:
pixels- the array of image pixel values.nCols- the number of image columnsnRows- 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:AbstractKernelFilterFilter 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:
filterInPlaceShortin classAbstractKernelFilter- Parameters:
pixels- the array of image pixel values.nCols- the number of image columnsnRows- 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:AbstractKernelFilterFilter 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:
filterInPlaceUShortin classAbstractKernelFilter- Parameters:
pixels- the array of image pixel values.nCols- the number of image columnsnRows- 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:AbstractKernelFilterFilter 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:
filterInPlaceIntin classAbstractKernelFilter- Parameters:
pixels- the array of image pixel values.nCols- the number of image columnsnRows- 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:AbstractKernelFilterFilter 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:
filterInPlaceUIntin classAbstractKernelFilter- Parameters:
pixels- the array of image pixel values.nCols- the number of image columnsnRows- 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:AbstractKernelFilterFilter 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:
filterInPlaceLongin classAbstractKernelFilter- Parameters:
pixels- the array of image pixel values.nCols- the number of image columnsnRows- 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:AbstractKernelFilterFilter an array of floating-point pixel values "in place".- Specified by:
filterInPlaceFloatin classAbstractKernelFilter- Parameters:
pixels- the array of image pixel values.nCols- the number of image columnsnRows- 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 fromCol, int toCol, int fromRow, int toRow, int fromSlice, int toSlice, int nCols, int nRows, int nSlices) Filter a cuboid portion of an array of floating-point pixel values "in place".- Parameters:
pixels- the array of image pixel values.fromCol- the first image column to start filtering.toCol- the last image column (exclusive) to stop filtering.fromRow- the first image row to start filtering.toRow- the last image row to stop filtering.fromSlice- the first image row to start filtering.toSlice- the last image slice to start filtering.nCols- the number of image columns.nRows- the number of image rows.nSlices- the number of image slices.
-
filterInPlaceDouble
public void filterInPlaceDouble(double[] pixels, int nCols, int nRows, int nSlices, MonitorWorker worker, boolean verbose) throws CancelledException Description copied from class:AbstractKernelFilterFilter 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:
filterInPlaceDoublein classAbstractKernelFilter- Parameters:
pixels- the array of image pixel values.nCols- the number of image columnsnRows- 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.
-
toImage
public WritableImage toImage(Class<? extends WritableImage> imageClass) throws InvalidImageException, IOException Create an image of the kernel weights.- Parameters:
imageClass- the Class of image to create.- Returns:
- an image of the kernel weights.
- Throws:
InvalidImageException- if the image cannot be created.IOException- if the image cannot be created because of an I/O error.
-
toString
Returns aStringdescribing thisFixedWeightsKernelFilter.- Overrides:
toStringin classObject- Returns:
- a
Stringshowing the weights of thisFixedWeightsKernelFilter.
-