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 used 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 scans, 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 for measuring 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 scans, 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 capable of performing elementary morphological transformations in brain images of MS patients and healthy individuals in order to delete undesirable components and extract the relevant structures such as MS lesions. Also, the algorithm computes the granulometry in MRI scans to describe the size qualities of lesions. Using this algorithm, we trained two artificial neural networks (ANNs) to predict MS diagnoses. By computing the differences in granulometry measurements between an image with MS lesions and a reference image (without lesions), we determined the size characterization of the lesions. Then, the ANNs were evaluated with the validation set, and the performance results (test accuracy = 0.9753; cross-entropy loss = 0.0247) show that the proposed algorithm can support specialists in making decisions to diagnose MS and estimating the disease progress based on granulometry values.