Segmentation Circuits Using Constrained Optimization