148 IEEE SIGNAL PROCESSING LETTERS, VOL. 9, NO. 5, MAY2002 An Efficient Algorithm to Calculate Sample and Rank Selection Probabilities for Weighted Median Filters Aldo Morales, Senior Member, IEEE, Eugene Boman, and Sung Jea Ko, Senior Member, IEEE Abstract—Sample and rank selection probabilities are impor- tant in the analysis of weighted median filters as well as in com- paring linear and nonlinear filters. In this correspondence, we pro- pose a new, efficient algorithm to calculate these probabilities for weighted median filters. The computational savings of this new al- gorithm are substantial and compare favorably with other known algorithms [1], [3]. Index Terms—Nonlinear filters, rank and sample selection prob- abilities, weighted median filters. I. INTRODUCTION W EIGHTED median filters were first introduced by Brownrigg [4]. Given a set of positive integers the output of a weighted median filter (WMF) is given by (1) where are the input samples, and is the replicator operator defined as . In order to analyze these filters, Prasad and Lee [11] introduced rank and sample selection probabilities. They defined these probabilities as follows. Rank Selection Probability (RSP): The th rank selection probability is denoted by and is the probability that the output equals the th smallest sample . Sample Selection Probability (SSP): The th sample selec- tion probability is denoted by and is the probability that the output equals the th sample . These two important definitions are essential to understanding the relationship between linear and nonlinear filters [2], [5]. For instance, Mallows [8] has defined the “linear part” of a stack filter of size , with independent and identically distributed (i.i.d.) in- puts, to be an FIR filter whose impulse response coefficients are equal to th sample selection probability. Clearly it is essential to develop efficient algorithms to find the SSPs (RSPs). In [6] Boolean derivatives were used to find SSPs. Manuscript received April 25, 2001; revised March 13, 2002. The associate editor coordinating the review of this manuscript and approving it for publica- tion was Dr. Yingbo Hua. A. Morales was with the College of Engineering, Pennsylvania State Uni- versity at DuBois, DuBois, PA 15801 USA. He is now with the Electrical En- gineering Department, Penn State University at Harrisburg, Middletown, PA 17057 USA (e-mail: awm2@psu.edu). E. Boman is with the Division of Mathematics, Pennsylvania State University at DuBois, DuBois, PA 15801 USA (e-mail: ecb5@psu.edu). S. J. Ko is with the Electronics Engineering Department, Korea University, Seoul, Korea (e-mail: sjko@dali.korea.ac.kr). Publisher Item Identifier S 1070-9908(02)06042-X. In [7] RSPs and SSPs were calculated for the case of stack filters. In [10] and [12], an algorithm is developed to find the SSPs from a set of partial sums generated by an induced tree of weights. In [1] and [3] rank and sample selection probabilities are calculated from generating functions in terms of binomial polynomials in two dimensions using a matrix convolution [1] or a clever recur- sive algorithm [3]. However, the algorithms in [1] and [3] do not take into account the highly symmetric nature of binomial coef- ficients as pointed out in [9] nor the sparsity of the matrices in- volved. We will show that, using this symmetry and sparsity, one can reduce the number of computations by a factor of 5. In this correspondence we will first state a simple general lemma which can be regarded as a general proof of algorithms 8.4 and 8.5 of [1]. Then an efficient implementation for the cal- culations of RSPs and SSPs will be provided. First, the definition of the combination matrix is needed. The entries of the combination matrix are given by the fol- lowing theorem. Theorem [11]: The function is a polynomial in the arbitrary variables and . Let the coefficients of in be given by then (2) where Once the ’s are known, each entry of the permutation ma- trix is calculated by (3) The RSPs and SSPs are calculated by adding entries of the matrix, row-wise (for RSP) or column-wise (for SSP) and dividing by . A. General Lemma From the introductory comments it is clear that the theorem presented is of essential importance. In fact generating the poly- nomials in and is the crucial computation needed to obtain the combination matrix. To calculate these polynomials let (4) where is the number of repetitions of a given weight and is the number of distinct weights. If no weight is repeated then each . Note also that if there are repeated weights (which 1070-9908/02$17.00 © 2002 IEEE