自然饱和度”是图像整体的明亮程度,“饱和度”是图像颜色的鲜艳程度。
“饱和度”与“色相/饱和度”命令中的“饱和度”选项效果相同,可以增加整个画面的“饱和度”,但如调节到较高数值,图像会产生色彩过饱和从而引起图像失真。
在GPUImage中使用GPUImageVibranceFilter来实现调整图像的自然饱和度
片段着色
varying highp vec2 textureCoordinate; uniform sampler2D inputImageTexture; uniform lowp float vibrance; void main() { lowp vec4 color = texture2D(inputImageTexture, textureCoordinate); lowp float average = (color.r + color.g + color.b) / 3.0; lowp float mx = max(color.r, max(color.g, color.b)); lowp float amt = (mx - average) * (-vibrance * 3.0); color.rgb = mix(color.rgb, vec3(mx), amt); gl_FragColor = color; }
具体应用
+ (UIImage *)changeValueForVibranceFilter:(float)value image:(UIImage *)image { GPUImageVibranceFilter *filter = [[GPUImageVibranceFilter alloc] init]; filter.vibrance = value; [filter forceProcessingAtSize:image.size]; GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image]; [pic addTarget:filter]; [pic processImage]; [filter useNextFrameForImageCapture]; return [filter imageFromCurrentFramebuffer]; }
效果
原文:http://www.cnblogs.com/salam/p/5120025.html