helper functions for up/down sampling an image