This paper discusses the realization of an adaptive weighted median filter which can eliminate impulsive noise while preserving the original signal. We propose a method in which the weights are determined by a weight controller composed of a counterpropagation network, and the learning algorithm is investigated. The weight controller executes a kind of pattern matching, in which the inputs are classified according to their characteristics and the corresponding weight masks are assigned. By this technique, the preservation of the original signal is improved. Since a neural network is employed, the class of the input signal and the corresponding mask can be determined by learning, which lead to a satisfactory result. The effectiveness of the proposed method is demonstrated with an actual image processing example.