Phase-resolved functional lung (PREFUL) MRI is a promising contrast agent-free 1H method to derive information about perfusion dynamics in free breathing. The analysis includes the segmentation of a main vessel to determine the perfusion phase for reconstruction of a full cardiac cycle. Since manual segmentation can be challenging and time-consuming, an algorithm for automated phase sorting is desirable. In this study such an algorithm is proposed, tested in 34 patients with CF and CTEPH and compared to manual phase sorting. The algorithm was able to perform segmentation in all cases and showed improved phase sorting compared to manual segmentation.