title: Getting black and white image after applying mask
body: <p>I am removing background from image containing at least one human body. I am applying mask to UIImage and successfully masked image containing only human body with transparent background, but if I tried to convert to UIImage back after applying mask I am getting black and white cropped image. </p>
  
  <p>I am using this snippet to apply mask and get result as UIImage</p>
  
  <pre class="lang-swift prettyprint-override"><code>func maskImage(image:UIImage, mask:(UIImage))-&gt;UIImage{
  
          let imageReference = image.cgImage
          let maskReference = mask.cgImage
  
          let imageMask = CGImage(maskWidth: maskReference!.width,
                                  height: maskReference!.height,
                                  bitsPerComponent: maskReference!.bitsPerComponent,
                                  bitsPerPixel: maskReference!.bitsPerPixel,
                                  bytesPerRow: maskReference!.bytesPerRow,
                                  provider: maskReference!.dataProvider!, decode: nil, shouldInterpolate: true)
  
          let maskedReference = imageReference!.masking(imageMask!)
  
          let maskedImage = UIImage(cgImage:maskedReference!)
  
          return maskedImage
      }
  
  </code></pre>
  
  <p>but I am getting black and white image with only human body instead of coloured.</p>