Search in sources :

Example 11 with WlCoef_I32

use of boofcv.struct.wavelet.WlCoef_I32 in project BoofCV by lessthanoptimal.

the class TestFactoryWaveletHaar method checkProperties_I32.

@Test
public void checkProperties_I32() {
    WaveletDescription<WlCoef_I32> desc = FactoryWaveletHaar.generate(true, 32);
    WlCoef_I32 coef = desc.getForward();
    double energyScaling = UtilWavelet.computeEnergy(coef.scaling, coef.denominatorScaling);
    double energyWavelet = UtilWavelet.computeEnergy(coef.wavelet, coef.denominatorWavelet);
    assertEquals(energyWavelet, energyScaling, 1e-4);
    double sumWavelet = UtilWavelet.sumCoefficients(coef.wavelet);
    assertEquals(0, sumWavelet, 1e-4);
    checkBiorthogonal_I32(desc);
}
Also used : WlCoef_I32(boofcv.struct.wavelet.WlCoef_I32) Test(org.junit.Test)

Example 12 with WlCoef_I32

use of boofcv.struct.wavelet.WlCoef_I32 in project BoofCV by lessthanoptimal.

the class ImplWaveletTransformBorder method horizontalInverse.

public static void horizontalInverse(BorderIndex1D border, WlBorderCoef<WlCoef_I32> desc, GrayS32 input, GrayS32 output) {
    int[] trends = new int[input.width];
    int[] details = new int[input.width];
    final int height = output.height;
    final int paddedWidth = output.width + output.width % 2;
    WlCoef inner = desc.getInnerCoefficients();
    // need to convolve coefficients that influence the ones being updated
    int lowerExtra = -Math.min(inner.offsetScaling, inner.offsetWavelet);
    int upperExtra = Math.max(inner.getScalingLength() + inner.offsetScaling, inner.getWaveletLength() + inner.offsetWavelet);
    lowerExtra += lowerExtra % 2;
    upperExtra += upperExtra % 2;
    int lowerBorder = (UtilWavelet.borderInverseLower(desc, border) + lowerExtra) / 2;
    int upperBorder = (UtilWavelet.borderInverseUpper(desc, border, output.width) + upperExtra) / 2;
    boolean isLarger = input.width >= output.width;
    // where updated wavelet values are stored
    int lowerCompute = lowerBorder * 2 - lowerExtra;
    int upperCompute = upperBorder * 2 - upperExtra;
    int[] indexes = new int[lowerBorder + upperBorder];
    for (int i = 0; i < lowerBorder; i++) indexes[i] = i * 2;
    for (int i = lowerBorder; i < indexes.length; i++) indexes[i] = paddedWidth - (indexes.length - i) * 2;
    border.setLength(output.width + output.width % 2);
    WlCoef_I32 coefficients = desc.getInnerCoefficients();
    final int e = coefficients.denominatorScaling * 2;
    final int f = coefficients.denominatorWavelet * 2;
    final int ef = e * f;
    final int ef2 = ef / 2;
    for (int y = 0; y < height; y++) {
        // initialize details and trends arrays
        for (int i = 0; i < indexes.length; i++) {
            int x = indexes[i];
            details[x] = 0;
            trends[x] = 0;
            x++;
            details[x] = 0;
            trends[x] = 0;
        }
        for (int i = 0; i < indexes.length; i++) {
            int x = indexes[i];
            float a = input.get(x / 2, y);
            float d = input.get(input.width / 2 + x / 2, y);
            if (x < lowerBorder) {
                coefficients = desc.getBorderCoefficients(x);
            } else if (x >= upperBorder) {
                coefficients = desc.getBorderCoefficients(x - paddedWidth);
            } else {
                coefficients = desc.getInnerCoefficients();
            }
            final int offsetA = coefficients.offsetScaling;
            final int offsetB = coefficients.offsetWavelet;
            final int[] alpha = coefficients.scaling;
            final int[] beta = coefficients.wavelet;
            // add the trend
            for (int j = 0; j < alpha.length; j++) {
                // if an odd image don't update the outer edge
                int xx = border.getIndex(x + offsetA + j);
                if (isLarger && xx >= output.width)
                    continue;
                trends[xx] += a * alpha[j];
            }
            // add the detail signal
            for (int j = 0; j < beta.length; j++) {
                int xx = border.getIndex(x + offsetB + j);
                if (isLarger && xx >= output.width)
                    continue;
                details[xx] += d * beta[j];
            }
        }
        int indexDst = output.startIndex + y * output.stride;
        for (int x = 0; x < lowerCompute; x++) {
            output.data[indexDst + x] = UtilWavelet.round(trends[x] * f + details[x] * e, ef2, ef);
        }
        for (int x = paddedWidth - upperCompute; x < output.width; x++) {
            output.data[indexDst + x] = UtilWavelet.round(trends[x] * f + details[x] * e, ef2, ef);
        }
    }
}
Also used : WlCoef_I32(boofcv.struct.wavelet.WlCoef_I32) WlCoef(boofcv.struct.wavelet.WlCoef)

Example 13 with WlCoef_I32

use of boofcv.struct.wavelet.WlCoef_I32 in project BoofCV by lessthanoptimal.

the class ImplWaveletTransformNaive method verticalInverse.

