Originally, mathematical morphology was a theory of signal transformations which are invariant under Euclidean translations. An interest in the extension of mathematical morphology to spatially-variant (SV) operators has emerged due to the requirements imposed by numerous applications in adaptive signal (image) processing. This paper presents a general theory of spatially-variant mathematical morphology in the Euclidean space. We define the binary and gray-level spatially-variant basic morphological operators (i.e., erosion, dilation, opening and closing) and study their properties. We subsequently derive kernel representations for a large class of binary and gray-level SV operators in terms of the basic SV morphological operators. The theory of SV mathematical morphology is used to extend and analyze two important image processing applications: morphological image restoration and skeleton representation of binary images. For morphological image restoration, we obtain new realizations of adaptive median filters in terms of the basic SV morphological operators. For skeleton representation, we develop an algorithm to construct the optimal structuring elements, in the sense of minimizing the cardinality of the spatially-variant morphological skeleton representation. Experimental results show the power of the proposed theory of spatially-variant mathematical morphology in practical image processing applications.