1. A method, comprising: selecting a plurality of reference pixels in a first image; associating with each reference pixel a respective pixel in a second image, the associating including: selecting a block of pixels surrounding the reference pixel; selecting a plurality of candidate pixels in the second image; for each candidate pixel in the second image, selecting a block of pixels surrounding the candidate pixel, said block of pixels surrounding the candidate pixel having a same dimension as said block of pixels surrounding the reference pixel; identifying a subset of pixels in at least one of the block of pixels surrounding the reference pixel and the block of pixels surrounding the candidate pixel, the identifying the subset of pixels including identifying pixels in the block of pixels surrounding the reference pixel which have similar values as corresponding pixels in the block of pixels surrounding the candidate pixel; and determining a cost associated with the candidate pixel based on the identified subset of pixels; and selecting a subset of the candidate pixels based on the determined costs; determining a disparity between each reference pixel and the respective pixel in said second image; determining for each reference pixel a depth value as a function of the respective disparity; and generating a depth map based on the determined depth values.