iOS 5 支持模糊 CoreImage 滤镜吗?

发布于 2024-12-21 09:29:59 字数 1436 浏览 2 评论 0原文

根据文档,它应该支持模糊,请注意“在 iOS 5.0 及更高版本中可用”:

CIFilter 类参考

但根据设备,它不:

[CIFilter filterNamesInCategory:kCICategoryBlur];

不返回任何内容。

根据以下内容,只有这些过滤器在我的 iPhone 和模拟器(都运行 5.0)上可用:

[CIFilter filterNamesInCategory:kCICategoryBuiltIn]

CIAdditionCompositing,
CIAffineTransform,
CICheckerboardGenerator,
CIColorBlendMode,
CIColorBurnBlendMode,
CIColorControls,
CIColorCube,
CIColorDodgeBlendMode,
CIColorInvert,
CIColorMatrix,
CIColorMonochrome,
CIConstantColorGenerator,
CICrop,
CIDarkenBlendMode,
CIDifferenceBlendMode,
CIExclusionBlendMode,
CIExposureAdjust,
CIFalseColor,
CIGammaAdjust,
CIGaussianGradient,
CIHardLightBlendMode,
CIHighlightShadowAdjust,
CIHueAdjust,
CIHueBlendMode,
CILightenBlendMode,
CILinearGradient,
CILuminosityBlendMode,
CIMaximumCompositing,
CIMinimumCompositing,
CIMultiplyBlendMode,
CIMultiplyCompositing,
CIOverlayBlendMode,
CIRadialGradient,
CISaturationBlendMode,
CIScreenBlendMode,
CISepiaTone,
CISoftLightBlendMode,
CISourceAtopCompositing,
CISourceInCompositing,
CISourceOutCompositing,
CISourceOverCompositing,
CIStraightenFilter,
CIStripesGenerator,
CITemperatureAndTint,
CIToneCurve,
CIVibrance,
CIVignette,
CIWhitePointAdjust

According to the documentation it should support blurring, note the "Available in iOS 5.0 and later":

CIFilter Class Reference

But according to the device, it doesn't:

[CIFilter filterNamesInCategory:kCICategoryBlur];

returns nothing.

According to the following only these filters are available on my iPhone and Simulator (which are both running 5.0):

[CIFilter filterNamesInCategory:kCICategoryBuiltIn]

CIAdditionCompositing,
CIAffineTransform,
CICheckerboardGenerator,
CIColorBlendMode,
CIColorBurnBlendMode,
CIColorControls,
CIColorCube,
CIColorDodgeBlendMode,
CIColorInvert,
CIColorMatrix,
CIColorMonochrome,
CIConstantColorGenerator,
CICrop,
CIDarkenBlendMode,
CIDifferenceBlendMode,
CIExclusionBlendMode,
CIExposureAdjust,
CIFalseColor,
CIGammaAdjust,
CIGaussianGradient,
CIHardLightBlendMode,
CIHighlightShadowAdjust,
CIHueAdjust,
CIHueBlendMode,
CILightenBlendMode,
CILinearGradient,
CILuminosityBlendMode,
CIMaximumCompositing,
CIMinimumCompositing,
CIMultiplyBlendMode,
CIMultiplyCompositing,
CIOverlayBlendMode,
CIRadialGradient,
CISaturationBlendMode,
CIScreenBlendMode,
CISepiaTone,
CISoftLightBlendMode,
CISourceAtopCompositing,
CISourceInCompositing,
CISourceOutCompositing,
CISourceOverCompositing,
CIStraightenFilter,
CIStripesGenerator,
CITemperatureAndTint,
CIToneCurve,
CIVibrance,
CIVignette,
CIWhitePointAdjust

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

无畏 2024-12-28 09:29:59

虽然 iOS 5.0 上的 Core Image 缺少模糊滤镜,但仍有一种方法可以实现 GPU 加速的图像和视频模糊。我的开源 GPUImage 框架有多种模糊类型,包括高斯(使用 GPUImageGaussianBlurFilter 进行一般高斯或用于硬件优化的 9 命中高斯的 GPUImageFastBlurFilter)、框(使用 GPUImageBoxBlurFilter)、中值(使用GPUImageMedianFilter)和双边模糊(使用 GPUImageBilingualBlurFilter)。

我在这个答案中描述了用于实现硬件优化高斯模糊的着色器,您可以检查我使用的代码框架内的其余部分。这些过滤器的运行速度比我尝试过的任何受 CPU 限制的例程快数十倍。

