Fringe projection profilometry is widely used in 3D structured light due to its fast speed and accuracy. However, in the process of phase unwrapping, it is easy to cause invalid points in the edges and shadows of objects, which leads to error points in 3D reconstruction. To solve this problem, we propose an invalid points removal method based on Markov random fields. Specifically, the proposed method formulates unwrapped phase and mask maps as energy functions and uses iterative methods to minimize them. Furthermore, we validate the proposed method in a monocular structured light system and compare it with existing algorithms. Results show that the proposed method effectively identifies edges and shadows while preserving valid points, and has strong robustness and correctness.