Add comments , re-order code and use
userRoI.downscalePowerOfTwoSmallestEnclosing
in getImageRectangleDisplayed