Capturing UIImage with GPUImageSketchFilter produces black and white image
Hey Brad - I'm trying out a few of your filters and I'm having some trouble with the GPUImageSketchFilter. I've modified the SimpleImageFilter example and replaced the default sepia filter with a sketch filter. I immediately capture a UIImage using:
UIImage *image = [sketchFilter imageFromCurrentlyProcessedOutput];
and writing it to the photos library using:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library writeImageToSavedPhotosAlbum:[image CGImage] metadata:nil completionBlock:nil];
It's a fairly basic example but I noticed that the image written is simply a black and white image. The preview of the image in the app properly has the "sketch" effect applied to it. I noticed this issue in a different app I was working on and wanted a simple example to demonstrate it.
Is saving an image this way not intended behavior? Should I be doing something different here to write out the filtered image?
Good catch. For a two-pass filter like the edge detection and sketch filters, I was writing the first pass to disk, not the end result. That should now be fixed in the repository.
Thanks for pointing this out.
Thanks Brad. Pulled in the changes and looks great.
Thanks again for putting together this library. My experience in image processing/filtering is non-existent and this has been a great experiment in learning.
Hi! Thanks for that great piece of software ;)! I find it very helpful, expecially for me: I don't know anything about elaborating images and I was asked to add some effects to photo sharing app.
I've some problem and I think it can be something similar to the one discussed in this thread.
I have a problem with Sketch effects (and TiltShift too): when I apply Sketch effect on preview image it works really well, but when I use it on full size image (and save image data to file) it seems like just half effects was applied.
For example with Sketch effetc I got image without too much contrast (eg. the edge aren't very "dark").
Do you have some insights?
Thanks!
William
That's really a different issue. The sketch filter is based on edge detection routines. These are calculated based on neighboring pixels, so when you have a preview at a lower resolution the effect will be performed over a larger effective area in the image than when you capture a high-res still photo. You can control this to some degree by setting the texelWidth and texelHeight parameters of the filter to be 1/width and 1/height of the image size you start with. This will keep the edge detection calculations relatively constant.
The tilt shift filter is a different case, in that it uses a Gaussian blur. That blur is calculated based on local pixels, and again if you increase the image resolution it is now blurring over a smaller relative radius. You could try increasing the blurSize scaling value, but you will quickly see banding in that. I don't really have a good way of maintaining a constant image processing quality for this filter between images of various resolutions.
Has anyone come up with a solution to the Tilt Shift preview and final output not look the same? I get a nice effect on the preview but the final captured image has a lot less effect to it.
@pednaa - This comment doesn't really have anything to do with this issue.
The reason for the difference in preview and photo appearance is that the Gaussian blur used for the out-of-focus section of the image is calculated based on neighboring pixels. The blur samples over a 9-pixel radius around each pixel, so for lower-resolution previews this blurs a larger region than in the high-resolution final image. You need to apply the blur over a larger number of pixels to achieve the same effect in the higher-resolution image.
Unfortunately, my blur filters are currently hardcoded to sample from a set number of pixels for performance reasons, and increasing the pixel spacing will introduce image artifacts. Multiple blur passes or a custom Gaussian blur that works over a larger radius would be needed here to achieve the same size of blur on a higher-resolution image.