Moved some functions
Cleaned up some code for setting the ROI of images

Now uses a (x,y,w,h) tuple everywhere. Cleaner that way.
Take into account the ROI when the image is scaled down

If a maximum perimeter is set, get the perimeter from the ROI if
a ROI is set. Otherwise you might end up with a very small ROI.