public class DynamicWarping
extends java.lang.Object
For sequences f and g, dynamic warping finds a sequence of shifts u such that f[i1] ~ g[i1+u[i1]], subject to a bound b1 on strain, the rate at which the shifts u[i1] vary with sample index i1.
An increasing u[i1] = u[i1-1] + 1 implies that, between indices i1-1 and i1, g[i1] is a stretched version of f[i1] ~ g[i1+u[i1]]. For, in this case, values in f for indices i1 and i1-1 are one sample apart, but corresponding values in g are two samples apart, which implies stretching by 100%. Likewise, a decreasing u[i1] = u[i1-1] - 1 implies squeezing by 100%.
In practice, 100% strain (stretching or squeezing) may be extreme. Therefore, the upper bound on strain may be smaller than one. For example, if the bound b1 = 0.5, then |u[i1]-u[i1-1]| ≤ 0.5.
For 2D images f and g, dynamic warping finds a 2D array of shifts u[i2][i1] such that f[i2][i1] ~ g[i2][i1+u[i2][i1]], subject to bounds b1 and b2 on strains, the rates at which shifts u[i2][i1] vary with samples indices i1 and i2, respectively.
For 3D images f and g, dynamic warping finds a 3D array of shifts u[i3][i2][i1] in a similar way. However, finding shifts for 3D images may require an excessive amount of memory. Dynamic image warping requires a temporary array of nlag*nsample floats, where the number of lags nlag = 1+shiftMax-shiftMin and nsample is the number of image samples. For 3D images, the product nlag*nsample is likely to be too large for the temporary array to fit in random- access memory (RAM). In this case, shifts u are obtained by blending together shifts computed from overlapping subsets of the 3D image.
Estimated shifts u can be smoothed, and the extent of smoothing along each dimension is inversely proportional to the strain limit for that dimension. These extents can be scaled by specified factors for more or less smoothing. The default scale factors are zero, for no smoothing.
This class provides numerous methods, but typical applications require only several of these, usually only the methods that find and apply shifts. The many other methods are provided only for atypical applications and research.
Modifier and Type | Class and Description |
---|---|
static class |
DynamicWarping.ErrorExtrapolation
The method used to extrapolate alignment errors.
|
Constructor and Description |
---|
DynamicWarping(int shiftMin,
int shiftMax)
Constructs a dynamic warping for specified bounds on shifts.
|
Modifier and Type | Method and Description |
---|---|
float[][] |
accumulateForward(float[][] e)
Returns errors accumulated in forward direction.
|
void |
accumulateForward(float[][] e,
float[][] d)
Accumulates alignment errors in forward direction.
|
float[][][] |
accumulateForward1(float[][][] e)
Returns errors accumulated in forward direction in 1st dimension.
|
void |
accumulateForward1(float[][][] e,
float[][][] d)
Accumulates alignment errors in forward direction in 1st dimension.
|
float[][][] |
accumulateForward2(float[][][] e)
Returns errors accumulated in forward direction in 2nd dimension.
|
void |
accumulateForward2(float[][][] e,
float[][][] d)
Accumulates alignment errors in forward direction in 2nd dimension.
|
float[][] |
accumulateReverse(float[][] e)
Returns errors accumulated in reverse direction.
|
void |
accumulateReverse(float[][] e,
float[][] d)
Accumulates alignment errors in reverse direction.
|
float[][][] |
accumulateReverse1(float[][][] e)
Returns errors accumulated in reverse direction in 1st dimension.
|
void |
accumulateReverse1(float[][][] e,
float[][][] d)
Accumulates alignment errors in reverse direction in 1st dimension.
|
float[][][] |
accumulateReverse2(float[][][] e)
Returns errors accumulated in reverse direction in 2nd dimension.
|
void |
accumulateReverse2(float[][][] e,
float[][][] d)
Accumulates alignment errors in reverse direction in 2nd dimension.
|
float[][][] |
applyShifts(float[][][] u,
float[][][] g)
Returns an image warped by applying specified shifts.
|
void |
applyShifts(float[][][] u,
float[][][] g,
float[][][] h)
Computes an image warped by applying specified shifts.
|
float[][] |
applyShifts(float[][] u,
float[][] g)
Returns an image warped by applying specified shifts.
|
void |
applyShifts(float[][] u,
float[][] g,
float[][] h)
Computes an image warped by applying specified shifts.
|
float[] |
applyShifts(float[] u,
float[] g)
Returns a sequence warped by applying specified shifts.
|
void |
applyShifts(float[] u,
float[] g,
float[] h)
Computes a sequence warped by applying specified shifts.
|
float[] |
backtrackReverse(float[][] d,
float[][] e)
Returns shifts found by backtracking in reverse.
|
void |
backtrackReverse(float[][] d,
float[][] e,
float[] u)
Computes shifts by backtracking in reverse direction.
|
float[][] |
backtrackReverse1(float[][][] d,
float[][][] e)
Returns shifts found by backtracking in reverse in 1st dimension.
|
void |
backtrackReverse1(float[][][] d,
float[][][] e,
float[][] u)
Computes shifts by backtracking in reverse direction in 1st dimension.
|
float[][] |
backtrackReverse2(float[][][] d,
float[][][] e)
Returns shifts found by backtracking in reverse in 2nd dimension.
|
void |
backtrackReverse2(float[][][] d,
float[][][] e,
float[][] u)
Computes shifts by backtracking in reverse direction in 2nd dimension.
|
float[][][] |
computeErrors(float[][] f,
float[][] g)
Returns normalized alignment errors for all samples and lags.
|
float[][] |
computeErrors(float[] f,
float[] g)
Returns normalized alignment errors for all samples and lags.
|
float[][] |
computeErrors1(float[][][] f,
float[][][] g)
Returns normalized 1D alignment errors for 3D images.
|
float[][] |
computeErrors1(float[][] f,
float[][] g)
Returns normalized 1D alignment errors for 2D images.
|
float[][][] |
findShifts(float[][][] f,
float[][][] g)
Computes and returns shifts for specified images.
|
void |
findShifts(float[][][] f,
float[][][] g,
float[][][] u)
Computes shifts for specified images.
|
float[][] |
findShifts(float[][] f,
float[][] g)
Computes and returns shifts for specified images.
|
void |
findShifts(float[][] f,
float[][] g,
float[][] u)
Computes shifts for specified images.
|
float[] |
findShifts(float[] f,
float[] g)
Computes and returns shifts for specified sequences.
|
void |
findShifts(float[] f,
float[] g,
float[] u)
Computes shifts for specified sequences.
|
float[] |
findShifts1(float[][][] f,
float[][][] g)
Computes and returns 1D shifts u for specified 3D images f and g.
|
void |
findShifts1(float[][][] f,
float[][][] g,
float[] u)
Computes 1D shifts u for specified 3D images f and g.
|
float[] |
findShifts1(float[][] f,
float[][] g)
Computes and returns 1D shifts u for specified 2D images f and g.
|
void |
findShifts1(float[][] f,
float[][] g,
float[] u)
Computes 1D shifts u for specified 2D images f and g.
|
static void |
normalizeErrors(float[][] e)
Normalizes alignment errors to be in range [0,1].
|
static void |
normalizeErrors(float[][][] e)
Normalizes alignment errors to be in range [0,1].
|
void |
setErrorExponent(double e)
Sets the exponent used to compute alignment errors |f-g|^e.
|
void |
setErrorExtrapolation(DynamicWarping.ErrorExtrapolation ee)
Sets the method used to extrapolate alignment errors.
|
void |
setErrorSmoothing(int esmooth)
Sets the number of nonlinear smoothings of alignment errors.
|
void |
setShiftSmoothing(double usmooth)
Sets extent of smoothing filters used to smooth shifts.
|
void |
setShiftSmoothing(double usmooth1,
double usmooth2)
Sets extents of smoothing filters used to smooth shifts.
|
void |
setShiftSmoothing(double usmooth1,
double usmooth2,
double usmooth3)
Sets extents of smoothing filters used to smooth shifts.
|
void |
setStrainMax(double strainMax)
Sets bound on strain for all dimensions.
|
void |
setStrainMax(double strainMax1,
double strainMax2)
Sets bound on strains in 1st and 2nd dimensions.
|
void |
setStrainMax(double strainMax1,
double strainMax2,
double strainMax3)
Sets bound on strains in 1st, 2nd and 3rd dimensions.
|
void |
setWindowSizeAndOverlap(int l2,
int l3,
double f2,
double f3)
Sets the size and overlap of windows used for 3D image warping.
|
float[][] |
smoothErrors(float[][] e)
Returns smoothed (and normalized) alignment errors.
|
float[][][] |
smoothErrors(float[][][] e)
Returns smoothed (and normalized) alignment errors.
|
void |
smoothErrors(float[][][] e,
float[][][] es)
Smooths (and normalizes) alignment errors.
|
void |
smoothErrors(float[][] e,
float[][] es)
Smooths (and normalizes) alignment errors.
|
float[] |
smoothShifts(float[] u)
Returns smoothed shifts.
|
float[][] |
smoothShifts(float[][] u)
Returns smoothed shifts.
|
void |
smoothShifts(float[][] u,
float[][] us)
Smooths the specified shifts.
|
void |
smoothShifts(float[] u,
float[] us)
Smooths the specified shifts.
|
float |
sumErrors(float[][][] e,
float[][] u)
Returns the sum of errors for specified shifts, rounded to integers.
|
float |
sumErrors(float[][] e,
float[] u)
Returns the sum of errors for specified shifts, rounded to integers.
|
static float[][] |
transposeLag(float[][] e)
Returns errors in an array with lag the slowest dimension.
|
static float[][][] |
transposeLag(float[][][] e)
Returns errors in an array with lag the slowest dimension.
|
public DynamicWarping(int shiftMin, int shiftMax)
shiftMin
- lower bound on shift u.shiftMax
- upper bound on shift u.public void setStrainMax(double strainMax)
strainMax
- the bound, a value less than or equal to one.public void setStrainMax(double strainMax1, double strainMax2)
strainMax1
- bound on strain in the 1st dimension.strainMax2
- bound on strain in the 2nd dimension.public void setStrainMax(double strainMax1, double strainMax2, double strainMax3)
strainMax1
- bound on strain in the 1st dimension.strainMax2
- bound on strain in the 2nd dimension.strainMax3
- bound on strain in the 3rd dimension.public void setErrorExtrapolation(DynamicWarping.ErrorExtrapolation ee)
ee
- the error extrapolation method.public void setErrorExponent(double e)
e
- the exponent.public void setErrorSmoothing(int esmooth)
The default number of smoothings is zero, which is best for 1D sequences. For 2D and 3D images, two smoothings are recommended.
esmooth
- number of nonlinear smoothings.public void setShiftSmoothing(double usmooth)
usmooth
- extent of smoothing filter in all dimensions.public void setShiftSmoothing(double usmooth1, double usmooth2)
usmooth1
- extent of smoothing filter in 1st dimension.usmooth2
- extent of smoothing filter in 2nd dimension.public void setShiftSmoothing(double usmooth1, double usmooth2, double usmooth3)
usmooth1
- extent of smoothing filter in 1st dimension.usmooth2
- extent of smoothing filter in 2nd dimension.usmooth3
- extent of smoothing filter in 3rd dimension.public void setWindowSizeAndOverlap(int l2, int l3, double f2, double f3)
Image subsets overlap in the 2nd and 3rd dimensions by specified fractions f2 and f3, which must be less than one. Because window sizes are integers, the actual overlap be greater than (but never less than) these fractions.
Default window sizes are 50 samples; default overlap fractions are 0.5, which corresponds to 50% overlap in both dimensions.
l2
- length of window in 2nd dimension.l3
- length of window in 3rd dimension.f2
- fraction of window overlap in 2nd dimension.f3
- fraction of window overlap in 3rd dimension.public float[] findShifts(float[] f, float[] g)
f
- array for the sequence f.g
- array for the sequence g.public float[][] findShifts(float[][] f, float[][] g)
f
- array for the image f.g
- array for the image g.public float[][][] findShifts(float[][][] f, float[][][] g)
f
- array for the image f.g
- array for the image g.public float[] findShifts1(float[][] f, float[][] g)
f
- array[n2][n1] for the image f.g
- array[n2][n1] for the image g.public float[] findShifts1(float[][][] f, float[][][] g)
f
- array[n3][n2][n1] for the image f.g
- array[n3][n2][n1] for the image g.public void findShifts(float[] f, float[] g, float[] u)
f
- input array for the sequence f.g
- input array for the sequence g.u
- output array of shifts u.public void findShifts(float[][] f, float[][] g, float[][] u)
f
- input array for the image f.g
- input array for the image g.u
- output array of shifts u.public void findShifts(float[][][] f, float[][][] g, float[][][] u)
f
- input array for the image f.g
- input array for the image g.u
- output array of shifts u.public void findShifts1(float[][] f, float[][] g, float[] u)
f
- input array[n2][n1] for the image f.g
- input array[n2][n1] for the image g.u
- output array[n1] of shifts u.public void findShifts1(float[][][] f, float[][][] g, float[] u)
f
- input array[n3][n2][n1] for the image f.g
- input array[n3][n2][n1] for the image g.u
- output array[n1] of shifts u.public float[] applyShifts(float[] u, float[] g)
u
- array of shifts.g
- array for the sequence to be warped.public float[][] applyShifts(float[][] u, float[][] g)
u
- array of shifts.g
- array for the image to be warped.public float[][][] applyShifts(float[][][] u, float[][][] g)
u
- array of shifts.g
- array for the image to be warped.public void applyShifts(float[] u, float[] g, float[] h)
u
- input array of shifts.g
- input array for the sequence to be warped.h
- output array for the warped sequence.public void applyShifts(float[][] u, float[][] g, float[][] h)
u
- input array of shifts.g
- input array for the image to be warped.h
- output array for the warped image.public void applyShifts(float[][][] u, float[][][] g, float[][][] h)
u
- input array of shifts.g
- input array for the image to be warped.h
- output array for the warped image.public float[][] computeErrors(float[] f, float[] g)
f
- array[n1] for the sequence f[i1].g
- array[n1] for the sequence g[i1].public float[][][] computeErrors(float[][] f, float[][] g)
f
- array[n2][n1] for the image f[i2][i1].g
- array[n2][n1] for the image g[i2][i1].public float[][] computeErrors1(float[][] f, float[][] g)
f
- array[n2][n1] for the image f[i2][i1].g
- array[n2][n1] for the image g[i2][i1].public float[][] computeErrors1(float[][][] f, float[][][] g)
f
- array[n3][n2][n1] for the image f[i3][i2][i1].g
- array[n3][n2][n1] for the image g[i3][i2][i1].public float[][] smoothErrors(float[][] e)
e
- array[n1][nl] of alignment errors.public float[][][] smoothErrors(float[][][] e)
e
- array[n2][n1][nl] of alignment errors.public void smoothErrors(float[][] e, float[][] es)
e
- input array[n1][nl] of alignment errors.es
- output array[n1][nl] of smoothed errors.public void smoothErrors(float[][][] e, float[][][] es)
e
- input array[n2][n1][nl] of alignment errors.es
- output array[n2][n1][nl] of smoothed errors.public float[] smoothShifts(float[] u)
u
- array of shifts to be smoothed.public float[][] smoothShifts(float[][] u)
u
- array of shifts to be smoothed.public void smoothShifts(float[] u, float[] us)
u
- input array of shifts to be smoothed.us
- output array of smoothed shifts.public void smoothShifts(float[][] u, float[][] us)
u
- input array of shifts to be smoothed.us
- output array of smoothed shifts.public float[][] accumulateForward(float[][] e)
e
- array of alignment errors.public float[][] accumulateReverse(float[][] e)
e
- array of alignment errors.public float[][][] accumulateForward1(float[][][] e)
e
- array of alignment errors.public float[][][] accumulateReverse1(float[][][] e)
e
- array of alignment errors.public float[][][] accumulateForward2(float[][][] e)
e
- array of alignment errors.public float[][][] accumulateReverse2(float[][][] e)
e
- array of alignment errors.public void accumulateForward(float[][] e, float[][] d)
e
- input array of alignment errors.d
- output array of accumulated errors.public void accumulateReverse(float[][] e, float[][] d)
e
- input array of alignment errors.d
- output array of accumulated errors.public void accumulateForward1(float[][][] e, float[][][] d)
e
- input array of alignment errors.d
- output array of accumulated errors.public void accumulateReverse1(float[][][] e, float[][][] d)
e
- input array of alignment errors.d
- output array of accumulated errors.public void accumulateForward2(float[][][] e, float[][][] d)
e
- input array of alignment errors.d
- output array of accumulated errors.public void accumulateReverse2(float[][][] e, float[][][] d)
e
- input array of alignment errors.d
- output array of accumulated errors.public float[] backtrackReverse(float[][] d, float[][] e)
d
- array of accumulated errors.e
- array of alignment errors.public float[][] backtrackReverse1(float[][][] d, float[][][] e)
d
- array of accumulated errors.e
- array of alignment errors.public float[][] backtrackReverse2(float[][][] d, float[][][] e)
d
- array of accumulated errors.e
- array of alignment errors.public void backtrackReverse(float[][] d, float[][] e, float[] u)
d
- input array of accumulated errors.e
- input array of alignment errors.u
- output array of shifts.public void backtrackReverse1(float[][][] d, float[][][] e, float[][] u)
d
- input array of accumulated errors.e
- input array of alignment errors.u
- output array of shifts.public void backtrackReverse2(float[][][] d, float[][][] e, float[][] u)
d
- input array of accumulated errors.e
- input array of alignment errors.u
- output array of shifts.public static void normalizeErrors(float[][] e)
e
- input/output array of alignment errors.public static void normalizeErrors(float[][][] e)
e
- input/output array of alignment errors.public float sumErrors(float[][] e, float[] u)
e
- array[n1][nl] of errors.u
- array[n1] of shifts.public float sumErrors(float[][][] e, float[][] u)
e
- array[n2][n1][nl] of errors.u
- array[n2][n1] of shifts.public static float[][] transposeLag(float[][] e)
e
- array[n1][nl] of errors.public static float[][][] transposeLag(float[][][] e)
e
- array[n2][n1][nl] of errors.