Search in sources :

Example 11 with GrowQueue_I8

use of org.ddogleg.struct.GrowQueue_I8 in project BoofCV by lessthanoptimal.

the class TestGaliosFieldTableOps method polyEval.

@Test
public void polyEval() {
    GaliosFieldTableOps alg = new GaliosFieldTableOps(8, primitive8);
    // Create an arbitrary polynomial: 0x12*x^2 + 0x54*x + 0xFF
    GrowQueue_I8 inputA = new GrowQueue_I8();
    inputA.resize(3);
    inputA.set(0, 0x12);
    inputA.set(1, 0x54);
    inputA.set(2, 0xFF);
    int input = 0x09;
    int found = alg.polyEval(inputA, input);
    int expected = 0xFF ^ alg.multiply(0x54, input);
    expected ^= alg.multiply(0x12, alg.multiply(input, input));
    assertEquals(expected, found);
}
Also used : GrowQueue_I8(org.ddogleg.struct.GrowQueue_I8) Test(org.junit.Test)

Example 12 with GrowQueue_I8

use of org.ddogleg.struct.GrowQueue_I8 in project BoofCV by lessthanoptimal.

the class TestGaliosFieldTableOps method polyAdd.

@Test
public void polyAdd() {
    GaliosFieldTableOps alg = new GaliosFieldTableOps(8, primitive8);
    // Create an arbitrary polynomial: 0x12*x^2 + 0x54*x + 0xFF
    GrowQueue_I8 inputA = new GrowQueue_I8(3);
    inputA.resize(3);
    inputA.set(0, 0x12);
    inputA.set(1, 0x54);
    inputA.set(2, 0xFF);
    // Create an arbitrary polynomial: 0xA0*x^3 + 0x45
    GrowQueue_I8 inputB = new GrowQueue_I8(4);
    inputB.resize(4);
    inputB.set(0, 0xA0);
    inputB.set(3, 0x45);
    // make sure the order doesn't matter
    GrowQueue_I8 output0 = new GrowQueue_I8();
    alg.polyAdd(inputA, inputB, output0);
    GrowQueue_I8 output1 = new GrowQueue_I8();
    alg.polyAdd(inputB, inputA, output1);
    assertEquals(4, output0.size);
    assertEqualsG(output0, output1);
    // compare to hand computed solution
    assertEquals(0xA0, output0.data[0] & 0xFF);
    assertEquals(0x12, output0.data[1] & 0xFF);
    assertEquals(0x54, output0.data[2] & 0xFF);
    assertEquals(0xFF ^ 0x45, output0.data[3] & 0xFF);
}
Also used : GrowQueue_I8(org.ddogleg.struct.GrowQueue_I8) Test(org.junit.Test)

Example 13 with GrowQueue_I8

use of org.ddogleg.struct.GrowQueue_I8 in project BoofCV by lessthanoptimal.

the class TestReidSolomonCodes method findErrors_BruteForce_TooMany.

/**
 * Test a case where there are too many errors.
 */
@Test
public void findErrors_BruteForce_TooMany() {
    GrowQueue_I8 message = randomMessage(50);
    findErrors_BruteForce(message, 6, true);
    findErrors_BruteForce(message, 8, true);
}
Also used : GrowQueue_I8(org.ddogleg.struct.GrowQueue_I8) Test(org.junit.Test)

Example 14 with GrowQueue_I8

use of org.ddogleg.struct.GrowQueue_I8 in project BoofCV by lessthanoptimal.

the class TestReidSolomonCodes method findErrors_BruteForce.

