modifined image processing codes for easier understanding