C++ program to remove bad pixels using average of neighbouring pixels