Matlab to C++ percentile clipping
The block

for (int i = 0; i &lt; _roiY1; i++)
{
    for (int j = 0; j &lt; newWidth; j++)
    {
        channel_gr[i*newWidth + j] = clipLevel;
    }
}


can be made more concise by using std::fill.

std::fill(channel_gr, channel_gr+_roiY1*newWidth, cliplevel);


I won't vouch for better performance though.