Search in sources :

Example 1 with WlCoef_I32

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

the class TestWaveletTransformInt method compareToWaveletTransformOps.

@Test
public void compareToWaveletTransformOps() {
    GrayS32 orig = new GrayS32(width, height);
    GImageMiscOps.fillUniform(orig, rand, 0, 20);
    GrayS32 origCopy = orig.clone();
    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<GrayS32> alg = new WaveletTransformInt<>(desc, N, 0, 255, GrayS32.class);
    alg.transform(orig, found);
    // make sure the original input was not modified like it is in WaveletTransformOps
    BoofTesting.assertEquals(origCopy, orig, 0);
    // see if the two techniques produced the same results
    BoofTesting.assertEquals(expected, found, 0);
    // test inverse transform
    GrayS32 reconstructed = new GrayS32(width, height);
    alg.invert(found, reconstructed);
    BoofTesting.assertEquals(orig, 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) GrayS32(boofcv.struct.image.GrayS32) Test(org.junit.Test)

Example 2 with WlCoef_I32

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

the class TestFactoryWaveletDaub method transform_biorthogonal_I32.

@Test
public void transform_biorthogonal_I32() {
    for (BorderType type : borderTypes) {
        for (int i = 5; i <= 5; i += 2) {
            WaveletDescription<WlCoef_I32> desc = FactoryWaveletDaub.biorthogonal_I32(i, type);
            checkEncodeDecode_I32(desc);
        }
    }
}
Also used : WlCoef_I32(boofcv.struct.wavelet.WlCoef_I32) BorderType(boofcv.core.image.border.BorderType) Test(org.junit.Test)

Example 3 with WlCoef_I32

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

the class FactoryImageDenoise method createDefaultShrinkTransform.

/**
 * Default wavelet transform used for denoising images.
 */
private static WaveletTransform createDefaultShrinkTransform(ImageDataType imageType, int numLevels, double minPixelValue, double maxPixelValue) {
    WaveletTransform descTran;
    if (!imageType.isInteger()) {
        WaveletDescription<WlCoef_F32> waveletDesc_F32 = FactoryWaveletDaub.daubJ_F32(4);
        descTran = FactoryWaveletTransform.create_F32(waveletDesc_F32, numLevels, (float) minPixelValue, (float) maxPixelValue);
    } else {
        WaveletDescription<WlCoef_I32> waveletDesc_I32 = FactoryWaveletDaub.biorthogonal_I32(5, BorderType.REFLECT);
        descTran = FactoryWaveletTransform.create_I(waveletDesc_I32, numLevels, (int) minPixelValue, (int) maxPixelValue, ImageType.getImageClass(ImageType.Family.GRAY, imageType));
    }
    return descTran;
}
Also used : WlCoef_F32(boofcv.struct.wavelet.WlCoef_F32) WlCoef_I32(boofcv.struct.wavelet.WlCoef_I32) FactoryWaveletTransform(boofcv.factory.transform.wavelet.FactoryWaveletTransform) WaveletTransform(boofcv.abst.transform.wavelet.WaveletTransform)

Example 4 with WlCoef_I32

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

the class WaveletTransformOps method transform1.

/**
 * <p>
 * Performs a single level wavelet transform.
 * </p>
 *
 * @param desc Description of the wavelet.
 * @param input Input image. Not modified.
 * @param output Where the wavelet transform is written to. Modified.
 * @param storage Optional storage image.  Should be the same size as output image. If null then
 * an image is declared internally.
 */
public static void transform1(WaveletDescription<WlCoef_I32> desc, GrayS32 input, GrayS32 output, GrayS32 storage) {
    UtilWavelet.checkShape(input, output);
    WlCoef_I32 coef = desc.getForward();
    if (output.width < coef.scaling.length || output.width < coef.wavelet.length)
        throw new IllegalArgumentException("Wavelet is too large for provided image.");
    if (output.height < coef.scaling.length || output.height < coef.wavelet.length)
        throw new IllegalArgumentException("Wavelet is too large for provided image.");
    storage = InputSanityCheck.checkDeclare(output, storage);
    // the faster routines can only be run on images which are not too small
    int minSize = Math.max(coef.getScalingLength(), coef.getWaveletLength()) * 3;
    if (input.getWidth() <= minSize || input.getHeight() <= minSize) {
        ImplWaveletTransformNaive.horizontal(desc.getBorder(), coef, input, storage);
        ImplWaveletTransformNaive.vertical(desc.getBorder(), coef, storage, output);
    } else {
        ImplWaveletTransformInner.horizontal(coef, input, storage);
        ImplWaveletTransformBorder.horizontal(desc.getBorder(), coef, input, storage);
        ImplWaveletTransformInner.vertical(coef, storage, output);
        ImplWaveletTransformBorder.vertical(desc.getBorder(), coef, storage, output);
    }
}
Also used : WlCoef_I32(boofcv.struct.wavelet.WlCoef_I32)

Example 5 with WlCoef_I32

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

the class WaveletTransformOps method inverse1.

/**
 * <p>
 * Performs a single level inverse wavelet transform. Do not pass in a whole image which has been
 * transformed by a multilevel transform.  Just the relevant sub-image.
 * </p>
 *
 * @param desc Description of the inverse wavelet.
 * @param input Input wavelet transform. Not modified.
 * @param output Reconstruction of original image. Modified.
 * @param storage Optional storage image.  Should be the same size as the input image. If null then
 * an image is declared internally.
 * @param minValue Minimum allowed pixel value
 * @param maxValue Maximum allowed pixel value
 */
public static void inverse1(WaveletDescription<WlCoef_I32> desc, GrayS32 input, GrayS32 output, GrayS32 storage, int minValue, int maxValue) {
    UtilWavelet.checkShape(output, input);
    WlCoef_I32 coef = desc.getForward();
    if (output.width < coef.scaling.length || output.width < coef.wavelet.length)
        throw new IllegalArgumentException("Wavelet is too large for provided image.");
    if (output.height < coef.scaling.length || output.height < coef.wavelet.length)
        throw new IllegalArgumentException("Wavelet is too large for provided image.");
    storage = InputSanityCheck.checkDeclare(input, storage);
    // the faster routines can only be run on images which are not too small
    int minSize = Math.max(coef.getScalingLength(), coef.getWaveletLength()) * 3;
    if (output.getWidth() <= minSize || output.getHeight() <= minSize) {
        ImplWaveletTransformNaive.verticalInverse(desc.getBorder(), desc.getInverse(), input, storage);
        ImplWaveletTransformNaive.horizontalInverse(desc.getBorder(), desc.getInverse(), storage, output);
    } else {
        ImplWaveletTransformInner.verticalInverse(desc.getInverse().getInnerCoefficients(), input, storage);
        ImplWaveletTransformBorder.verticalInverse(desc.getBorder(), desc.getInverse(), input, storage);
        ImplWaveletTransformInner.horizontalInverse(desc.getInverse().getInnerCoefficients(), storage, output);
        ImplWaveletTransformBorder.horizontalInverse(desc.getBorder(), desc.getInverse(), storage, output);
    }
    if (minValue != Integer.MIN_VALUE && maxValue != Integer.MAX_VALUE)
        PixelMath.boundImage(output, minValue, maxValue);
}
Also used : WlCoef_I32(boofcv.struct.wavelet.WlCoef_I32)

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