Search in sources :

Example 1 with BorderIndex1D

use of boofcv.core.image.border.BorderIndex1D in project BoofCV by lessthanoptimal.

the class CommonFactoryWavelet method checkEncodeDecode_I32.

/**
 * See if the provided wavelets can be used to transform the image and change it back without error
 *
 * @param waveletDesc The wavelet being tested
 */
public void checkEncodeDecode_I32(WaveletDescription<WlCoef_I32> waveletDesc) {
    // test both even and odd images
    for (int makeOdd = 0; makeOdd <= 1; makeOdd++) {
        GrayS32 orig = new GrayS32(width - makeOdd, height - makeOdd);
        GrayS32 tran = new GrayS32(width, height);
        GrayS32 rev = new GrayS32(width - makeOdd, height - makeOdd);
        ImageMiscOps.fillUniform(orig, rand, -50, 50);
        BorderIndex1D border = waveletDesc.getBorder();
        ImplWaveletTransformNaive.horizontal(border, waveletDesc.forward, orig, tran);
        ImplWaveletTransformNaive.horizontalInverse(border, waveletDesc.inverse, tran, rev);
        BoofTesting.assertEquals(orig, rev, 0);
        // quick sanity check to make sure that WaveletTransformOps
        // also correctly does a transform with these wavelets
        // more of a robustness test of WaveletTransformOps than anything else
        WaveletTransformOps.transform1(waveletDesc, orig, tran, null);
        WaveletTransformOps.inverse1(waveletDesc, tran, rev, null, Integer.MIN_VALUE, Integer.MAX_VALUE);
        BoofTesting.assertEquals(orig, rev, 0);
    }
}
Also used : BorderIndex1D(boofcv.core.image.border.BorderIndex1D) GrayS32(boofcv.struct.image.GrayS32)

Example 2 with BorderIndex1D

use of boofcv.core.image.border.BorderIndex1D in project BoofCV by lessthanoptimal.

the class PermuteWaveletCompare method createDesc_I32.

