title: Quartz : Getting the diff images of two images
body: <p>I've following two images the background may be totally different image, e.g. not just plain color.</p>
  
  <p><img src="https://i.stack.imgur.com/Ygsvt.png" alt="Image number one"> <img src="https://i.stack.imgur.com/ay5DB.png" alt="enter image description here"></p>
  
  <p>So basically I want to get the diff image of these two images i.e. </p>
  
  <p><img src="https://i.stack.imgur.com/VLRSs.png" alt="enter image description here"></p>
  
  <blockquote>
    <p>The diff image of two images is the image with the same size but the
    pixels are set to be transparent that haven't been changed. The difference image is constructed from the diff pixels with the color from the second image</p>
  </blockquote>
  
  <p>I'm looking for the solution based on Core Graphics techniques, please don't suggest to run all over the pixels in loop. I do care about the performance.</p>
  
  <p>As I'm new to Quartz I would like to know is it possible to achieve this with masks ? 
  Or please suggest another approach !</p>
  
  <p><strong>Update on using difference blending mode</strong>
  Actually if I use the difference blending mode it doesn't solve my problem as it doesn't keep right colors of the pixels. If I apply difference blend mode to above 2 images I'll get following  </p>
  
  <p><img src="https://i.stack.imgur.com/DVg02.png" alt="enter image description here"></p>
  
  <p>Which seems to have inverted colors for the pixels and then if I invert them I get following </p>
  
  <p><img src="https://i.stack.imgur.com/liZWg.png" alt="enter image description here"></p>
  
  <p>Which actually is not what I wanted, as the pixel colors are totally different </p>