A method for generating an image from a plurality of images, each of the plurality of images having been captured at a different focus distance and having a unique index, the method comprising: registering each of the plurality of images relative to one another; generating , from each of the registered images, a high frequency frame, each high frequency frame being representative of the high frequency content of the corresponding image and having an index corresponding to the index of the respective image; determining , for each of a plurality of regions in each of the high frequency frames, whether or not the high frequency content in that region is valid; for each of the plurality of regions, determining the index of the high frequency frame having the greatest valid high frequency content among the plurality of high frequency frames; and generating a final image comprising, for each of the plurality of regions, the image data from the one of the plurality of images having the index corresponding to the index of the high frequency frame having the greatest valid high frequency content in that region, wherein determining whether or not the high frequency content in a region is valid comprises: comparing the high frequency content of the region to a predetermined validity threshold, and considering the high frequency content of the region to be invalid if it is below the predetermined validity threshold; comparing the high frequency content of the region with the local maximum high frequency content of regions within a neighborhood surrounding the region and considering the high frequency content of the region to be invalid if it is not above a threshold value based on the local maximum high frequency content within the neighborhood surrounding the region, the neighborhood surrounding the region optionally comprising regions within the frame and within adjacent frames of the region. registering each of the plurality of images relative to one another; generating , from each of the registered images, a high frequency frame, each high frequency frame being representative of the high frequency content of the corresponding image and having an index corresponding to the index of the respective image; determining , for each of a plurality of regions in each of the high frequency frames, whether or not the high frequency content in that region is valid; for each of the plurality of regions, determining the index of the high frequency frame having the greatest valid high frequency content among the plurality of high frequency frames; and generating a final image comprising, for each of the plurality of regions, the image data from the one of the plurality of images having the index corresponding to the index of the high frequency frame having the greatest valid high frequency content in that region, wherein determining whether or not the high frequency content in a region is valid comprises: comparing the high frequency content of the region to a predetermined validity threshold, and considering the high frequency content of the region to be invalid if it is below the predetermined validity threshold; comparing the high frequency content of the region with the local maximum high frequency content of regions within a neighborhood surrounding the region and considering the high frequency content of the region to be invalid if it is not above a threshold value based on the local maximum high frequency content within the neighborhood surrounding the region, the neighborhood surrounding the region optionally comprising regions within the frame and within adjacent frames of the region. <EOS>