This paper presents image processing algorithms for a selective robotic sprayer in vineyards. Two types of machine vision algorithms were developed to directly spray grape clusters and foliage. The first algorithm is based on the difference in the distribution of edges between the foliage and the grape clusters. The second detection algorithm uses a decision tree algorithm for separating the grape clusters from the background based on a training dataset from 100 images. Both image processing algorithms were tested on data from movies acquired in vineyards during the growing season of 2008. Results indicate high reliability of both foliage detection and grape clusters detection. Preliminary results show 90% percent accuracy of grape clusters detection, leading to 30% reduction in the use of pesticides.