1. A method for editing an input image to produce an output image, comprising a processor for performing steps of the method, comprising the steps: partitioning pixels of the input image into sets of pixels, wherein the pixels in each set are adjacent, and for each set of pixels, further comprising the steps of: defining a trellis having nodes connected by directed links, wherein each node corresponds to one of the pixels in the set of pixels, and each node is associated with an action and location of the pixel in the output image; assigning costs to the nodes and the links; determining a path through the trellis, wherein the path has a least cost; and applying, for each node on the path, the action associated the node to the corresponding pixel in the input image to edit the corresponding pixel at the location in the output image associated with the node.