小编Ora*_*kan的帖子

如何获得有意义的CIAreaHistogram输出?

我想计算a的直方图CGImage.我正在使用CIAreaHistogram内置CoreImage过滤器.

Justin Mrkva已经做了类似的事情.他说:

我得到直方图本身的CIImage,然后我通过自定义内核运行(参见结尾)将alpha值设置为1(因为否则直方图计算的alpha值被预乘)然后将其转换为NSBitmapImageRep.

我的问题是:是否有可能获得直方图数据而无需创建自定义内核?如果是这样,怎么样?

以下代码只是尝试渲染直方图而不修改alpha值:

- (void)printHistogram:(CGImageRef)img {

    NSNumber* buckets = @10;

    CIImage* img_ = [CIImage imageWithCGImage:img];

    CIFilter* histF = [CIFilter filterWithName:@"CIAreaHistogram"];
    [histF setValue:img_ forKey:@"inputImage"];
    [histF setValue:[CIVector vectorWithX:0.0
                                        Y:0.0
                                        Z:CGImageGetWidth(img)
                                        W:CGImageGetHeight(img)]
             forKey:@"inputExtent"];
    [histF setValue:buckets forKey:@"inputCount"];
    [histF setValue:@1.0 forKey:@"inputScale"];

    CIImage* histImg = [histF valueForKey:@"outputImage"];

    int rowBytes = [buckets intValue] * 4; // ARGB has 4 components
    uint8_t byteBuffer[rowBytes]; // Buffer to render into
    CGColorSpaceRef cspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);

    CIContext* ctx = [[CIContext …
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c core-image cifilter

5
推荐指数
1
解决办法
2452
查看次数

标签 统计

cifilter ×1

cocoa ×1

core-image ×1

objective-c ×1