Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I blend two images together in GPUImage2 using Swift syntax

I am familiar with the following syntax to do single image filtering within GPUImage2 using something like this in Swift syntax:

input --> blur --> output

But how do I use an image processing operation that requires two images? One of the examples in GPUImage2 shows that you can do this:

input --> self.lookup1 --> self.alphaBlend --> self.lookup2 --> output
          self.lookup1 --> self.gaussianBlur --> self.alphaBlend

Where self.lookup1 and self.lookup2 are 2 different images. But I am unsure of this syntax, is the second image supposed to go after the alphaBlend filter in this case?

like image 674
dr_pepper Avatar asked Dec 24 '22 02:12

dr_pepper


1 Answers

Found that the above example I posted works by analyzing the chain and using the number of inputs required in the operation. So alphaBlend will wait to for another input to be applied, here is a working example:

      let alphaBlend = AlphaBlend()

      let input1 = PictureInput(image: image1)
      let input2 = PictureInput(image: image2)
      alphaBlend.mix = 0.5;

      let output = PictureOutput();
      output.encodedImageFormat = .JPEG

      output.imageAvailableCallback = {image in
        // Do something with the image
        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
      }

      input1 -->  alphaBlend
      input2 --> alphaBlend --> output

      input1.processImage(synchronously: true)
      input2.processImage(synchronously: true)
like image 136
dr_pepper Avatar answered May 15 '23 09:05

dr_pepper