added support for sorting parts of the image instead of the whole