added index guard while retrieving pixel from image