Detection of defects in fruits and vegetables using k means segmentation and Otsu thresholding in Matlab. Both external and internal defects are detected. For external defects, the surface of the fruits in the image is processed. For internal defects, two approaches are followed. In the first one, the internal images of the fruits are processed for defects, whereas in the second one, the X-ray images of the images are taken and processed for defects.