Added algorithm to check if image is going out of bounds.