1. A method of controlling polishing, comprising: storing a library having a plurality of reference spectra; polishing a substrate; measuring a sequence of spectra of light from the substrate during polishing; for each measured spectrum of the sequence of spectra, finding a best matching reference spectrum from the plurality of reference spectra to generate a sequence of best matching reference spectra, wherein finding the best matching reference spectrum uses a cell counting technique; and determining at least one of a polishing endpoint or an adjustment for a polishing rate based on the sequence of best matching reference spectra.