Diabetic macular edema (DME) is a major cause of visual loss in the patients with diabetic retinopathy. DME detection in Optical Coherence Tomography (OCT) image contributes to the early diagnosis of diabetic retinopathy and blindness prevention. Currently, DME detection in the OCT image mainly relies on the handwork by the experienced clinician. It is a laborious, time-consuming, and challenging work to organize a comprehensive DME screening for diabetic patients. In this study, we proposed a novel algorithm for the detection and segmentation of DME region in OCT image based on the K-means clustering algorithm and improved Selective Binary and Gaussian Filtering regularized level set (SBGFRLS) algorithm named as SBGFRLS-OCT algorithm. SBGFRLS-OCT algorithm was compared with the current level set algorithms, including C-V (Chan-Vese), GAC (geodesic active contour), and SBGFRLS, to estimate the performance of DME detection. SBGFRLS-OCT algorithm was also compared with the clinician to estimate the precision, sensitivity, and specificity of DME segmentation. Compared with C-V, GAC, and SBGFRLS algorithm, the SBGFRLS-OCT algorithm enhanced the accuracy and reduces the processing time of DME detection. Compared with manual DME segmentation, the SBGFRLS-OCT algorithm achieved a comparable precision (97.7%), sensitivity (91.8%), and specificity (99.2%). Collectively, this study presents a novel algorithm for DME detection in the OCT image, which can be used for mass diabetic retinopathy screening.