This paper presents a novel dictionary learning method which, because of its simplicity and the limited number of training samples it requires, can be used for online learning of dictionaries for spatial texture prediction. The proposed learning method has first been described to address the problem of intra image prediction based on signal expansion on overcomplete dictionaries. It has then been evaluated in a complete image codec. The experimental results obtained show a significant improvement in terms of the quality of the predicted image compared to H.264/AVC intra prediction. Significant rate-distortion gains have also been achieved on the reconstructed image, after coding and decoding the prediction residue, compared with the H.264/AVC and a sparse spatial prediction method which will be referred to as the generalized template matching approach.