1. A method implemented by one or more computing devices to edit a target image, the method comprising: selecting, for each respective pixel of a plurality of pixels comprising the target image, a respective mask from a plurality of masks, wherein at least some selected masks are different for different respective pixels; applying each respective selected mask to a source patch corresponding to the respective selected mask to down-weight portions of the corresponding source patch having irrelevant content and to define portions of the corresponding source patch to be included in computations of a target patch; computing a target patch based, at least in part, on the plurality of pixels comprising the target image and the defined portions of corresponding source patches to be included in computations of the target patch, the computing including using a distance function to weight a distance between pixels of the source patch and pixels of the target patch by: subtracting a location of a respective pixel of the pixels of the source patch from a location of a respective pixel of the pixels of the target patch; squaring a difference determined by the subtracting; and multiplying the squared difference by a mask value; and editing the target image by including the target patch as part of the target image, wherein the target patch corresponds to a segment of the target image, the segment including a foreground segment and a background segment.