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

Averaging the pixels is trivial; the hard part is identifying 'bad' pixels. Really, what is a 'bad' pixel? You must answer that question in the context of your images and what they contain.