Added checks for size of ROI

To prevent crashing.