A method of imaging, comprising: capturing an image of a scene using an imaging device having a lens and an optical mask placed in front of said lens, said optical mask being selected to optically decompose said image into a plurality of channels, each being characterized by a different range of effective depth-of-field; and by means of a data processor: accessing a computer readable medium storing an in-focus dictionary defined over a plurality of dictionary atoms, and an out-of-focus dictionary defined over a plurality of sets of dictionary atoms, each set being a sub-dictionary of said out-of-focus dictionary and corresponding to a defocus parameter parameterizing a different depth-of-field, wherein each sub-dictionary of said out-of-focus dictionary is obtainable from said in-focus dictionary by convolution of said in-focus dictionary by a kernel function characterized by the respective defocus parameter; computing at least one sparse representation of said decomposed image over said out-of-focus dictionary, wherein said image is divided into a plurality of patches, and wherein said computing said sparse representation comprises expressing each patch as a combination of atoms of a sub-dictionary of said out-of-focus dictionary; and using said sparse representation for at least one of: (i) processing the image using coefficients of said combinations and the atoms of said in-focus dictionary; and (ii) extracting a value of said defocus parameter for each patch of said image that forms said sparse representation, and constructing a depth map of said scene, said depth map describing relative depths of different objects in the scene using the distribution of said values of said defocus parameter among said patches. capturing an image of a scene using an imaging device having a lens and an optical mask placed in front of said lens, said optical mask being selected to optically decompose said image into a plurality of channels, each being characterized by a different range of effective depth-of-field; and by means of a data processor: accessing a computer readable medium storing an in-focus dictionary defined over a plurality of dictionary atoms, and an out-of-focus dictionary defined over a plurality of sets of dictionary atoms, each set being a sub-dictionary of said out-of-focus dictionary and corresponding to a defocus parameter parameterizing a different depth-of-field, wherein each sub-dictionary of said out-of-focus dictionary is obtainable from said in-focus dictionary by convolution of said in-focus dictionary by a kernel function characterized by the respective defocus parameter; computing at least one sparse representation of said decomposed image over said out-of-focus dictionary, wherein said image is divided into a plurality of patches, and wherein said computing said sparse representation comprises expressing each patch as a combination of atoms of a sub-dictionary of said out-of-focus dictionary; and using said sparse representation for at least one of: (i) processing the image using coefficients of said combinations and the atoms of said in-focus dictionary; and (ii) extracting a value of said defocus parameter for each patch of said image that forms said sparse representation, and constructing a depth map of said scene, said depth map describing relative depths of different objects in the scene using the distribution of said values of said defocus parameter among said patches. accessing a computer readable medium storing an in-focus dictionary defined over a plurality of dictionary atoms, and an out-of-focus dictionary defined over a plurality of sets of dictionary atoms, each set being a sub-dictionary of said out-of-focus dictionary and corresponding to a defocus parameter parameterizing a different depth-of-field, wherein each sub-dictionary of said out-of-focus dictionary is obtainable from said in-focus dictionary by convolution of said in-focus dictionary by a kernel function characterized by the respective defocus parameter; computing at least one sparse representation of said decomposed image over said out-of-focus dictionary, wherein said image is divided into a plurality of patches, and wherein said computing said sparse representation comprises expressing each patch as a combination of atoms of a sub-dictionary of said out-of-focus dictionary; and using said sparse representation for at least one of: (i) processing the image using coefficients of said combinations and the atoms of said in-focus dictionary; and (ii) extracting a value of said defocus parameter for each patch of said image that forms said sparse representation, and constructing a depth map of said scene, said depth map describing relative depths of different objects in the scene using the distribution of said values of said defocus parameter among said patches. (i) processing the image using coefficients of said combinations and the atoms of said in-focus dictionary; and (ii) extracting a value of said defocus parameter for each patch of said image that forms said sparse representation, and constructing a depth map of said scene, said depth map describing relative depths of different objects in the scene using the distribution of said values of said defocus parameter among said patches.