Feature classification in digital medical images like mammography presents an optimization problem which researchers often neglect. The use of a convolutional neural network (CNN) in feature extraction and classification has been widely reported in the literature to have achieved outstanding performance and acceptance in the disease detection procedure. However, little emphasis is placed on ensuring that only discriminant features extracted by the convolutional operations are passed on to the classifier, to avoid bottlenecking the classification operation. Unfortunately, since this has been left unaddressed, a subtle performance impairment has resulted from this omission. Therefore, this study is devoted to addressing these drawbacks using a metaheuristic algorithm to optimize the number of features extracted by the CNN, so that suggestive features are applied for the classification process. To achieve this, a new variant of the Ebola-based optimization algorithm is proposed, based on the population immunity concept and the use of a chaos mapping initialization strategy. The resulting algorithm, called the immunity-based Ebola optimization search algorithm (IEOSA), is applied to the optimization problem addressed in the study. The optimized features represent the output from the IEOSA, which receives the noisy and unfiltered detected features from the convolutional process as input. An exhaustive evaluation of the IEOSA was carried out using classical and IEEE CEC benchmarked functions. A comparative analysis of the performance of IEOSA is presented, with some recent optimization algorithms. The experimental result showed that IEOSA performed well on all the tested benchmark functions. Furthermore, IEOSA was then applied to solve the feature enhancement and selection problem in CNN for better prediction of breast cancer in digital mammography. The classification accuracy returned by the IEOSA method showed that the new approach improved the classification process on detected features when using CNN models.