Nonlinear signal processing elements are increasingly needed in current signal processing systems. Stack filters form a large class of nonlinear filters, which have found a range of applications, giving excellent results in the area of noise filtering. Naturally, the development of fast procedures for the optimization of stack filters is one of the major aims in the research in the field. The objective of the optimization method presented in this paper is to find the stack filter producing optimal noise attenuation and satisfying given constraints. The constraints may limit the search into a set of stack filters with some common statistical description or they may describe certain structures which must be preserved or deleted.