ios - 高斯模糊的白边问题
迷茫
迷茫 2017-04-17 14:58:19
[iOS讨论组]

以下是我写高斯模糊的代码

- (UIImage *)blureImage:(UIImage *)originImage withInputRadius:(CGFloat)inputRadius
{
    CIContext *context = [CIContext contextWithOptions:nil];
    CIImage *image = [CIImage imageWithCGImage:originImage.CGImage];
    CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
    [filter setValue:image forKey:kCIInputImageKey];
    [filter setValue:@(inputRadius) forKey: @"inputRadius"];
    CIImage *result = [filter valueForKey:kCIOutputImageKey];
    CGImageRef outImage = [context createCGImage: result fromRect:[result extent]];
    UIImage * blurImage = [UIImage imageWithCGImage:outImage];
    return blurImage;
}

如图所示,图片周围会有一圈虚化的白边,这是高斯模糊的正常效果吗,我该如何去掉这个白边?

原图在这里

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

全部回复(5)
伊谢尔伦

前几天我也遇过这个问题,你试一下改变fromRect...
CGRect extent = CGRectInset(filter.outputImage.extent, insert, insert);
CGImageRef outImage = [context createCGImage:outputImage fromRect:extent];

天蓬老师

CGImageRef outImage = [context createCGImage: result fromRect:[result extent]];

改为 CGImageRef outImage = [context createCGImage: result fromRect:[image extent]];

image 为上边的 CIImage *image = [CIImage imageWithCGImage:originImage.CGImage];

巴扎黑

高斯模糊我记得没错的话无非就是每一个pixel的RGB都是周围pixel的RGB的平均值.
所以我推测,你的原图是不是有白边?

大家讲道理

你是不是高斯模糊的同时,把图片缩小了

黄舟

高斯模糊在边界上确实有点问题。。

有个比较好的思路:将图片的第一行复制若干份放到图片上方(或者向上拉长第一行),其余边类似处理,高斯模糊之后再将图片裁剪回原大小。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号