Class AlgorithmWaveletThreshold
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.filters.AlgorithmWaveletThreshold
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmWaveletThreshold extends AlgorithmBase
In hard thresholding a wavelet coefficient whose magnitude is below the product of threshold and the maximum wavelet magnitude is zeroed, and a wavelet coefficient whose magnitude is greater than or equal to the product is left unchanged. In soft thresholding a wavelet coefficient whose magnitude is below the product of threshold and the maximum wavelet magnitude is zeroed, and a wavelet coefficient whose magnitude is greater than or equal to the product has its magnitude decreased by the product. Generally, soft thresholding is a better choice. The signal reconstructed with the coefficients left after hard thresholding may have undesirable artifacts including sidelobes. Then, an inverse wavelet transform is performed. The image is stripped down to its original size. The data is clamped so as not to exceed the bounds of the data type of the image into which it is imported. This is a simple method of reducing white noise.
The forward and inverse Daubechies wavelet transform routines are taken from Numerical Recipes in C The Art of Scientific Computing, 2nd edition, by William H. Press, Saul A. Teukolsky, William T. Vetterling, and Brian P. Flannery, Cambridge University Press, 1997, Chapter 13.10, pp. 591 - 606. The wavelet routines daub4, pwt, wt1, wtn, and pwtset in Numerical Recipes in C are in the public domain. See {@link http://www.nr.com/public-domain.html} for more information.
The wavelet transform is mathematically defined only within a signal; image applications need to solve the boundary problem. 4 different techniques exist:
- Mirror image replication
- Zero padding
- Linear extrapolation
- Circular convolution
In this module zero padding is used. As stated in the Medx 3.4 User's Guide in Chapter 17 on Advanced Image Processing Techniques: "The mirror condition can only be used with symmetric wavelet basis." "Daubechies wavelet bases are non-symmetrical orthogonal wavelets with compact support and are good for data suppression. Only the periodic boundary condition should be used when using the Daubechies wavelet basis." In Empirical Evaluation of Boundary Policies for Wavelet-based Image Coding by Claudia Schremmer zero padding, circular convolution, and mirror image padding are compared. She concludes that mirror padding works best with regard to quality, zero padding performs worst with regard to quality, and circular convolution is midway between the 2. The matlab wavelet toolbox literature says that "the disadvantage of zero padding is that discontinuities are artificially created at the border." Mirror padding "has the disadvantage of artificially creating discontinuities of the first derivative at the border, but this method works well in general for images." Extrapolation "works well in general for smooth signals." The wavelet toolbox uses mirror padding as its default mode. How much padding is required? Claudia Schremmer states: "With padding, the coefficients of the signal on either side of the border are padded with filter_length - 2 coefficients. Consequently, each signal coefficient enters into filter_length/2 calculations of convolution, and the transform is reversible."
The image is expanded so that all dimensions are powers of 2 and there is zero padding going past each original boundary by the coefficient number - 2. The image is transformed into wavelet coefficients.
-
-
Field Summary
Fields Modifier and Type Field Description private float[]
aArray
DOCUMENT ME!private float
aCutoff
DOCUMENT ME!private float[]
aExp
DOCUMENT ME!private float[]
aLog
DOCUMENT ME!private float
aMax
DOCUMENT ME!private int
arrayLength
DOCUMENT ME!private int
belowThreshold
DOCUMENT ME!static double
C0
coefficents for DAUB4 wavelet filter.static double
C1
DOCUMENT ME!static double[]
c12
DOCUMENT ME!static double
C2
DOCUMENT ME!static double[]
c20
DOCUMENT ME!static double
C3
DOCUMENT ME!static double[]
c4
coefficients for the PWT filter.private double[]
cc
DOCUMENT ME!private int
cm2
DOCUMENT ME!private int
cNum
DOCUMENT ME!private double[]
cr
DOCUMENT ME!private int
dataType
DOCUMENT ME!static int
DAUB4
underlying wavelet filter For 4 coefficients the routine daub4 is considerably faster than pwt.private boolean
doWaveletImage
DOCUMENT ME!private int[]
extents
DOCUMENT ME!private int
filterType
DOCUMENT ME!static int
FORWARD
DOCUMENT ME!private boolean
foundSize
DOCUMENT ME!static int
HARD
thresholding estimator.static int
INVERSE
FORWARD and INVERSE are 2 possible transformDir valuesprivate int
ioff
DOCUMENT ME!private int
joff
DOCUMENT ME!private int
minSize
DOCUMENT ME!private int
nDims
DOCUMENT ME!private int
newArrayLength
DOCUMENT ME!private int[]
newExtents
DOCUMENT ME!private int
newXDim
DOCUMENT ME!private int
newXY
DOCUMENT ME!private int
newYDim
DOCUMENT ME!private int
newZDim
DOCUMENT ME!static int
NONNEGATIVE_GARROTE
private int
offsetX
DOCUMENT ME!private int
offsetY
DOCUMENT ME!private int
offsetZ
DOCUMENT ME!static int
PWT
DOCUMENT ME!static int
SCAD
static int
SOFT
DOCUMENT ME!private float
threshold
DOCUMENT ME!private int
thresholdType
DOCUMENT ME!private int
transformDir
DOCUMENT ME!private ModelImage
waveletImage
DOCUMENT ME!private int
xDim
DOCUMENT ME!private int
xy
DOCUMENT ME!private int
yDim
DOCUMENT ME!private int
zDim
DOCUMENT ME!-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmWaveletThreshold(ModelImage srcImg, int filterType, int cNum, int thresholdType, float threshold, boolean doWaveletImage)
Creates a new AlgorithmWaveletThreshold object.AlgorithmWaveletThreshold(ModelImage destImg, ModelImage srcImg, int filterType, int cNum, int thresholdType, float threshold, boolean doWaveletImage)
Creates a new AlgorithmWaveletThreshold object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
daub4(float[] a, int n)
DOCUMENT ME!void
finalize()
Prepare this class for destruction.ModelImage
getWaveletImage()
Accessor that returns the image.private void
pwt(float[] a, int n)
DOCUMENT ME!void
runAlgorithm()
Starts the program.private void
wt1(float[] a)
DOCUMENT ME!private void
wtn(float[] a)
DOCUMENT ME!-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
INVERSE
public static final int INVERSE
FORWARD and INVERSE are 2 possible transformDir values- See Also:
- Constant Field Values
-
FORWARD
public static final int FORWARD
DOCUMENT ME!- See Also:
- Constant Field Values
-
DAUB4
public static final int DAUB4
underlying wavelet filter For 4 coefficients the routine daub4 is considerably faster than pwt. DAUB4 implements a Daubechies 4-coefficient wavelet filter. PWT implements Daubechies filters with 4, 12, and 20 coefficients. DAUB4 and PWT use different default centerings. In spite of the faster speed of DAUB4, the dialog is designed only to call PWT so that the user only sees changes due to the number of coefficients and is not confused by changes in centering. Reference on NONNEGATIVE_GARROTE and SCAD thresholding: "Wavelet Estimators in Nonparametric Regression: A Comparative Simulation Study" by Anestis Antoniadis, Jeremie Bigot, and Theofanis Sapatinas, Journal of Statistical Software, Vol. 6, Issue 6, pp. 1-83, 2001.- See Also:
- Constant Field Values
-
PWT
public static final int PWT
DOCUMENT ME!- See Also:
- Constant Field Values
-
C0
public static final double C0
coefficents for DAUB4 wavelet filter.- See Also:
- Constant Field Values
-
C1
public static final double C1
DOCUMENT ME!- See Also:
- Constant Field Values
-
C2
public static final double C2
DOCUMENT ME!- See Also:
- Constant Field Values
-
C3
public static final double C3
DOCUMENT ME!- See Also:
- Constant Field Values
-
c4
public static final double[] c4
coefficients for the PWT filter.
-
c12
public static final double[] c12
DOCUMENT ME!
-
c20
public static final double[] c20
DOCUMENT ME!
-
HARD
public static final int HARD
thresholding estimator.- See Also:
- Constant Field Values
-
SOFT
public static final int SOFT
DOCUMENT ME!- See Also:
- Constant Field Values
-
NONNEGATIVE_GARROTE
public static final int NONNEGATIVE_GARROTE
- See Also:
- Constant Field Values
-
SCAD
public static final int SCAD
- See Also:
- Constant Field Values
-
aArray
private float[] aArray
DOCUMENT ME!
-
aCutoff
private float aCutoff
DOCUMENT ME!
-
aExp
private float[] aExp
DOCUMENT ME!
-
aLog
private float[] aLog
DOCUMENT ME!
-
aMax
private float aMax
DOCUMENT ME!
-
arrayLength
private int arrayLength
DOCUMENT ME!
-
belowThreshold
private int belowThreshold
DOCUMENT ME!
-
cc
private double[] cc
DOCUMENT ME!
-
cm2
private final int cm2
DOCUMENT ME!
-
cNum
private final int cNum
DOCUMENT ME!
-
cr
private double[] cr
DOCUMENT ME!
-
dataType
private int dataType
DOCUMENT ME!
-
doWaveletImage
private final boolean doWaveletImage
DOCUMENT ME!
-
extents
private int[] extents
DOCUMENT ME!
-
filterType
private final int filterType
DOCUMENT ME!
-
foundSize
private boolean foundSize
DOCUMENT ME!
-
ioff
private int ioff
DOCUMENT ME!
-
joff
private int joff
DOCUMENT ME!
-
minSize
private int minSize
DOCUMENT ME!
-
nDims
private int nDims
DOCUMENT ME!
-
newArrayLength
private int newArrayLength
DOCUMENT ME!
-
newExtents
private int[] newExtents
DOCUMENT ME!
-
newXDim
private int newXDim
DOCUMENT ME!
-
newYDim
private int newYDim
DOCUMENT ME!
-
newZDim
private int newZDim
DOCUMENT ME!
-
offsetX
private int offsetX
DOCUMENT ME!
-
offsetY
private int offsetY
DOCUMENT ME!
-
offsetZ
private int offsetZ
DOCUMENT ME!
-
threshold
private final float threshold
DOCUMENT ME!
-
thresholdType
private final int thresholdType
DOCUMENT ME!
-
transformDir
private int transformDir
DOCUMENT ME!
-
waveletImage
private ModelImage waveletImage
DOCUMENT ME!
-
xDim
private int xDim
DOCUMENT ME!
-
yDim
private int yDim
DOCUMENT ME!
-
zDim
private int zDim
DOCUMENT ME!
-
xy
private int xy
DOCUMENT ME!
-
newXY
private int newXY
DOCUMENT ME!
-
-
Constructor Detail
-
AlgorithmWaveletThreshold
public AlgorithmWaveletThreshold(ModelImage srcImg, int filterType, int cNum, int thresholdType, float threshold, boolean doWaveletImage)
Creates a new AlgorithmWaveletThreshold object.- Parameters:
srcImg
- source image modelfilterType
- wavelet filtercNum
- number of coefficients in the pwt filterthresholdType
- HARD or SOFT thresholdingthreshold
- fraction of maximum magnitude below which coefficients are zeroeddoWaveletImage
- display wavelet transform image in log magnitude if trueuserInterface
- DOCUMENT ME!
-
AlgorithmWaveletThreshold
public AlgorithmWaveletThreshold(ModelImage destImg, ModelImage srcImg, int filterType, int cNum, int thresholdType, float threshold, boolean doWaveletImage)
Creates a new AlgorithmWaveletThreshold object.- Parameters:
destImg
- image model where result image is to be storedsrcImg
- source image modelfilterType
- wavelet filtercNum
- number of coefficients in the pwt filterthresholdType
- HARD or SOFT thresholdingthreshold
- fraction of maximum magnitude below which coefficients are zeroeddoWaveletImage
- display log maagnitude wavelet transform image if trueuserInterface
- DOCUMENT ME!
-
-
Method Detail
-
finalize
public void finalize()
Prepare this class for destruction.- Overrides:
finalize
in classAlgorithmBase
-
getWaveletImage
public ModelImage getWaveletImage()
Accessor that returns the image.- Returns:
- the wavelet image
-
runAlgorithm
public void runAlgorithm()
Starts the program.- Specified by:
runAlgorithm
in classAlgorithmBase
-
daub4
private void daub4(float[] a, int n)
DOCUMENT ME!- Parameters:
a
- data vector to which Daubechies 4-coefficient wavelet filter or its transpose (for transformDir == INVERSE) is appliedn
- DOCUMENT ME!
-
pwt
private void pwt(float[] a, int n)
DOCUMENT ME!- Parameters:
a
- data to which wavelet filter (for transformDir == FORWARD) or to which transpose wavelet filter is applied (for transformDir == INVERSE)n
- Used hierarchically by routines wt1 and wtn
-
wt1
private void wt1(float[] a)
DOCUMENT ME!- Parameters:
a
- data replaced by its wavelet transform for transformDir == FORWARD or by its inverse wavelet transform for transformDir == INVERSE One dimensional discrete wavelet transform. Note that the length of a must be an integer power of 2
-
wtn
private void wtn(float[] a)
DOCUMENT ME!- Parameters:
a
- data replaced by its wavelet transform for transformDir == FORWARD or by its inverse wavelet transform for transformDir == INVERSE n-dimensional discrete wavelet transform. Note that the length of each dimension of a must be an integer power of 2
-
-