use of boofcv.core.image.border.BorderIndex1D in project BoofCV by lessthanoptimal.
the class CommonFactoryWavelet method checkBiorthogonal_F32.
/**
* Computes the dot product of two wavelets separated by different offsets. If
* the offset is zero and they have an orthogonal/biorothogonal relationship then
* the dot product should be one. Otherwise it will be zero.
*/
public static void checkBiorthogonal_F32(WaveletDescription<WlCoef_F32> desc) {
WlCoef_F32 forward = desc.getForward();
BorderIndex1D border = desc.getBorder();
int N = Math.max(forward.getScalingLength(), forward.getWaveletLength());
N += N % 2;
N *= 2;
border.setLength(N);
DMatrixRMaj A = new DMatrixRMaj(N, N);
DMatrixRMaj B = new DMatrixRMaj(N, N);
// using the provided wrapping rule to construct a matrix with the coefficients
for (int i = 0; i < N; i += 2) {
for (int j = 0; j < forward.scaling.length; j++) {
int index = border.getIndex(i + j + forward.offsetScaling);
A.add(i, index, forward.scaling[j]);
}
for (int j = 0; j < forward.wavelet.length; j++) {
int index = border.getIndex(i + j + forward.offsetWavelet);
A.add(i + 1, index, forward.wavelet[j]);
}
}
// the inverse coefficients should create a matrix that is the inverse of the forward coefficients
final int lowerBorder = desc.getInverse().getLowerLength() * 2;
final int upperBorder = N - desc.getInverse().getUpperLength() * 2;
for (int i = 0; i < N; i += 2) {
WlCoef_F32 inverse;
if (i < lowerBorder) {
inverse = desc.getInverse().getBorderCoefficients(i);
} else if (i >= upperBorder) {
inverse = desc.getInverse().getBorderCoefficients(i - N);
} else {
inverse = desc.getInverse().getInnerCoefficients();
}
for (int j = 0; j < inverse.scaling.length; j++) {
int index = border.getIndex(i + j + inverse.offsetScaling);
B.add(index, i, inverse.scaling[j]);
}
for (int j = 0; j < inverse.wavelet.length; j++) {
int index = border.getIndex(i + j + inverse.offsetWavelet);
B.add(index, i + 1, inverse.wavelet[j]);
}
}
DMatrixRMaj C = new DMatrixRMaj(N, N);
CommonOps_DDRM.mult(A, B, C);
// A.print();
// B.print();
// C.print();
assertTrue(MatrixFeatures_DDRM.isIdentity(C, 1e-4));
}
use of boofcv.core.image.border.BorderIndex1D in project BoofCV by lessthanoptimal.
the class CommonFactoryWavelet method checkBiorthogonal_I32.
public static void checkBiorthogonal_I32(WaveletDescription<WlCoef_I32> desc) {
WlCoef_I32 forward = desc.getForward();
BorderIndex1D border = desc.getBorder();
int N = Math.max(forward.getScalingLength(), forward.getWaveletLength());
N += N % 2;
N *= 2;
border.setLength(N);
DMatrixRMaj A = new DMatrixRMaj(N, N);
DMatrixRMaj B = new DMatrixRMaj(N, N);
// using the wrapping rule construct a matrix with the coefficients
for (int i = 0; i < N; i += 2) {
for (int j = 0; j < forward.scaling.length; j++) {
int index = border.getIndex(i + j + forward.offsetScaling);
A.add(i, index, (double) forward.scaling[j] / forward.denominatorScaling);
}
for (int j = 0; j < forward.wavelet.length; j++) {
int index = border.getIndex(i + j + forward.offsetWavelet);
A.add(i + 1, index, (double) forward.wavelet[j] / forward.denominatorWavelet);
}
}
// the inverse coefficients should be a matrix which is the inverse of the forward coefficients
final int lowerBorder = desc.getInverse().getLowerLength() * 2;
final int upperBorder = N - desc.getInverse().getUpperLength() * 2;
for (int i = 0; i < N; i += 2) {
WlCoef_I32 inverse;
if (i < lowerBorder) {
inverse = desc.getInverse().getBorderCoefficients(i);
} else if (i >= upperBorder) {
inverse = desc.getInverse().getBorderCoefficients(i - N);
} else {
inverse = desc.getInverse().getInnerCoefficients();
}
for (int j = 0; j < inverse.scaling.length; j++) {
int index = border.getIndex(i + j + inverse.offsetScaling);
B.add(index, i, (double) inverse.scaling[j] / inverse.denominatorScaling);
}
for (int j = 0; j < inverse.wavelet.length; j++) {
int index = border.getIndex(i + j + inverse.offsetWavelet);
B.add(index, i + 1, (double) inverse.wavelet[j] / inverse.denominatorWavelet);
}
}
DMatrixRMaj C = new DMatrixRMaj(N, N);
CommonOps_DDRM.mult(A, B, C);
assertTrue(MatrixFeatures_DDRM.isIdentity(C, 1e-4));
}
use of boofcv.core.image.border.BorderIndex1D in project BoofCV by lessthanoptimal.
the class PermuteWaveletCompare method createDesc_F32.
private WaveletDescription<WlCoef_F32> createDesc_F32(int offset, int length, BorderType type) {
WlCoef_F32 forward = createRandomCoef_F32(offset, length);
WlBorderCoef<WlCoef_F32> inverse;
BorderIndex1D border;
if (type == BorderType.WRAP) {
inverse = new WlBorderCoefStandard<>(forward);
border = new BorderIndex1D_Wrap();
} else {
inverse = createFixedCoef_F32(forward);
border = new BorderIndex1D_Reflect();
}
return new WaveletDescription<>(border, forward, inverse);
}
Aggregations