We describe a new bad pixel correction algorithm designed originally to correct two-dimensional images containing high-fidelity spectroscopic data. Our method can be used to correct images with significant rates of adjacent bad pixels or bad pixel clusters such as taken by infrared focal plane arrays. It is applicable to any image data that can be locally approximated by a second-degree polynomial. A filter performing the correction can be easily implemented in programmable hardware utilizing very little resources. The accuracy of the method is analyzed and its performance tested on real spectroscopic data.