title: What settings do I use to capture a RAW in iOS without noise reduction but otherwise looking identical to BGRA?
body: <p>We can either ask AVFoundation to capture a photo in a processed format like BGRA, or ask it to capture a RAW and then process it to BGRA using Core Image. The latter lets us control the <a href="https://developer.apple.com/documentation/coreimage/cifilter/raw_image_options" rel="nofollow noreferrer">parameters</a> used in the process rather than leaving it to the defaults iOS uses.</p>
  
  <p>In my case, I want to turn off noise-reduction, but otherwise have the image similar to BGRA. So I tried:</p>
  
  <pre><code>let rawData = AVCapturePhotoOutput.dngPhotoDataRepresentation(forRawSampleBuffer: self,
                                                                       previewPhotoSampleBuffer: nil)!
  let options: [AnyHashable : Any] = [
    kCIInputNoiseReductionAmountKey: 0.0,
    kCIInputLuminanceNoiseReductionAmountKey: 0.0,
    kCIInputColorNoiseReductionAmountKey: 0.0]
  
  let rawFilter = CIFilter(imageData: rawData, options: options)!
  let outputImage = rawFilter.outputImage!
  let context = CIContext()
  let cgImage = context.createCGImage(outputImage, from: outputImage.extent)!
  let uiImage = UIImage(cgImage: cgImage)
  let data = UIImageJPEGRepresentation(uiImage, jpegQuality)!
  // Save the data using PHPhotoLibrary
  </code></pre>
  
  <p>But this results in a RAW that looks much brighter...</p>
  
  <p><a href="https://i.stack.imgur.com/KWPCx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KWPCx.jpg" alt="enter image description here"></a></p>
  
  <p>... than the BGRA:</p>
  
  <p><a href="https://i.stack.imgur.com/TeNIU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TeNIU.jpg" alt="enter image description here"></a></p>
  
  <p>Right-click the photos and open in new tabs to see the difference.</p>
  
  <p>This is just one photo, as an example. I tested for many different scenes, and found that no matter what settings I tried, I couldn't match the quality of the JPEG — it was too bright, or too dark, or had too much contrast, etc.</p>
  
  <p>I then noticed that there's an input boost parameter with a default value of 1 for a full boost, so I set it to 0:</p>
  
  <pre><code>let options: [AnyHashable: Any] = [kCIInputBoostKey: 0.0]
  </code></pre>
  
  <p>But that produced a dull image without adequate contrast:</p>
  
  <p><a href="https://i.stack.imgur.com/bxp5s.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bxp5s.jpg" alt="enter image description here"></a></p>
  
  <p>So, the question is what settings should I use to have Core Image develop the RAW to BGRA with the same visual look as a BGRA captured by AVFoundation, except without noise reduction.</p>