Quantitative analysis of nanostructures from scanning electron microscope (SEM) images requires a clear segmentation of grains and their boundaries. This is not provided by active contour models, which also require user guidance. Our automatic technique creates a rough representation of grain boundaries by adaptive thresholding. It then performs raycasting from a rectangular grid of seed points to ensure that the grain shapes are convex, and selects the best result for each grain. The whole process can be repeated several times to improve the segmentation. We present results for images of titanium foil, which show that our approach compares favorably in terms of speed and segmentation quality with four competing techniques.