During the past few decades digital images have become an important part of numerous scientific fields. Digital images used in medicine enabled tremendous progress in the diagnostics, treatment determination process as well as in monitoring patient recovery. Detection of brain tumors represents one of the active research fields and an algorithm for brain image segmentation was developed with an aim to emphasize four different primary brain tumors: glioma, metastatic adenocarcinoma, metastatic bronchogenic carcinoma and sarcoma from PET, MRI and SPECT images. The proposed image segmentation method is based on the firefly algorithm whose solutions are improved by the k-means clustering algorithm when Otsu's criterion was used as the fitness function. The proposed combined algorithm was tested on commonly used images from Harvard Whole Brain Atlas and the results were compared to other method from literature. The method proposed in this paper achieved better segmentation considering standard segmentation quality metrics such as normalized root square mean error, peak signal to noise and structural similarity index metric.