1

我正在使用 CIImage 对象,试图获得饱和值。但我找不到获得图像饱和度的方法,至少使用 OS X 中可用的 CIFilters。
是否可以使用标准 CIFilters 获得 CIImage 的饱和度?

4

3 回答 3

3

看看CIColorControls过滤器。使用此滤镜可以调整图像的饱和度、亮度和对比度。

为了计算饱和度,该滤波器在灰度图像(饱和度 = 0.0)和原始图像(饱和度 = 1.0)之间进行线性插值。过滤器支持外推:对于大于 1.0 的值,它会增加饱和度。

例子:

CIFilter *colorControlsFilter = [CIFilter filterWithName:@"CIColorControls"];
[colorControlsFilter setDefaults];
[colorControlsFilter setValue:sourceImage forKey:@"inputImage"];
[colorControlsFilter setValue:[NSNumber numberWithFloat:1.0] forKey:@"inputSaturation"];
[colorControlsFilter setValue:[NSNumber numberWithFloat:0.2] forKey:@"inputBrightness"];
[colorControlsFilter setValue:[NSNumber numberWithFloat:1.0] forKey:@"inputContrast"];

CIImage *outputImage = [colorControlsFilter valueForKey:@"outputImage"];


CIColorControls参考这里
▸ 所有 CIFilters在这里

于 2012-10-05T17:55:11.930 回答
0

You cannot do it using built-in CIFilter but you can code it quite simply. I won't give you full implementation but I can give you the cikernel that'll do the work :

vec4 rgbToHsv(vec4 rgb) {
    float x = min(rgb.r, min(rgb.g, rgb.b));
    float v = max(rgb.r, max(rgb.g, rgb.b));
    float f = (rgb.r == x) ? rgb.g - rgb.b : ((rgb.g == x) ? rgb.b - rgb.r : rgb.r - rgb.g);
    float i = (rgb.r == x) ? 3.0 : ((rgb.g == x) ? 5.0 : 1.0);
    float h = i - (f / (v - x));
    float s = (v - x) / v;
    return (v == x) ? vec4(-1, 0, v, rgb.a) : vec4(h, s, v, rgb.a);
}

kernel vec4 saturationToGrayscale(sampler image) {
    vec4 color = sample(image, samplerCoord(image));
    vec4 hsv = rgbToHsv(color);
    return premultiply(vec4(vec3(hsv.g), color.a));
}

rgbToHsv function comes from Andy Finnell's blog

Output result is a grayscale image where white means sat == 1.0 and black means sat == 0.0. You can revert this by using "1.0-hsv.g" instead of "hsv.g" in the return argument. You can also retrieve hue and value by using respectively hsv.r and rsv.b.

Making it a CIFilter is left to you. Take a Look at Apple's Creating Custom Filters to do this. The code above takes place in the .cikernel file.

于 2013-01-28T16:57:30.237 回答
0

您可以通过将 RGB 图像转换为 YpCbCr 并更改cbcr值来调整其饱和度。Accelerate.vimage 可以为您完成此转换,Apple 有一个示例代码项目在此处讨论该主题。

您可以将 vImage 操作包装在 aCIImageProcessorKernel中以使它们可用于 Core Image。同样,Apple 有一篇文章解释了如何做到这一点

希望有帮助,

西蒙

于 2018-11-26T13:20:24.557 回答