title: Removing a colour from a UIImage
body: <p>I have an image:</p>
  
  <p><a href="https://i.stack.imgur.com/CQwHl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CQwHl.png" alt="enter image description here"></a></p>
  
  <p>As you can clearly see, the barcode doesn't fit in very well with the UI :/</p>
  
  <p>I thought a potential fix for this, was to "green screen" out the black in the image, leaving on the white part of the barcode.</p>
  
  <p>The barcode itself is generated on the fly.</p>
  
  <pre><code>func generateBarcode(from string: String) -&gt; UIImage? {
          let data = string.data(using: String.Encoding.ascii)
  
          if let filter = CIFilter(name: "CICode128BarcodeGenerator") {
              filter.setValue(data, forKey: "inputMessage")
  
              let transform = CGAffineTransform(scaleX: 3, y: 3)
  
              if let output = filter.outputImage?.applying(transform) {
                  let invertFiler = CIFilter(name: "CIColorInvert")!
                  invertFiler.setValue(output, forKey: kCIInputImageKey)
  
                  return UIImage(ciImage: (invertFiler.outputImage?.applying(transform))!) //TODO: Remove force unwrap
              }
          }
          return nil
      }
  </code></pre>
  
  <p>Now I've heard I can use a "CIColorCube" filter but haven't been able to work out to use it.</p>
  
  <p>Is removing the black part possible? And, if so, would you be able to help me out?</p>
  
  <p>Thanks</p>