gpt4 book ai didi

iphone - 核心图像过滤器应用

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:30 26 4
gpt4 key购买 nike

我如何应用我应用的 CIToneCurve 滤镜

  filter= [CIFilter filterWithName:@"CIScreenBlendMode"];
[filter setValue:beginImage1 forKey:kCIInputImageKey];
[filter setValue:beginImage forKey:@"inputBackgroundImage"];

使用这种方法的不同过滤器现在我想应用 CIToneCurve 我应该如何使用这些参数来应用它

inputImage A CIImage class whose display name is Image.

inputPoint0 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 1. Default value: [0, 0] Identity: [0, 0]

inputPoint1 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 2l. Default value: [0.25, 0.25] Identity: [0.25, 0.25]

inputPoint2 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 3l. Default value: [0.5, 0.5] Identity: [0.5, 0.5]

inputPoint3 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 4. Default value: [0.75, 0.75] Identity: [0.75, 0.75]

inputPoint4 A CIVector class whose attribute type is CIAttributeTypeOffset and whose display name is Point 5. Default value: [1, 1] Identity: [1, 1]

我写了这些,但我的应用程序崩溃了,没有给出任何错误

最佳答案

每个过滤器都接受不同类型的参数,但是一旦你习惯了它们就很容易了。你没有发布你遇到的错误,但这对我有用:

- (void)doCIToneCurveFilter
{
// Set an appropriate image. A bit dark so we see the results clearer
// This image is being taken from http://photo.tutsplus.com/tutorials/post-processing/adobe-camera-raw-for-beginners-tone-curve/
imageView.image = [UIImage imageNamed:@"turtles"];
imageView.frame = CGRectMake(0, 0, imageView.image.size.width*0.7, imageView.image.size.height*0.7); // shrank this a bit 2 images fit on screen

// Make the input image recipe
CIImage *inputImage = [CIImage imageWithCGImage:imageView.image.CGImage];

// Make tone filter filter
// See mentioned link for visual reference
CIFilter *toneCurveFilter = [CIFilter filterWithName:@"CIToneCurve"];
[toneCurveFilter setDefaults];
[toneCurveFilter setValue:inputImage forKey:kCIInputImageKey];
[toneCurveFilter setValue:[CIVector vectorWithX:0.0 Y:0.0] forKey:@"inputPoint0"]; // default
[toneCurveFilter setValue:[CIVector vectorWithX:0.27 Y:0.26] forKey:@"inputPoint1"];
[toneCurveFilter setValue:[CIVector vectorWithX:0.5 Y:0.80] forKey:@"inputPoint2"];
[toneCurveFilter setValue:[CIVector vectorWithX:0.7 Y:1.0] forKey:@"inputPoint3"];
[toneCurveFilter setValue:[CIVector vectorWithX:1.0 Y:1.0] forKey:@"inputPoint4"]; // default

// Get the output image recipe
CIImage *outputImage = [toneCurveFilter outputImage];

// Create the context and instruct CoreImage to draw the output image recipe into a CGImage
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];

// Draw the image in screen
UIImageView *imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:cgimg]];
CGRect f = imageView2.frame;
f.origin.y = CGRectGetMaxY(imageView.frame);
f.size.width = imageView.frame.size.width;
f.size.height = imageView.frame.size.height;
imageView2.frame = f;

[self.view addSubview:imageView2];
}

这是结果:

Result CIToneCurve

我使用的图片来自here在那里你可以找到我在这个例子中近似的曲线:

curve

PS:如果您想知道为什么我的结果图像看起来与 the link 中的结果不完全一样这是因为我的图像是局部图像并且颜色分布不同。相似但不完全相同。所以应用完全相同的曲线不会给出完全相同的结果。

希望对你有帮助

关于iphone - 核心图像过滤器应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9818300/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com