/**
 * Performs a single level inverse wavelet transform along the vertical axis.
 *
 * @param inverseCoef Description of wavelet coefficients.
 * @param input Transformed image. Not modified.
 * @param output Reconstruction of original image. Modified
 */
public static void verticalInverse(BorderIndex1D border, WlBorderCoef<WlCoef_I32> inverseCoef, GrayI input, GrayI output) {
    UtilWavelet.checkShape(output, input);
    int[] trends = new int[output.height];
    int[] details = new int[output.height];
    boolean isLarger = input.height > output.height;
    int paddedHeight = output.height + output.height % 2;
    final int lowerBorder = inverseCoef.getLowerLength() * 2;
    final int upperBorder = output.height - inverseCoef.getUpperLength() * 2;
    border.setLength(output.height + output.height % 2);
    WlCoef_I32 coefficients = inverseCoef.getInnerCoefficients();
    final int e = coefficients.denominatorScaling * 2;
    final int f = coefficients.denominatorWavelet * 2;
    final int ef = e * f;
    final int ef2 = ef / 2;
    for (int x = 0; x < output.width; x++) {
        for (int i = 0; i < details.length; i++) {
            details[i] = 0;
            trends[i] = 0;
        }
        for (int y = 0; y < output.height; y += 2) {
            int a = input.get(x, y / 2);
            int d = input.get(x, y / 2 + input.height / 2);
            if (y < lowerBorder) {
                coefficients = inverseCoef.getBorderCoefficients(y);
            } else if (y >= upperBorder) {
                coefficients = inverseCoef.getBorderCoefficients(y - paddedHeight);
            } else {
                coefficients = inverseCoef.getInnerCoefficients();
            }
            final int offsetA = coefficients.offsetScaling;
            final int offsetB = coefficients.offsetWavelet;
            final int[] alpha = coefficients.scaling;
            final int[] beta = coefficients.wavelet;
            // add the 'average' signal
            for (int i = 0; i < alpha.length; i++) {
                // if an odd image don't update the outer edge
                int yy = border.getIndex(y + offsetA + i);
                if (isLarger && yy >= output.height)
                    continue;
                trends[yy] += a * alpha[i];
            }
            // add the detail signal
            for (int i = 0; i < beta.length; i++) {
                int yy = border.getIndex(y + offsetB + i);
                if (isLarger && yy >= output.height)
                    continue;
                details[yy] += d * beta[i];
            }
        }
        for (int y = 0; y < output.height; y++) {
            output.set(x, y, UtilWavelet.round(trends[y] * f + details[y] * e, ef2, ef));
        }
    }
}
Also used : WlCoef_I32(boofcv.struct.wavelet.WlCoef_I32)

Example 14 with WlCoef_I32

use of boofcv.struct.wavelet.WlCoef_I32 in project BoofCV by lessthanoptimal.

the class TestWaveletTransformInt method checkOtherType.

/**
 * See how well it processes an image which is not an GrayS32
 */
@Test
public void checkOtherType() {
    GrayS32 orig = new GrayS32(width, height);
    GImageMiscOps.fillUniform(orig, rand, 0, 20);
    GrayU8 orig8 = ConvertImage.convert(orig, (GrayU8) null);
    int N = 3;
    ImageDimension dimen = UtilWavelet.transformDimension(orig, N);
    GrayS32 found = new GrayS32(dimen.width, dimen.height);
    GrayS32 expected = new GrayS32(dimen.width, dimen.height);
    WaveletDescription<WlCoef_I32> desc = FactoryWaveletDaub.biorthogonal_I32(5, BorderType.REFLECT);
    GrayS32 storage = new GrayS32(dimen.width, dimen.height);
    WaveletTransformOps.transformN(desc, orig.clone(), expected, storage, N);
    WaveletTransformInt<GrayU8> alg = new WaveletTransformInt<>(desc, N, 0, 255, GrayU8.class);
    alg.transform(orig8, found);
    // see if the two techniques produced the same results
    BoofTesting.assertEquals(expected, found, 0);
    // see if it can convert it back
    GrayU8 reconstructed = new GrayU8(width, height);
    alg.invert(found, reconstructed);
    BoofTesting.assertEquals(orig8, reconstructed, 0);
    // make sure the input has not been modified
    BoofTesting.assertEquals(expected, found, 0);
}
Also used : WlCoef_I32(boofcv.struct.wavelet.WlCoef_I32) ImageDimension(boofcv.struct.image.ImageDimension) GrayU8(boofcv.struct.image.GrayU8) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Aggregations

WlCoef_I32 (boofcv.struct.wavelet.WlCoef_I32)14 Test (org.junit.Test)6 BorderType (boofcv.core.image.border.BorderType)2 GrayS32 (boofcv.struct.image.GrayS32)2 ImageDimension (boofcv.struct.image.ImageDimension)2 WlCoef (boofcv.struct.wavelet.WlCoef)2 WaveletTransform (boofcv.abst.transform.wavelet.WaveletTransform)1 BorderIndex1D (boofcv.core.image.border.BorderIndex1D)1 FactoryWaveletTransform (boofcv.factory.transform.wavelet.FactoryWaveletTransform)1 GrayU8 (boofcv.struct.image.GrayU8)1 WlCoef_F32 (boofcv.struct.wavelet.WlCoef_F32)1 DMatrixRMaj (org.ejml.data.DMatrixRMaj)1