private WaveletDescription<WlCoef_I32> createDesc_I32(int offset, int length, BorderType type) {
    WlCoef_I32 forward = createRandomCoef_I32(offset, length);
    BorderIndex1D border;
    WlBorderCoef<WlCoef_I32> inverse;
    if (type == BorderType.WRAP) {
        inverse = new WlBorderCoefStandard<>(forward);
        border = new BorderIndex1D_Wrap();
    } else {
        inverse = createFixedCoef_I32(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)

Example 3 with BorderIndex1D

use of boofcv.core.image.border.BorderIndex1D in project BoofCV by lessthanoptimal.

the class FactoryWaveletDaub method biorthogonal_F32.

/**
 * <p>
 * Daub J/K biorthogonal wavelets have the following properties:<br>
 * <ul>
 * <li>DO NOT conserve the signal's energy</li>
 * <li>If the signal is approximately polynomial of degree (J-1)/2-1 within the support then fluctuations are approximately zero.</li>
 * <li>The sum of the scaling numbers is 1</li>
 * <li>The sum of the wavelet numbers is 0</li>
 * </ul>
 * </p>
 *
 * @param J The wavelet's degree. K = J-2.
 * @param borderType How image borders are handled.
 * @return Description of the Daub J/K wavelet.
 */
public static WaveletDescription<WlCoef_F32> biorthogonal_F32(int J, BorderType borderType) {
    if (J != 5) {
        throw new IllegalArgumentException("Only 5 is currently supported");
    }
    WlCoef_F32 forward = new WlCoef_F32();
    forward.offsetScaling = -2;
    forward.offsetWavelet = 0;
    forward.scaling = new float[5];
    forward.wavelet = new float[3];
    forward.scaling[0] = (float) (-1.0 / 8.0);
    forward.scaling[1] = (float) (2.0 / 8.0);
    forward.scaling[2] = (float) (6.0 / 8.0);
    forward.scaling[3] = (float) (2.0 / 8.0);
    forward.scaling[4] = (float) (-1.0 / 8.0);
    forward.wavelet[0] = -1.0f / 2.0f;
    forward.wavelet[1] = 1;
    forward.wavelet[2] = -1.0f / 2.0f;
    BorderIndex1D border;
    WlBorderCoef<WlCoef_F32> inverse;
    if (borderType == BorderType.REFLECT) {
        WlCoef_F32 inner = computeInnerInverseBiorthogonal(forward);
        border = new BorderIndex1D_Reflect();
        inverse = computeBorderCoefficients(border, forward, inner);
    } else if (borderType == BorderType.WRAP) {
        WlCoef_F32 inner = computeInnerInverseBiorthogonal(forward);
        inverse = new WlBorderCoefStandard<>(inner);
        border = new BorderIndex1D_Wrap();
    } else {
        throw new IllegalArgumentException("Unsupported border type: " + borderType);
    }
    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)

Example 4 with BorderIndex1D

use of boofcv.core.image.border.BorderIndex1D in project BoofCV by lessthanoptimal.

the class FactoryWaveletDaub method biorthogonal_I32.

/**
 * Integer version of {@link #biorthogonal_F32}.
 *
 * @param J The wavelet's degree. K = J-2.
 * @param borderType How image borders are handled.
 * @return Description of the Daub J/K wavelet.
 */
public static WaveletDescription<WlCoef_I32> biorthogonal_I32(int J, BorderType borderType) {
    if (J != 5) {
        throw new IllegalArgumentException("Only 5 is currently supported");
    }
    WlCoef_I32 forward = new WlCoef_I32();
    forward.offsetScaling = -2;
    forward.offsetWavelet = 0;
    forward.scaling = new int[5];
    forward.wavelet = new int[3];
    forward.denominatorScaling = 8;
    forward.scaling[0] = -1;
    forward.scaling[1] = 2;
    forward.scaling[2] = 6;
    forward.scaling[3] = 2;
    forward.scaling[4] = -1;
    forward.denominatorWavelet = 2;
    forward.wavelet[0] = -1;
    forward.wavelet[1] = 2;
    forward.wavelet[2] = -1;
    BorderIndex1D border;
    WlBorderCoef<WlCoef_I32> inverse;
    if (borderType == BorderType.WRAP) {
        WlCoef_I32 inner = computeInnerBiorthogonalInverse(forward);
        inverse = new WlBorderCoefStandard<>(inner);
        border = new BorderIndex1D_Wrap();
    } else if (borderType == BorderType.REFLECT) {
        WlCoef_I32 inner = computeInnerBiorthogonalInverse(forward);
        inverse = convertToInt((WlBorderCoefFixed<WlCoef_F32>) biorthogonal_F32(J, borderType).getInverse(), inner);
        border = new BorderIndex1D_Reflect();
    } else {
        throw new IllegalArgumentException("Unsupported border type: " + borderType);
    }
    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)

Example 5 with BorderIndex1D

use of boofcv.core.image.border.BorderIndex1D in project BoofCV by lessthanoptimal.

the class CommonFactoryWavelet method checkEncodeDecode_F32.

/**
 * See if the provided wavelets can be used to transform the image and change it back without error
 *
 * @param waveletDesc The wavelet being tested
 */
public void checkEncodeDecode_F32(WaveletDescription<WlCoef_F32> waveletDesc) {
    // test both even and odd images
    for (int makeOdd = 0; makeOdd <= 1; makeOdd++) {
        GrayF32 orig = new GrayF32(width - makeOdd, height - makeOdd);
        GrayF32 tran = new GrayF32(width, height);
        GrayF32 rev = new GrayF32(width - makeOdd, height - makeOdd);
        ImageMiscOps.fillUniform(orig, rand, 0, 50);
        BorderIndex1D border = waveletDesc.getBorder();
        // First test again naive transform operations, which are the standard implementation
        ImplWaveletTransformNaive.horizontal(border, waveletDesc.forward, orig, tran);
        ImplWaveletTransformNaive.horizontalInverse(border, waveletDesc.inverse, tran, rev);
        BoofTesting.assertEquals(orig, rev, 1e-4f);
        ImplWaveletTransformNaive.vertical(border, waveletDesc.forward, orig, tran);
        ImplWaveletTransformNaive.verticalInverse(border, waveletDesc.inverse, tran, rev);
        BoofTesting.assertEquals(orig, rev, 1e-4f);
        // quick sanity check to make sure that WaveletTransformOps
        // also correctly does a transform with these wavelets
        // more of a robustness test of WaveletTransformOps than anything else
        WaveletTransformOps.transform1(waveletDesc, orig, tran, null);
        WaveletTransformOps.inverse1(waveletDesc, tran, rev, null, 0, 255);
        // BoofTesting.printDiff(orig,rev);
        BoofTesting.assertEquals(orig, rev, 1e-4f);
    }
}
Also used : BorderIndex1D(boofcv.core.image.border.BorderIndex1D) GrayF32(boofcv.struct.image.GrayF32)

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