Fruits picking by human is a time consuming, tedious and expensive task. For this reason, the automation of fruit harvesting has achieved great popularity in the last decade. Tomato fruits do not ripe simultaneously and one of the main challenges in the design of a tomato harvester robot is its ability in recognition and localization of ripen tomato on the plant. In the current study, a new segmentation algorithm was developed for guidance of a robot arm to pick the ripen tomato using a machine vision system. To reach this aim, a vision system was used to acquire images from tomato plant. The recognition algorithm had to be adaptive to the lighting conditions of greenhouse. Totally 110 color images of tomato were acquired under greenhouse light conditions. The developed algorithm works in two steps: (1) by removing the background in RGB color space and then extract the ripen tomato using combination of RGB, HSI, and YIQ spaces and (2) localizing the ripen tomato using morphological features of image. According to the results, the total accuracy of proposed algorithm was 96.36%.