title: iPhone iOS "face in the hole" kind of app, how to stitch two images together?
body: <p>I'm building a "face in the hole" or "photo booth" kind of app where the user's face can be inserted into an existing image using face detection technology. I'm getting the "cutout" <code>UIImage</code> face boundaries by using face detection. </p>
  
  <p>See the sharp boundary between the face and hair close to the guy's ear below. How can such transition be smoothed and blended together better? I know that there are apps that "expand" pictures, is there some kind of a well known algorithm I can use for this purpose?</p>
  
  <p><img src="https://i.stack.imgur.com/lM4Jp.jpg" alt="face detection example"></p>
  
  <p>My question is how to paste in the user's face into such an image? I was thinking of adding a transparent mask over the cutout's face (effectively cutting out a hole for the face), and substituting the user's face from a live camera feed from a view located behind the cutout.</p>
  
  <p>What concerns me is that this method would create sharp edges around the edge of the cut out face. How can I smooth this edge? Should my transparent mask rather than being pure alpha channel instead be an gradient with alpha channel of 1 in the middle and less on the outer edges? </p>
  
  <p><strong>How can I blend two images and make the boundary between them disappear or be a lot less noticeable?</strong> </p>