The learning algorithm develops basis functions for natural images that are similar to receptive fields in the primary visual cortex. The algorithm optimizes a cost function that trades off representation quality and sparseness. It searches for basis functions that lead to good sparse approximations of natural image sets. The resulting dictionaries have basis functions that are localized in space and scale, and oriented in specific directions. Applying the algorithm to different image sets produces basis functions that capture the intrinsic structures of the images, such as brushstrokes in paintings and edges in building photos.