Image segmentation is considered one of the most important tasks in image processing, which has several applications in different areas such as; industry agriculture, medicine, etc. In this paper, we develop the electromagnetic optimization (EMO) algorithm based on levy function, EMO-levy, to enhance the EMO performance for determining the optimal multi-level thresholding of image segmentation. In general, EMO simulates the mechanism of attraction and repulsion between charges to develop the individuals of a population. EMO takes random samples from search space within the histogram of image, where, each sample represents each particle in EMO. The quality of each particle is assessed based on Otsu's or Kapur objective function value. The solutions are updated using EMO operators until determine the optimal objective functions. Finally, this approach produces segmented images with optimal values for the threshold and a few number of iterations. The proposed technique is validated using different standard test images. Experimental results prove the effectiveness and superiority of the proposed algorithm for image segmentation compared with well-known optimization methods.