Silence-GitHub / BBMetalImage

A high performance Swift library for GPU-accelerated image/video processing based on Metal.
MIT License
988 stars 126 forks source link

ChromaKey filter on still image does not really work #36

Closed aminiz closed 4 years ago

aminiz commented 4 years ago

The following code returns a faded image, not one that has its green removed.

BBMetalChromaKeyFilter(thresholdSensitivity: 0.4, smoothing: 1.0, colorToReplace: .green).filteredImage(with: image)

Silence-GitHub commented 4 years ago

Version 1.1.1 fixes it.

aminiz commented 4 years ago

Thanks for the prompt response! Your change fixes the bug but I am seeing some quality difference between GPUImage2 and BBMetalImage.

I had a green-screen background and put the airpod case, key, and finger on top of it. Then I chromakeyed that image with both GPUImage2 (first image) and BBMetalImage (second image). The MacBook is just part of a different image.

I did not spend time fixing the orientation for the BBMetalImage so please ignore the orientation and aspect ratio issue.

Screen Shot 2020-05-12 at 8 23 40 AM Screen Shot 2020-05-12 at 8 25 46 AM

Silence-GitHub commented 4 years ago

Hi, I have a few questions for the bug.

Q1

Do you use this code ?

BBMetalChromaKeyFilter(thresholdSensitivity: 0.4, smoothing: 1.0, colorToReplace: .green)

smoothing is too high. Try to use default parameters.

BBMetalChromaKeyFilter()

Q2

How do you blend two images (Macbook image and chroma key image) ?

Q3

If the bug is not fixed, could you please show me the original image (green-screen background image)? I will use it to test.

aminiz commented 4 years ago

Q1: I get the same result with both.

Q2: I don't actually blend the images. I have an ImageView that shows the MacBook image. On top of that, I have another ImageView that shows the chromakey image.

Q3: Green screen image is attached. Screen Shot 2020-05-12 at 11 00 47 AM

Silence-GitHub commented 4 years ago

I test the green-screen background image in the demo project with iPhone 7 (iOS 13.3). Here are the results.

The original image.

IMG_1050

The chroma key image. I use the code BBMetalChromaKeyFilter()

IMG_1051

The chroma key image with sunflower image at the bottom.

IMG_1052

Are the expected results?

aminiz commented 4 years ago

Yes! I was able to get this result as well now. I had made a coding error where I was setting smoothness. Thanks for the help!