📄 subbandan.java
字号:
*
* <P>It uses the initChilds() method to initialize the childs.
*
* @param hfilter The horizontal wavelet filter used to decompose
* this subband. It has to be a AnWTFilter object.
*
* @param vfilter The vertical wavelet filter used to decompose this
* subband. It has to be a AnWTFilter object.
*
* @return A reference to the LL leaf (subb_LL).
*
* @see Subband#initChilds
*
*
* */
protected Subband split(WaveletFilter hfilter, WaveletFilter vfilter) {
// Test that this is a node
if (isNode) {
throw new IllegalArgumentException();
}
// Modify this element into a node and set the filters
isNode = true;
this.hFilter = (AnWTFilter) hfilter;
this.vFilter = (AnWTFilter) vfilter;
// Create childs
subb_LL = new SubbandAn();
subb_LH = new SubbandAn();
subb_HL = new SubbandAn();
subb_HH = new SubbandAn();
// Assign parent
subb_LL.parent = this;
subb_HL.parent = this;
subb_LH.parent = this;
subb_HH.parent = this;
// Initialize childs
initChilds();
// Return reference to LL subband
return subb_LL;
}
/**
* Calculates the basis waveform of the first leaf for which the
* L2-norm has not been calculated yet. This method searches
* recursively for the first leaf for which the value has not been
* calculated yet, and then calculates the L2-norm on the return
* path.
*
* <P>The wfs argument should be a size 2 array of float arrays
* (i.e. 2D array) and it must be of length 2 (or more). When
* returning, wfs[0] will contain the line waveform, and wfs[1]
* will contain the column waveform.
*
* <P>This method can not be called on an element that ahs a
* non-negative value in l2Norm, since that means that we are
* done.
*
* @param wfs An size 2 array where the line and column waveforms
* will be returned.
*
*
* */
private void calcBasisWaveForms(float wfs[][]) {
if (l2Norm < 0) {
// We are not finished with this element yet
if (isNode) {
// We are on a node => search on childs
if (subb_LL.l2Norm < 0f) {
subb_LL.calcBasisWaveForms(wfs);
wfs[0] =
hFilter.getLPSynWaveForm(wfs[0],null);
wfs[1] =
vFilter.getLPSynWaveForm(wfs[1],null);
}
else if (subb_HL.l2Norm < 0f) {
subb_HL.calcBasisWaveForms(wfs);
wfs[0] =
hFilter.getHPSynWaveForm(wfs[0],null);
wfs[1] =
vFilter.getLPSynWaveForm(wfs[1],null);
}
else if (subb_LH.l2Norm < 0f) {
subb_LH.calcBasisWaveForms(wfs);
wfs[0] =
hFilter.getLPSynWaveForm(wfs[0],null);
wfs[1] =
vFilter.getHPSynWaveForm(wfs[1],null);
}
else if (subb_HH.l2Norm < 0f) {
subb_HH.calcBasisWaveForms(wfs);
wfs[0] =
hFilter.getHPSynWaveForm(wfs[0],null);
wfs[1] =
vFilter.getHPSynWaveForm(wfs[1],null);
}
else {
// There is an error! If all childs have
// non-negative l2norm, then this node should have
// non-negative l2norm
throw new Error("You have found a bug in JJ2000!");
}
}
else {
// This is a leaf, just use diracs (null is
// equivalent to dirac)
wfs[0] = new float[1];
wfs[0][0] = 1.0f;
wfs[1] = new float[1];
wfs[1][0] = 1.0f;
}
}
else {
// This is an error! The calcBasisWaveForms() method is
// never called on an element with non-negative l2norm
throw new Error("You have found a bug in JJ2000!");
}
}
/**
* Assigns the given L2-norm to the first leaf that does not have
* an L2-norm value yet (i.e. l2norm is negative). The search is
* done recursively and in the same order as that of the
* calcBasisWaveForms() method, so that this method is used to
* assigne the l2norm of the previously computed waveforms.
*
* <P>This method can not be called on an element that ahs a
* non-negative value in l2Norm, since that means that we are
* done.
*
* @param l2n The L2-norm to assign.
*
*
* */
private void assignL2Norm(float l2n) {
if (l2Norm < 0) {
// We are not finished with this element yet
if (isNode) {
// We are on a node => search on childs
if (subb_LL.l2Norm < 0f) {
subb_LL.assignL2Norm(l2n);
}
else if (subb_HL.l2Norm < 0f) {
subb_HL.assignL2Norm(l2n);
}
else if (subb_LH.l2Norm < 0f) {
subb_LH.assignL2Norm(l2n);
}
else if (subb_HH.l2Norm < 0f) {
subb_HH.assignL2Norm(l2n);
// If child now is done, we are done
if (subb_HH.l2Norm >= 0f) {
l2Norm = 0f; // We are on a node, any non-neg value OK
}
}
else {
// There is an error! If all childs have
// non-negative l2norm, then this node should have
// non-negative l2norm
throw new Error("You have found a bug in JJ2000!");
}
}
else {
// This is a leaf, assign the L2-norm
l2Norm = l2n;
}
}
else {
// This is an error! The assignL2Norm() method is
// never called on an element with non-negative l2norm
throw new Error("You have found a bug in JJ2000!");
}
}
/**
* Calculates the L2-norm of the sythesis waveforms of every leaf
* in the tree. This method should only be called on the root
* element.
*
*
* */
private void calcL2Norms() {
int i;
float wfs[][] = new float[2][];
double acc;
float l2n;
// While we are not done on the root element, compute basis
// functions and assign L2-norm
while (l2Norm < 0f) {
calcBasisWaveForms(wfs);
// Compute line L2-norm, which is the product of the line
// and column L2-norms
acc = 0.0;
for (i=wfs[0].length-1; i>=0; i--) {
acc += wfs[0][i]*wfs[0][i];
}
l2n = (float) Math.sqrt(acc);
// Compute column L2-norm
acc = 0.0;
for (i=wfs[1].length-1; i>=0; i--) {
acc += wfs[1][i]*wfs[1][i];
}
l2n *= (float) Math.sqrt(acc);
// Release waveforms
wfs[0] = null;
wfs[1] = null;
// Assign the value
assignL2Norm(l2n);
}
}
/**
* This function returns the horizontal wavelet filter relevant to this
* subband
*
* @return The horizontal wavelet filter
*
*
*/
public WaveletFilter getHorWFilter(){
return hFilter;
}
/**
* This function returns the vertical wavelet filter relevant to this
* subband
*
* @return The vertical wavelet filter
*
*
*/
public WaveletFilter getVerWFilter(){
return hFilter;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -