added a check for image size and cols