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.24k stars 4.61k forks source link

Blending an image with an effect, possible? #1209

Open Gucky opened 11 years ago

Gucky commented 11 years ago

Hi there!

I'm just wondering if something I have in mind is possible with GPUImage. I tried it for a couple of hours now but sadly did not reach my goal.

What I have in mind is applying a GPUImageVignetteFilter to an image but blending my image with the vignette with a GPUImageOverlayBlendFilter.

I can create a vignette and I can blend two images, so far I got. Vignette:

- (UIImage *)filter1:(UIImage *)input
{
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:[self baseImage]];

GPUImageVignetteFilter *vignetteFilter = [[GPUImageVignetteFilter alloc] init];

[stillImageSource addTarget:vignetteFilter];
[stillImageSource processImage];

return [vignetteFilter imageFromCurrentlyProcessedOutputWithOrientation:input.imageOrientation];
}

And blending on the other hand:

- (UIImage *)filter2:(UIImage *)input
{
GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:[self baseImage]];

GPUImageOverlayBlendFilter *overlayFilter = [[GPUImageOverlayBlendFilter alloc] init];

UIImage *inputImage = [UIImage imageNamed:@"second_image.jpg"];
GPUImagePicture *sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];
[sourcePicture processImage];
[sourcePicture addTarget:overlayFilter];

[stillImageSource addTarget:overlayFilter];
[stillImageSource processImage];

return [overlayFilter imageFromCurrentlyProcessedOutputWithOrientation:input.imageOrientation];
}

But instead of blending with the second image I would like to insert the vingette there. In other words, take Photoshop with an image layer and a vignette layer above (only the vignette on a transparent layer) and add them by a blend effect. The only insight I achieved is that the blending wants to have two images to work with but there seems to be no way to feed another effect to it. Am I missing something? Is there a technique for that? Any advice would be welcome!

LukasRos commented 11 years ago

Finding a solution for this would be really helpful. Hope someone has one!

BradLarson commented 11 years ago

I'm confused. Why can't you just blend you source image and your overlay image, then send the output through a vignette filter? That would apply the vignette to the final blended image.

Gucky commented 11 years ago

Ok, I guess I shoudn't have posted my two methods I want to combine somehow. That was confusing, yes.. Let's try it with a drawing: sketch As you can see, I don't have two real images, just one, the black-white gradient one. The second image is created on the fly by the VignetteFilter. This one is never really there, it is created and added directly to the output image when I tell my FilterGroup to process. So the left example where the VignetteFilter is just applied to the input image is easy to get. But my goal is to get to the result at the right side. There I have an input image and somewhere while processing the FilterGroup the vignette effect is created but instead of simply drawing this vignette on top of my input image I'd like to use an OverlayFilter (or any other blend filter). It is easy to use an OverlayFilter with two input images (see second code block in first post) but the vignette layer does not exist as an real image I could fed into the OverlayFilter. In Photoshop this is what I would do: bildschirmfoto 2013-09-26 um 23 30 43

I hope I could clarify my problem.

tspecht commented 11 years ago

did you trie a normal blend filter?

Gucky commented 11 years ago

Overlay- or Alpha- or Add-BlendFilter (I suppose you mean the AddBlendFilter with 'normal') does not make a difference. Those filters expect to get two images and not one image and one other filter. At least that's what I expect.