It could be shorter:

    radius = std::min(radius, sqrt(img.cols*img.cols + img.rows*img.rows));