Phase retrieval, image reconstruction, and segmentation