Package ru.ifmo.diplom.kirilchuk.jawelet.core.dwt.filters

Examples of ru.ifmo.diplom.kirilchuk.jawelet.core.dwt.filters.Filter


    @Override
    public void reconstructInplace(double[] data, int approxLength) {
        Assert.checkNotNull(data, "Data vector can`t be null.");

        Filter lowReconstructionFilter = filtersFactory.getLowReconstructionFilter();
        Filter highReconstructionFilter = filtersFactory.getHighReconstructionFilter();
       
//        while(approxLength <= data.length/2) {
            double[] approximation = new double[approxLength];
            System.arraycopy(data, 0, approximation, 0, approxLength);

            double[] extendedApproximation = new Extensioner(approximation)
                    .schedule(new CopyElementToBegin(0))
                    .schedule(new AddLastToEnd())
                    .execute();

            extendedApproximation = sampler.upsample(extendedApproximation);
            extendedApproximation = MathUtils.convolve(extendedApproximation, lowReconstructionFilter.getCoeff());
            extendedApproximation = windower.window(extendedApproximation, 2, approximation.length * 2 + 2);

            double[] details = new double[approxLength]; //must have same length with approximation
            System.arraycopy(data, approxLength, details, 0, approxLength);
            double[] extendedDetails = new Extensioner(details)
                    .schedule(new CopyElementToBegin(1))
                    .schedule(new AddLastToEnd())
                    .execute();

            extendedDetails = sampler.upsample(extendedDetails);
            extendedDetails = MathUtils.convolve(extendedDetails, highReconstructionFilter.getCoeff());
            extendedDetails = windower.window(extendedDetails, 4, details.length * 2 + 4);

            for (int index = 0; index < approxLength * 2; index++) {
              data[index] = extendedApproximation[index] + extendedDetails[index];
            }
View Full Code Here


     *
     * @param data vector with approximation and details.
     * @param endIndex index where details start and approximations ended.
     */
    private void decomposeInplace1Lvl(double[] data, int endIndex) {
        Filter lowDecompositionFilter  = filtersFactory.getLowDecompositionFilter();
        Filter highDecompositionFilter = filtersFactory.getHighDecompositionFilter();

        double[] approximation = new double[endIndex]; //working only with approximation coefficients
        System.arraycopy(data, 0, approximation, 0, endIndex);

        double[] temp = new Extensioner(approximation)
                .schedule(new MirrorExtension(1))
                .execute();

        //TODO ugly but need one more element...
        double[] extended = new double[temp.length + 1];
        System.arraycopy(temp, 0, extended, 0, temp.length);
        extended[extended.length - 1] = approximation[approximation.length - 3];

        /* Here in "extended" we have extended data to reduce boundary effect */

        temp = MathUtils.convolve(extended, lowDecompositionFilter.getCoeff());
        temp = sampler.downsample(temp);
        temp = windower.window(temp, 2, endIndex / 2 + 2);

        double[] temp2 = MathUtils.convolve(extended, highDecompositionFilter.getCoeff());
        temp2 = sampler.downsample(temp2);
        temp2 = windower.window(temp2, 1, endIndex / 2 + 1);

        System.arraycopy(temp, 0, data, 0, temp.length);
        System.arraycopy(temp2, 0, data, temp.length, temp2.length);
View Full Code Here

     * Test of decomposeLow method, of class CyclicWrappingTransformStrategy.
     */
    @Test
    public void testDecomposeLowWithFilterLength2() {
        double[] data = {11.1, 22.2, 33.3, 44.4, 55.5, 66.6};
        Filter lowDecompositionFilter = new Filter(new double[]{1, 1});
        double[] expResult = {55.5, 99.9, 77.7};
        decomposeLowWithAssert(data, lowDecompositionFilter, expResult);

        lowDecompositionFilter = new Filter(new double[]{15.54, 18.2});
        expResult = new double[]{921.521999999999, 1670.549999999999, 1384.613999999999};
        decomposeLowWithAssert(data, lowDecompositionFilter, expResult);
    }
View Full Code Here

     * Test of decomposeHigh method, of class CyclicWrappingTransformStrategy.
     */
    @Test
    public void testDecomposeHigh() {
        double[] data = {46.2000, 565.8000, 12.1200, 163.5670, 123.1230, 90.8700, 18.3400, 1};
        Filter highDecompositionFilter = new Filter(new double[]{1.12, 1.21, 2.123, 12.2, 14.1, 7.8, 4.7});
        double[] expResult = {8009.72259, 7188.673029, 4216.37072,1546.0581};

        decomposeHighWithAssert(data, highDecompositionFilter, expResult);
    }
View Full Code Here

    @Test
    public void testReconstructEvenVectorWithFilterLength2() {
        double[] approximation = {5, 9, 7};
        double[] details = {-1, -1, 5};

        Filter lowReconstructionFilter = new Filter(new double[]{1, 1});
        Filter highReconstructionFilter = new Filter(new double[]{1, -1});

        double[] expResult = {2, 4, 6, 8, 10, 12};
        double[] result = instance.reconstruct(approximation, details, lowReconstructionFilter, highReconstructionFilter);
        assertArrayEquals(expResult, result, 0);
View Full Code Here

    @Test
    public void testDecomposeReconstructForHaarFilters() {
        HaarFiltersFactory factory = new HaarFiltersFactory();
        double[] data = {20,10,15,12,14,18,40,32,14,14};
        Filter lowDec  = factory.getLowDecompositionFilter();
        Filter highDec = factory.getHighDecompositionFilter();

        double[] lowExpect = {17.6776695296636, 18.38477631085, 41.01219330881975,
                              32.52691193458118, 24.04163056034261};
        double[] low = decomposeLowWithAssert(data, lowDec, lowExpect);

        double[] highExpect = {-3.535533905932737, -1.41421356237309, -15.55634918610404,
                               12.72792206135785, -4.242640687119268};
        double[] high = decomposeLowWithAssert(data, highDec, highExpect);

        Filter lowRec = factory.getLowReconstructionFilter();
        Filter highRec = factory.getHighReconstructionFilter();
        double[] recon = instance.reconstruct(low, high, lowRec, highRec);
        assertArrayEquals(data, recon, DOBLE_COMPARISON_DELTA);

        data = new double[]{23.25, 12.23, 56.124, 76.34, 642.12, 4.1, 87.9};
        lowExpect = new double[]{48.333576921225, 508.027938011286, 65.053823869162, 16.440232662587};
View Full Code Here

     * Test of extend method, of class Extensioner.
     */
    @Test
    public void testExtendEnd() {
        double[] data = {1, 2, 3, 4};
        Filter filter = new Filter(new double[]{2, 8, 4, -1});

        double[] result = new Extensioner(data)
                .schedule(new CyclicEndExtension(filter.getLength()))
                .execute();
        double[] expected = {1, 2, 3, 4, 1, 2, 3, 4};
        assertEquals(expected.length, result.length);
        assertArrayEquals(expected, result, 0);

        data = new double[]{1, 2, 3};
        result = new Extensioner(data)
                .schedule(new ZeroPaddingToEven())
                .schedule(new CyclicEndExtension(filter.getLength()))
                .execute();
        expected = new double[]{1, 2, 3, 0, 1, 2, 3, 0};
        assertEquals(expected.length, result.length);
        assertArrayEquals(expected, result, 0);
    }
View Full Code Here

     * Test of extend method, of class Extensioner.
     */
    @Test
    public void testExtendBeginning() {
        double[] data = {1, 2, 3, 4};
        Filter filter = new Filter(new double[]{2, 8});

        double[] result = new Extensioner(data)
                .schedule(new CyclicBeginExtension(filter.getLength()))
                .execute();

        assertEquals(data.length + filter.getCoeff().length, result.length);

        double[] expected = {3, 4, 1, 2, 3, 4};

        assertArrayEquals(expected, result, 0);
    }
View Full Code Here

    }

    @Test
    public void testEndExtensionWhenFilterLongButDataSmall() {
        double[] data = {1, 2};
        Filter filter = new Filter(new double[]{1, 1, 1, 1, 1, 1, 1});

        double[] result = new Extensioner(data)
                .schedule(new CyclicEndExtension(filter.getLength()))
                .execute();

        double[] expected = {1, 2, 1, 2, 1, 2, 1, 2, 1};
        assertArrayEquals(expected, result, 0);
    }
View Full Code Here

    }

    @Test
    public void testBeginExtensionWhenFilterLongButDataSmall() {
        double[] data = {1, 2};
        Filter filter = new Filter(new double[]{1, 1, 1, 1, 1, 1, 1});

        double[] result = new Extensioner(data)
                .schedule(new CyclicBeginExtension(filter.getLength()))
                .execute();

        double[] expected = {2, 1, 2, 1, 2, 1, 2, 1, 2};
        assertArrayEquals(expected, result, 0);
    }
View Full Code Here

TOP

Related Classes of ru.ifmo.diplom.kirilchuk.jawelet.core.dwt.filters.Filter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.