Grayscale morphology has been widely used in image processing, especially in noise removal. In this paper, we find an optimal solution for designing a grayscale morphological filter. An adaptive algorithm is developed for determining, from a given class of grayscale morphological filters, a filter which minimizes the mean square error between its output and a desired process. The adaptation using the conventional least mean square algorithm optimizes the grayscale structuring element in a given search area. The performance of noise removal is compared to another class of nonlinear filters, i.e., adaptive and nonadaptive stack-based filters.