This paper presents a dynamic thresholding algorithm for robotic apple detection. The algorithm enables robust detection in highly variable lighting conditions. The image is dynamically split into variable sized regions, where each region has approximately homogeneous lighting conditions. Nine thresholds were selected so as to accommodate three different illumination levels for three different dimensions in the natural difference index (NDI) space by quantifying the required relation between true positive rate and false positive rate. This rate can change along the robotic harvesting process, aiming to decrease FPR from far views (to minimize cycle times) and to increase TPR from close views (to increase grasping accuracy). Analyses were conducted on apple images acquired in outdoor conditions. The algorithm improved previously reported results and achieved 91.14% true positive rate (TPR) with 3.05% false positive rate (FPR) using the NDI first dimension and a noise removal process.