Roi test develop

Same as #598 but onto develop.
Cherry-picked the commits due to  conflicts.