This paper proposes a novel approach to recovering depth from defocus, which is a deterministic approach in spatial domain. Two defocused gray images from the same scene are obtained by changing two parameters (image distance and focal length of camera) other than only parameter (image distance). The idea of this approach is to convert the gray images into the gradient images by Canny operator other than Sobel operator, then calculate the ratio of the area of region with large gradient value to that of the whole image region in each block for each defocused image by moment-preserving method, and recover depth from scene according to the ratio of the ratio of one gradient image to that of the other gradient image. The experimental results show that the proposed approach is more accurate and efficient than the traditional approach