A method for calculating a height map of a surface of an object from an image stack in scanning optical 2.5D profiling of the surface by an optical system, the method comprising: scanning a focal plane at different height positions with respect to the object surface; capturing an image at each height position of the focal plane to form the image stack, wherein the scanning of the focal plane comprises: - long range sensing a displacement of the focal plane for sensing low spatial frequency motion or displacement, wherein the long range sensing comprises optical, mechanical or capacitive encoding; - short range sensing a displacement of the focal plane for sensing high spatial frequency motion or displacement, wherein the short range sensing comprises sensing vibrations, and wherein the short range sensing differs from the long range sensing; - filtering a measurement from the long range sensing to remove high spatial frequency motion or displacement, and/or filtering a measurement from the short range sensing to remove low spatial frequency motion or displacement; and - estimating the height position of the focal plane by combining the low spatial frequency motion or displacement and the high spatial frequency motion or displacement, wherein the method further comprises: calculating a height position of each image in the image stack, based on the estimated height position of each respective focal plane; interpolating the images of the image stack to equidistant height positions for obtaining a corrected image stack; and calculating the height map of the surface of the object from the corrected image stack. scanning a focal plane at different height positions with respect to the object surface; capturing an image at each height position of the focal plane to form the image stack, wherein the scanning of the focal plane comprises: - long range sensing a displacement of the focal plane for sensing low spatial frequency motion or displacement, wherein the long range sensing comprises optical, mechanical or capacitive encoding; - short range sensing a displacement of the focal plane for sensing high spatial frequency motion or displacement, wherein the short range sensing comprises sensing vibrations, and wherein the short range sensing differs from the long range sensing; - filtering a measurement from the long range sensing to remove high spatial frequency motion or displacement, and/or filtering a measurement from the short range sensing to remove low spatial frequency motion or displacement; and - estimating the height position of the focal plane by combining the low spatial frequency motion or displacement and the high spatial frequency motion or displacement, wherein the method further comprises: calculating a height position of each image in the image stack, based on the estimated height position of each respective focal plane; interpolating the images of the image stack to equidistant height positions for obtaining a corrected image stack; and calculating the height map of the surface of the object from the corrected image stack. - long range sensing a displacement of the focal plane for sensing low spatial frequency motion or displacement, wherein the long range sensing comprises optical, mechanical or capacitive encoding; - short range sensing a displacement of the focal plane for sensing high spatial frequency motion or displacement, wherein the short range sensing comprises sensing vibrations, and wherein the short range sensing differs from the long range sensing; - filtering a measurement from the long range sensing to remove high spatial frequency motion or displacement, and/or filtering a measurement from the short range sensing to remove low spatial frequency motion or displacement; and - estimating the height position of the focal plane by combining the low spatial frequency motion or displacement and the high spatial frequency motion or displacement, wherein the method further comprises: calculating a height position of each image in the image stack, based on the estimated height position of each respective focal plane; interpolating the images of the image stack to equidistant height positions for obtaining a corrected image stack; and calculating the height map of the surface of the object from the corrected image stack. calculating a height position of each image in the image stack, based on the estimated height position of each respective focal plane; interpolating the images of the image stack to equidistant height positions for obtaining a corrected image stack; and calculating the height map of the surface of the object from the corrected image stack.