This article describes a new segmentation by thresholding approach based on learning. The method consists in learning to threshold correctly submitting both an image and its ideal thresholded version. From this stage it is generated a decision matrix for each pixel and each gray level that is re-utilized at the moment of the new images segmentation. The new image is thresholded by means of a new strategy based on the nearest neighbors, that seeks, for each pixel of this new image, the best solution in the decision matrix. Performed tests on handwritten documents showed promising results. In terms of quality of the results, the developed technique is equal or superior to the traditional segmentation by thresholding techniques, with the advantage that the one discussed here does not requires the use of heuristic parameters.