An optical system (200, 300) for capturing images of a three-dimensional object (206, 318), the optical system (200, 300) comprising a projector for structured illumination of the object (206, 318), wherein the projector comprises: a light source, a grid mask (210, 304) positioned between the light source and the object (206, 318) for structured illumination of the object (206, 318), characterized by a first element (208, 308) having a phase modulating mask positioned between the grid mask (210, 304) and the object (206, 318) to receive patterned light from the light source through the grid mask (210, 304), wherein the first element (208, 308) is constructed and arranged such that a point spread function of the projector is substantially invariant over a wider range of depth of field of the grid mask (210, 304) than a point spread function of the projector without the first element (208, 308), wherein the optical system (200, 300) further comprises a detector (204, 316) for detecting the object (206, 318) with structured illumination from the projector, a second-element (214, 314) having a second phase modulating mask located between the object (206, 318) and the detector (204, 316) such that a first image of the object (206, 318) and a second image of the grid mask (210, 304) on the detector (204, 316) have a larger depth of field than without the second element (214, 314), wherein each of the first element (208, 308) and second element (214, 314) comprises a circularly symmetric element, and/or each of the first (208, 308) and second (214, 314) elements comprises a weakly non-separable function wherein especially the weakly non-separable function for the first element (208, 308) is expressed as P x y = ∑ i N ∑ j N α i x i + β j y j + γx i y i, the weakly non-separable function for the second element (214, 314) is expressed as P(X',Y') = ∑ i N ∑ j N α i − X ′ i + β j − Y ′ j + γ − X ′ i − Y ′ j, i and j are positive integers, wherein Y' axis is in the same direction as y axis, Z' axis is in the same direction as x axis, and X' axis is in the opposite direction of z axis. a light source, a grid mask (210, 304) positioned between the light source and the object (206, 318) for structured illumination of the object (206, 318), characterized by a first element (208, 308) having a phase modulating mask positioned between the grid mask (210, 304) and the object (206, 318) to receive patterned light from the light source through the grid mask (210, 304), wherein the first element (208, 308) is constructed and arranged such that a point spread function of the projector is substantially invariant over a wider range of depth of field of the grid mask (210, 304) than a point spread function of the projector without the first element (208, 308), wherein the optical system (200, 300) further comprises a detector (204, 316) for detecting the object (206, 318) with structured illumination from the projector, a second-element (214, 314) having a second phase modulating mask located between the object (206, 318) and the detector (204, 316) such that a first image of the object (206, 318) and a second image of the grid mask (210, 304) on the detector (204, 316) have a larger depth of field than without the second element (214, 314), wherein each of the first element (208, 308) and second element (214, 314) comprises a circularly symmetric element, and/or each of the first (208, 308) and second (214, 314) elements comprises a weakly non-separable function wherein especially the weakly non-separable function for the first element (208, 308) is expressed as P x y = ∑ i N ∑ j N α i x i + β j y j + γx i y i, the weakly non-separable function for the second element (214, 314) is expressed as P(X',Y') = ∑ i N ∑ j N α i − X ′ i + β j − Y ′ j + γ − X ′ i − Y ′ j, i and j are positive integers, wherein Y' axis is in the same direction as y axis, Z' axis is in the same direction as x axis, and X' axis is in the opposite direction of z axis.