Search in sources :

Example 6 with BorderIndex1D

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));
}
Also used : WlCoef_F32(boofcv.struct.wavelet.WlCoef_F32) BorderIndex1D(boofcv.core.image.border.BorderIndex1D) DMatrixRMaj(org.ejml.data.DMatrixRMaj)

Example 7 with BorderIndex1D

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));
}
Also used : BorderIndex1D(boofcv.core.image.border.BorderIndex1D) WlCoef_I32(boofcv.struct.wavelet.WlCoef_I32) DMatrixRMaj(org.ejml.data.DMatrixRMaj)

Example 8 with BorderIndex1D

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);
}
Also used : BorderIndex1D_Wrap(boofcv.core.image.border.BorderIndex1D_Wrap) BorderIndex1D(boofcv.core.image.border.BorderIndex1D) BorderIndex1D_Reflect(boofcv.core.image.border.BorderIndex1D_Reflect)

Aggregations

BorderIndex1D (boofcv.core.image.border.BorderIndex1D)8 BorderIndex1D_Reflect (boofcv.core.image.border.BorderIndex1D_Reflect)4 BorderIndex1D_Wrap (boofcv.core.image.border.BorderIndex1D_Wrap)4 DMatrixRMaj (org.ejml.data.DMatrixRMaj)2 GrayF32 (boofcv.struct.image.GrayF32)1 GrayS32 (boofcv.struct.image.GrayS32)1 WlCoef_F32 (boofcv.struct.wavelet.WlCoef_F32)1 WlCoef_I32 (boofcv.struct.wavelet.WlCoef_I32)1