An improved Stoilov algorithm was proposed based on statistical approach, which can remove singularities and large errors to improve measure precision. The optical element defect detection model was constructed by fitting the surface of optical element as well as reconstructing the surface of defect element. The defect on an optical flat was detected with this method and model. The measured depth of scratch is 40 nm.