public void findErrors_BruteForce(GrowQueue_I8 message, int numErrors, boolean expectedFail) {
    GrowQueue_I8 ecc = new GrowQueue_I8();
    int nsyn = 10;
    GrowQueue_I8 syndromes = GrowQueue_I8.zeros(nsyn);
    GrowQueue_I8 errorLocator = new GrowQueue_I8();
    GrowQueue_I32 locations = new GrowQueue_I32();
    ReidSolomonCodes alg = new ReidSolomonCodes(8, primitive8);
    alg.generator(nsyn);
    alg.computeECC(message, ecc);
    GrowQueue_I8 cmessage = message.copy();
    // corrupt the message and ecc
    int N = message.size + ecc.size;
    int[] corrupted = selectN(numErrors, N);
    for (int i = 0; i < corrupted.length; i++) {
        int w = corrupted[i];
        if (w < message.size)
            cmessage.data[w] ^= 0x45;
        else {
            ecc.data[w - message.size] ^= 0x45;
        }
    }
    // compute needed info
    alg.computeSyndromes(cmessage, ecc, syndromes);
    alg.findErrorLocatorPolynomialBM(syndromes, errorLocator);
    if (expectedFail) {
        assertFalse(alg.findErrorLocations_BruteForce(errorLocator, N, locations));
    } else {
        // find the error locations
        assertTrue(alg.findErrorLocations_BruteForce(errorLocator, N, locations));
        // see if it found the expected number of errors and that the locations match
        assertEquals(numErrors, locations.size);
        for (int i = 0; i < locations.size; i++) {
            int num = 0;
            for (int j = 0; j < corrupted.length; j++) {
                if (corrupted[j] == locations.data[i]) {
                    num++;
                }
            }
            assertEquals(1, num);
        }
        GrowQueue_I8 hack = new GrowQueue_I8();
        alg.findErrorLocatorPolynomial(N, locations, hack);
    }
}
Also used : GrowQueue_I8(org.ddogleg.struct.GrowQueue_I8) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 15 with GrowQueue_I8

use of org.ddogleg.struct.GrowQueue_I8 in project BoofCV by lessthanoptimal.

the class TestReidSolomonCodes method findErrorLocatorPolynomialBM.

/**
 * Computed using a reference implementation found at [1].
 */
@Test
public void findErrorLocatorPolynomialBM() {
    GrowQueue_I8 message = GrowQueue_I8.parseHex("[ 0x40, 0xd2, 0x75, 0x47, 0x76, 0x17, 0x32, 0x06, 0x27, 0x26, 0x96, 0xc6, 0xc6, 0x96, 0x70, 0xec ]");
    GrowQueue_I8 ecc = new GrowQueue_I8();
    int nsyn = 10;
    GrowQueue_I8 syndromes = GrowQueue_I8.zeros(nsyn);
    ReidSolomonCodes alg = new ReidSolomonCodes(8, primitive8);
    alg.generator(nsyn);
    alg.computeECC(message, ecc);
    message.data[0] = 0;
    alg.computeSyndromes(message, ecc, syndromes);
    GrowQueue_I8 errorLocator = new GrowQueue_I8();
    alg.findErrorLocatorPolynomialBM(syndromes, errorLocator);
    assertEquals(2, errorLocator.size);
    assertEquals(3, errorLocator.get(0));
    assertEquals(1, errorLocator.get(1));
    message.data[6] = 10;
    alg.computeSyndromes(message, ecc, syndromes);
    alg.findErrorLocatorPolynomialBM(syndromes, errorLocator);
    assertEquals(3, errorLocator.size);
    assertEquals(238, errorLocator.get(0) & 0xFF);
    assertEquals(89, errorLocator.get(1));
    assertEquals(1, errorLocator.get(2));
}
Also used : GrowQueue_I8(org.ddogleg.struct.GrowQueue_I8) Test(org.junit.Test)

Aggregations

GrowQueue_I8 (org.ddogleg.struct.GrowQueue_I8)30 Test (org.junit.Test)22 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)3 GrayU16 (boofcv.struct.image.GrayU16)1 File (java.io.File)1 Buffer (java.nio.Buffer)1 ByteBuffer (java.nio.ByteBuffer)1