The symptoms of multiple sclerosis (MS) are determined by the location of demyelinating lesions in the white matter of the brain and spinal cord. Currently, magnetic resonance imaging (MRI) is the most common tool for diagnosing MS, understanding the course of the disease, and analyzing the effects of treatments. However, undesirable components may appear during the generation of MRI, such as noise or intensity variations. Mathematical morphology (MM) is a powerful image analysis technique that helps to filter the image and extract relevant structures. Granulometry is an image measurement tool of MM that determines the size distribution of objects in an image without explicitly segmenting each object. While, several methods have been proposed for the automatic segmentation of MS lesions in MRI, in some cases only simple data preprocessing, such as image resizing to standardize the input dimensions, has been performed before the algorithm training. Therefore, this paper proposes an MRI preprocessing algorithm performing elementary morphological transformations in brain images of MS patients and healthy individuals to delete undesirable components and extract the relevant structures such as MS lesions. Also, the algorithm computes the granulometry in MRI to describe the size qualities of lesions and trains two artificial neural networks (ANN) to predict MS diagnosis. The computing of differences in granulometry measurements of an image with MS lesions and a reference image (without lesions) can determine the size characterization of the lesions. Then, the ANNs were evaluated with the validation set and the performance results (test accuracy = 0.9753, and cross-entropy loss = 0.0247) show the proposed algorithm can support the decision of specialists for diagnosing MS and estimating the disease progress, based on granulometry values.