BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.2k stars 4.61k forks source link

GPUImageChromaKeyBlendFilter doesn't work with replacing black/grey on an image with white #2589

Open Pranoy1c opened 5 years ago

Pranoy1c commented 5 years ago

I am trying to replace the black/dark gray with a pure black image in this image using GPUImageChromaKeyBlendFilter but it seems to be replacing the whites too:

photo 2018-07-20 2 57 28 am

photo 2018-07-20 2 57 36 am

Here's my code:

stillImageSource = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"head.jpg"]];
    blackImageSource = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:@"black.jpg"]];

    filter = [[GPUImageChromaKeyBlendFilter alloc] init];

     [(GPUImageChromaKeyBlendFilter *)filter setColorToReplaceRed:0.27 green:1.0 blue:1.0];
    [(GPUImageChromaKeyBlendFilter *)filter setThresholdSensitivity:self.myslider.value];

    [stillImageSource addTarget:filter];
    [blackImageSource addTarget:filter];

    [filter addTarget:self.mygpuimageview];
    [stillImageSource processImage];
    [blackImageSource processImage];

How can I make this work?

I notice in this post, you mention the issue is due to removing luminance: https://github.com/BradLarson/GPUImage/issues/2256

Is there a way to keep luminance in account too when keying?