void getDistortionValues(cv::RNG &rng, const Size2i &inputSize, AugParams *agp) { // This function just gets the random distortion values without modifying the // image itself. Useful if we need to reapply the same transformations over // again (e.g. for all frames of a video or for a corresponding target mask) // colornoise values // N.B. if _contrastMax == 100, then _colorNoiseStd will be 0.0 for (int i=0; i<3; i++) { agp->colornoise[i] = rng.gaussian(_colorNoiseStd); } // contrast, brightness, saturation // N.B. all value ranges tied to _contrastMin and _contrastMax for (int i=0; i<3; i++) { agp->cbs[i] = rng.uniform(_contrastMin, _contrastMax) / 100.0f; } /************************** * HORIZONTAL FLIP * ***************************/ agp->flip = _flip && rng(2) != 0 ? true : false; /************************** * ROTATION ANGLE * ***************************/ agp->angle = rng.uniform(_rotateMin, _rotateMax); /************************** * CROP BOX * ***************************/ float shortSide = std::min(inputSize.height, inputSize.width); // Special case where we just grab the whole image; if (_scaleMin == 0) { agp->cropBox = Rect(Point2i(), inputSize); return; } if (_center) { agp->cropBox.width = shortSide * _width / (float) _scaleMin; agp->cropBox.height = shortSide * _height / (float) _scaleMin; agp->cropBox.x = (inputSize.width - agp->cropBox.width) / 2; agp->cropBox.y = (inputSize.height - agp->cropBox.height) / 2; } else { cv::Size2f oSize = inputSize; // This is a hack for backward compatibility. // Valid aspect ratio range ( > 100) will override side scaling behavior if (_aspectRatio == 0) { float scaleFactor = rng.uniform(_scaleMin, _scaleMax); agp->cropBox.width = shortSide * _width / scaleFactor; agp->cropBox.height = shortSide * _height / scaleFactor; } else { float mAR = (float) _aspectRatio / 100.0f; float nAR = rng.uniform(1.0f / mAR, mAR); float oAR = oSize.width / oSize.height; // between minscale pct% to 100% subject to aspect ratio limitation float maxScale = nAR > oAR ? oAR / nAR : nAR / oAR; float minScale = std::min((float) _scaleMin / 100.0f, maxScale); float tgtArea = rng.uniform(minScale, maxScale) * oSize.area(); agp->cropBox.height = sqrt(tgtArea / nAR); agp->cropBox.width = agp->cropBox.height * nAR; } agp->cropBox.x = rng.uniform(0, inputSize.width - agp->cropBox.width); agp->cropBox.y = rng.uniform(0, inputSize.height - agp->cropBox.height); } return; }