See my code in this answer: http://www.mathworks.com/matlabcentral/answers/18504-how-to-remove-deadpixels-from-the-image
It does exactly what you are asking for. If not it would take just slight modifications.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!