Phass-shifted shadow Moire has gained more applications in electronic industry. However, printed circuit boards (PCB) may contain many cavities or specular materials on the surface that make the phase-unwrapping of Moire fringe patterns more difficult or fail. In this paper, a method is proposed to overcome this difficulty to process the phase-shifted fringe patterns effectively and automatically for surface profile measurement. Firstly the intensity values of the original four phase-shifted fringe patterns are averaged and differentiated to enhance the erroneous spots. Then the median grey-level value of the enhanced image is used as the threshold to binarize the enhanced image to find the erroneous bright and black spots. According to the largest size of erroneous spot, the size of a structuring element is determined for morphology filtering. Thereafter the phase can be calculated and unwrapped correctly. Test of the method on a PCB is demonstrated and discussed.