modified image processing codes for easier understanding