This paper presents a context-based filter to denoise grayscale images affected by random valued impulse noise. A support vector machine classifier is used for noise detection and two Markov filter variants are evaluated for their denoising capacity. The classifier needs to be trained on a set of training images. The experiments performed on another set of test images have shown that the support vector machine with the radial basis function kernel combined with the Markov+ filter is the best configuration, providing the highest noise detection accuracy. Our filter was compared with existing denoising methods, it being better on some images and comparable with them on others.