Picture *OpenCVPicture::distort(RNG &rng, batchType type) { OpenCVPicture *pic = new OpenCVPicture(*this); if (epoch <= 800 and type == TRAINBATCH) { // 2x2 identity matrix: // Generate an affine distortion matrix float c00 = 1, c01 = 0, c10 = 0, c11 = 1; c00 *= 1 + rng.uniform(-0.2, 0.2); // x stretch c11 *= 1 + rng.uniform(-0.2, 0.2); // y stretch if (rng.randint(2) == 0) // Horizontal flip c00 *= -1; int r = rng.randint(3); float alpha = rng.uniform(-0.2, 0.2); if (r == 0) // Slant matrixMul2x2inPlace(c00, c01, c10, c11, 1, 0, alpha, 1); if (r == 1) // Slant matrixMul2x2inPlace(c00, c01, c10, c11, 1, alpha, 0, 1); if (r == 2) // Rotate matrixMul2x2inPlace(c00, c01, c10, c11, cos(alpha), -sin(alpha), sin(alpha), cos(alpha)); pic->affineTransform(c00, c01, c10, c11); pic->jiggle(rng, 16); pic->colorDistortion(rng, 25.5, 0.15, 2.4, 2.4); } return pic; }
Picture *OpenCVPicture::distort(RNG &rng, batchType type) { OpenCVPicture *pic = new OpenCVPicture(*this); pic->loadDataWithoutScaling(0); float c00 = 1, c01 = 0, // 2x2 identity matrix---starting point for // calculating affine distortion matrix c10 = 0, c11 = 1; float r, alpha, beta, s = 1; if (type == TRAINBATCH) { r = rng.uniform(-0.1, 0.1); alpha = rng.uniform(0, 2 * 3.1415926535); beta = rng.uniform(-0.2, 0.2) + alpha; } else { r = 0; alpha = rng.uniform(0, 2 * 3.1415926535); beta = alpha; } c00 = (1 + r) * cos(alpha); c01 = (1 + r) * sin(alpha); c10 = -(1 - r) * sin(beta); c11 = (1 - r) * cos(beta); if (rng.randint(2) == 0) { c00 *= -1; c01 *= -1; } // Horizontal flip pic->affineTransform(c00, c01, c10, c11); pic->jiggle(rng, 300); return pic; }