我还将这些模糊合并到多级处理效果中,例如锐化掩蔽、倾斜移位过滤、Canny 边缘检测和 Harris 角点检测,所有这些都可以用作此框架中的过滤器。

While Core Image on iOS 5.0 lacks blur filters, there is still a way to get GPU-accelerated blurs of images and video. My open source GPUImage framework has multiple blur types, including Gaussian (using the GPUImageGaussianBlurFilter for a general Gaussian or the GPUImageFastBlurFilter for a hardware-optimized 9-hit Gaussian), box (using a GPUImageBoxBlurFilter), median (using a GPUImageMedianFilter), and a bilateral blur (using a GPUImageBilateralBlurFilter).

I describe the shaders used to pull off the hardware-optimized Gaussian blur in this answer, and you can examine the code I use for the rest within the framework. These filters run tens of times faster than any CPU-bound routine I've tried yet.

I've also incorporated these blurs into multi-stage processing effects, like unsharp masking, tilt-shift filtering, Canny edge detection, and Harris corner detection, all of which are available as filters within this framework.

空城之時有危險 2024-12-28 09:29:59

再次,为了拯救所有 iOS 模糊问题,这是我的贡献:

https://github.com/tomsoft1/ StackBluriOS

一个基于Stack Blur的简单模糊库。堆栈模糊与高斯模糊非常相似,但速度更快(请参阅 http://incubator.quasimondo.com /processing/fast_blur_deluxe.php

像这样使用它:

UIImage *newIma=[sourceIma stackBlur:radius]

希望这有帮助

Again, in an attempt to save all iOS blur isses, here is my contribution:

https://github.com/tomsoft1/StackBluriOS

A simple blur library based on Stack Blur. Stack Blur is very similar to Gaussian Blur, but much faster (see http://incubator.quasimondo.com/processing/fast_blur_deluxe.php )

use it like this:

UIImage *newIma=[sourceIma stackBlur:radius]

Hope this help

英雄似剑 2024-12-28 09:29:59

我也很失望地发现 iOS 中的 Core Image 不支持模糊。这是我编写的用于在 UIImage 上执行 9-tap 高斯模糊的函数。反复调用以获得更强的模糊效果。

@interface UIImage (ImageBlur)
- (UIImage *)imageWithGaussianBlur9;
@end

@implementation UIImage (ImageBlur)
- (UIImage *)imageWithGaussianBlur9 {
    float weight[5] = {0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162};
    // Blur horizontally
    UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
    [self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[0]];
    for (int x = 1; x < 5; ++x) {
        [self drawInRect:CGRectMake(x, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[x]];
        [self drawInRect:CGRectMake(-x, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[x]];
    }
    UIImage *horizBlurredImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    // Blur vertically
    UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
    [horizBlurredImage drawInRect:CGRectMake(0, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[0]];
    for (int y = 1; y < 5; ++y) {
        [horizBlurredImage drawInRect:CGRectMake(0, y, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[y]];
        [horizBlurredImage drawInRect:CGRectMake(0, -y, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[y]];
    }
    UIImage *blurredImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    //
    return blurredImage;
}

只需在现有图像上调用它,如下所示:

UIImage *blurredImage = [originalImage imageWithGaussianBlur9];

并重复它以获得更强的模糊效果,如下所示:

blurredImage = [blurredImage imageWithGaussianBlur9];

I too was disappointed to find that Core Image in iOS doesn't support blurs. Here's the function I wrote to do a 9-tap Gaussian blur on a UIImage. Call it repeatedly to get stronger blurs.

@interface UIImage (ImageBlur)
- (UIImage *)imageWithGaussianBlur9;
@end

@implementation UIImage (ImageBlur)
- (UIImage *)imageWithGaussianBlur9 {
    float weight[5] = {0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162};
    // Blur horizontally
    UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
    [self drawInRect:CGRectMake(0, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[0]];
    for (int x = 1; x < 5; ++x) {
        [self drawInRect:CGRectMake(x, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[x]];
        [self drawInRect:CGRectMake(-x, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[x]];
    }
    UIImage *horizBlurredImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    // Blur vertically
    UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
    [horizBlurredImage drawInRect:CGRectMake(0, 0, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[0]];
    for (int y = 1; y < 5; ++y) {
        [horizBlurredImage drawInRect:CGRectMake(0, y, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[y]];
        [horizBlurredImage drawInRect:CGRectMake(0, -y, self.size.width, self.size.height) blendMode:kCGBlendModePlusLighter alpha:weight[y]];
    }
    UIImage *blurredImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    //
    return blurredImage;
}

Just call it on an existing image like this:

UIImage *blurredImage = [originalImage imageWithGaussianBlur9];

and repeat it to get stronger blurring, like this:

blurredImage = [blurredImage imageWithGaussianBlur9];
是伱的 2024-12-28 09:29:59

不幸的是,它不支持任何模糊。为此,您必须自己推出。

Unfortunately, it does not support any blurs. For that, you'll have to roll your own.

鹿港巷口少年归 2024-12-28 09:29:59

更新:从 iOS 6 开始,[CIFilter filterNamesInCategory:kCICategoryBlur]; 返回 CIGaussianBlur 意味着该过滤器在设备上可用。尽管这是事实,但使用 GPUImage 您(可能)将获得更好的性能和更大的灵活性。

UPDATE: As of iOS 6 [CIFilter filterNamesInCategory:kCICategoryBlur]; returns CIGaussianBlur meaning that this filter is available on the device. Even though this is true, you (probably) will get better performance and more flexibility using GPUImage.

清晰传感 2024-12-28 09:29:59

这是我们使用不同方法在 iOS 应用程序中制作模糊效果的教程的链接。 http://blog. denivip.ru/index.php/2013/01/blur-effect-in-ios-applications/?lang=en

Here is the link to our tutorial on making blur effect in iOS application with different approaches. http://blog.denivip.ru/index.php/2013/01/blur-effect-in-ios-applications/?lang=en

自由范儿 2024-12-28 09:29:59

如果您可以在 iOS 应用程序中使用 OpenGL ES,则可以通过以下方式计算您选择的像素邻域半径的​​中值(当然,中值是一种模糊类型):

kernel vec4 medianUnsharpKernel(sampler u) {
vec4 pixel = unpremultiply(sample(u, samplerCoord(u)));
vec2 xy = destCoord();
int radius = 3;
int bounds = (radius - 1) / 2;
vec4 sum  = vec4(0.0);
for (int i = (0 - bounds); i <= bounds; i++)
{
    for (int j = (0 - bounds); j <= bounds; j++ )
    {
        sum += unpremultiply(sample(u, samplerTransform(u, vec2(xy + vec2(i, j)))));
    }
}
vec4 mean = vec4(sum / vec4(pow(float(radius), 2.0)));
float mean_avg = float(mean);
float comp_avg = 0.0;
vec4 comp  = vec4(0.0);
vec4 median  = mean;
for (int i = (0 - bounds); i <= bounds; i++)
{
    for (int j = (0 - bounds); j <= bounds; j++ )
    {
        comp = unpremultiply(sample(u, samplerTransform(u, vec2(xy + vec2(i, j)))));
        comp_avg = float(comp);
        median = (comp_avg < mean_avg) ? max(median, comp) : median;
    }
}

return premultiply(vec4(vec3(abs(pixel.rgb - median.rgb)), 1.0)); 
}

步骤的简要说明
1. 计算3x3邻域内源像素周围像素值的平均值;
2. 找出同一邻域内所有像素中小于平均值的最大像素值。
3. [可选] 从源像素值中减去中值像素值以进行边缘检测。

如果您使用中值进行边缘检测,有几种方法可以修改上述代码以获得更好的结果,即混合中值过滤和截断媒体过滤(替代和更好的“模式”过滤)。如果您有兴趣,请询问。

If you can use OpenGL ES in your iOS app, this is how you calculate the median in a pixel neighborhood radius of your choosing (the median being a type of blur, of course):

kernel vec4 medianUnsharpKernel(sampler u) {
vec4 pixel = unpremultiply(sample(u, samplerCoord(u)));
vec2 xy = destCoord();
int radius = 3;
int bounds = (radius - 1) / 2;
vec4 sum  = vec4(0.0);
for (int i = (0 - bounds); i <= bounds; i++)
{
    for (int j = (0 - bounds); j <= bounds; j++ )
    {
        sum += unpremultiply(sample(u, samplerTransform(u, vec2(xy + vec2(i, j)))));
    }
}
vec4 mean = vec4(sum / vec4(pow(float(radius), 2.0)));
float mean_avg = float(mean);
float comp_avg = 0.0;
vec4 comp  = vec4(0.0);
vec4 median  = mean;
for (int i = (0 - bounds); i <= bounds; i++)
{
    for (int j = (0 - bounds); j <= bounds; j++ )
    {
        comp = unpremultiply(sample(u, samplerTransform(u, vec2(xy + vec2(i, j)))));
        comp_avg = float(comp);
        median = (comp_avg < mean_avg) ? max(median, comp) : median;
    }
}

return premultiply(vec4(vec3(abs(pixel.rgb - median.rgb)), 1.0)); 
}

A brief description of the steps
1. Calculate the mean of the values of the pixels surrounding the source pixel in a 3x3 neighborhood;
2. Find the maximum pixel value of all pixels in the same neighborhood that are less than the mean.
3. [OPTIONAL] Subtract the median pixel value from the source pixel value for edge detection.

If you're using the median value for edge detection, there are a couple of ways to modify the above code for better results, namely, hybrid median filtering and truncated media filtering (a substitute and a better 'mode' filtering). If you're interested, please ask.

沉溺在你眼里的海 2024-12-28 09:29:59

因为我使用的是 Xamarin,所以我将 John Stephen 的答案转换为 C#:

    private UIImage ImageWithGaussianBlur9(UIImage image)
    {
        var weight = new nfloat[]
        {
            0.2270270270f, 0.1945945946f, 0.1216216216f, 0.0540540541f, 0.0162162162f
        };

        var width = image.Size.Width;
        var height = image.Size.Height;
        // Blur horizontally
        UIGraphics.BeginImageContextWithOptions(image.Size, false, 1f);

        image.Draw(new CGRect(0f, 0f, width, height), CGBlendMode.PlusLighter, weight[0]);

        for (int x = 1; x < 5; ++x)
        {
            image.Draw(new CGRect(x, 0, width, height), CGBlendMode.PlusLighter, weight[x]);
            image.Draw(new CGRect(-x, 0, width, height), CGBlendMode.PlusLighter, weight[x]);
        }

        var horizBlurredImage = UIGraphics.GetImageFromCurrentImageContext();
        UIGraphics.EndImageContext();

        // Blur vertically
        UIGraphics.BeginImageContextWithOptions(image.Size, false, 1f);

        horizBlurredImage.Draw(new CGRect(0, 0, width, height), CGBlendMode.PlusLighter, weight[0]);

        for (int y = 1; y < 5; ++y)
        {
            horizBlurredImage.Draw(new CGRect(0, y, width, height), CGBlendMode.PlusLighter, weight[y]);
            horizBlurredImage.Draw(new CGRect(0, -y, width, height), CGBlendMode.PlusLighter, weight[y]);
        }

        var blurredImage = UIGraphics.GetImageFromCurrentImageContext();
        UIGraphics.EndImageContext();

        return blurredImage;
    }

Because I'm using Xamarin, I converted John Stephen's answer to C#:

    private UIImage ImageWithGaussianBlur9(UIImage image)
    {
        var weight = new nfloat[]
        {
            0.2270270270f, 0.1945945946f, 0.1216216216f, 0.0540540541f, 0.0162162162f
        };

        var width = image.Size.Width;
        var height = image.Size.Height;
        // Blur horizontally
        UIGraphics.BeginImageContextWithOptions(image.Size, false, 1f);

        image.Draw(new CGRect(0f, 0f, width, height), CGBlendMode.PlusLighter, weight[0]);

        for (int x = 1; x < 5; ++x)
        {
            image.Draw(new CGRect(x, 0, width, height), CGBlendMode.PlusLighter, weight[x]);
            image.Draw(new CGRect(-x, 0, width, height), CGBlendMode.PlusLighter, weight[x]);
        }

        var horizBlurredImage = UIGraphics.GetImageFromCurrentImageContext();
        UIGraphics.EndImageContext();

        // Blur vertically
        UIGraphics.BeginImageContextWithOptions(image.Size, false, 1f);

        horizBlurredImage.Draw(new CGRect(0, 0, width, height), CGBlendMode.PlusLighter, weight[0]);

        for (int y = 1; y < 5; ++y)
        {
            horizBlurredImage.Draw(new CGRect(0, y, width, height), CGBlendMode.PlusLighter, weight[y]);
            horizBlurredImage.Draw(new CGRect(0, -y, width, height), CGBlendMode.PlusLighter, weight[y]);
        }

        var blurredImage = UIGraphics.GetImageFromCurrentImageContext();
        UIGraphics.EndImageContext();

        return blurredImage;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文