The weighted median filter (WMF) is a generalization of the median filter. The WMF is more effective for image processing than the conventional. However, the design of the parameters of the WMF is a difficult problem. In this letter, a novel method of optimizing the WMF is proposed. This method utilizes a close relation between the nonrecursive WMF and the feed-forward neural network with shift-invariant weight coefficients. The optimization problem of the WMF results in the learning of the interconnection weights of the network.